Shop OBEX P1 Docs P2 Docs Learn Events
Motormind Stuff — Parallax Forums

Motormind Stuff

ArchiverArchiver Posts: 46,084
edited 2001-03-21 15:19 in General Discussion
Here are some code snippets -- Like you, I'm trying to get the motor control
going.

'*** ports for output to MM modules

OUTPUT 15
OUTPUT 14

'*** ports for input from MM modules

INPUT 13
INPUT 12

'*** set up a variable for which motor to control -- 0 = right, 1 = left

Which_Motor VAR BYTE

'*** motor distance count in hex

Count_Hex VAR WORD
Count_High_Hex VAR Count_Hex.HIGHBYTE
Count_Low_Hex VAR Count_Hex.LOWBYTE

'*** set up duty cycle variable in hex

Duty_Cycle_Hex VAR BYTE

'*** right motor command send & receive ports

RM_Send CON 15
RM_Rec CON 13

'*** left & motor command send & receive ports

LM_Send CON 14
LM_Rec CON 12

'*** set the right & left command send ports to high

HIGH RM_Send
HIGH LM_Send

'*** use the right motor
Which_Motor = 0

'*** set motor count
Count_Hex = 32

GOSUB Motor_Count

PAUSE 5000

'*** set motor duty cycle
Duty_Cycle_Hex = $7F

GOSUB Motor_DC

'*** run selected motor for a fixed count ********************

Motor_Count:

IF Which_Motor = 0 THEN Count_Right

Count_Left:

DEBUG "sending command to run left motor ",DEC Count_High_Hex, DEC
Count_Low_Hex," counts",CR

SEROUT
LM_Send,1021,[noparse][[/noparse]$55,$86,Count_High_Hex,Count_Low_Hex,Duty_Cycle_Hex]

GOTO Count_End

Count_Right:

DEBUG "sending command to run right motor ",DEC Count_High_Hex, DEC
Count_Low_Hex," counts",CR

SEROUT
RM_Send,1021,[noparse][[/noparse]$55,$86,Count_High_Hex,Count_Low_Hex,Duty_Cycle_Hex]

Count_End:

RETURN

'*** run motor at fixed duty cycle **********************************

Motor_DC:

IF Which_Motor = 0 THEN Motor_DC_Right

Motor_DC_Left:

DEBUG "sending command to run left motor at ", DEC Duty_Cycle_Hex,"%
duty cycle",CR

SEROUT LM_Send,1021,[noparse][[/noparse]$55,$83,Duty_Cycle_Hex]

GOTO Stop_Motor_DC

Motor_DC_Right:

DEBUG "Right motor running at ",DEC Duty_Cycle_Hex,"% duty cycle",CR

SEROUT RM_Send,1021,[noparse][[/noparse]$55,$83,Duty_Cycle_Hex]

Stop_Motor_DC:

RETURN

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2001-03-21 15:08
    Thanks for the code Rodent. Is "Count_hex" fixed at 32 all of time or are
    you using some other interface?

    Jeff
  • ArchiverArchiver Posts: 46,084
    edited 2001-03-21 15:19
    For this version it was a fixed value, and actually it should be 0032, since
    it is actually 2 bytes in length. I was working on bump switches and I
    wanted the bot to turn about 45 degrees. 32 counts is about right in this
    case.

    I didn't include all the code because it would be a bit confusing.

    Basically, what I was doing was moving the 'bot forward at a fixed duty
    cycle until it hit a limit switch, then I was stopping, rolling the wheel on
    the opposite side back about 1/2 turn, then going forward again.

    The MotorMind is kind of limited in some respects, so you have to work
    around some of its quirks to do what you want.

    Original Message


    > Thanks for the code Rodent. Is "Count_hex" fixed at 32 all of time or are
    > you using some other interface?
Sign In or Register to comment.