|
Hello: I need to ensure my motors are stopped properly, however I have not found any hpwm code that I am certain will stop them and keep them stopped. On startup of the atom sometimes the motors will run for a few seconds. Not often but it has happend enough times to worry me. The following code lines are various attempts I have used to stop the motors. After program variables and constants I do the following. HPWM LEFTWHEEL, LEFTMOTORPERIOD, 0 HPWM RIGHTWHEEL, RIGHTMOTORPERIOD, 0 LOW P10 LOW P9 -------------------------
in my working code I use the above as my stopmotor subroutine. I than initialize my display, send a few messages, and send another stopmotor command. I then send a message to turn on the ps2 hand controller. I have yet another stopmotor command. Finally I get to the MAIN body of the program. Now than, if the controller syncs properly and I am in analog mode everything is fine. The problem is if the controller is not synced, or the controller is not in analog mode, sometimes the motors will start up. I dont know how, or where they are getting the code to start? I only kept adding all the gosub stopmotors all over the place in an attempt to prevent this odd behavior. I am posting the pertinent code below and apologize if it appears long. I will post the whole program if requested. -kerry --------------------------------
'START OF PROGRAM---------------------
gosub stopmotors LOW DOMEMOTOR serout 1,i9600,[0,0,0] ' suppposedly initializes the serial lcd chip pause 100
GOSUB CLEARDISPLAY
serout 1,i9600,[1,1,"PROGRAM START"] PAUSE 6000
' ps2 setup routines. GOSUB CLEARDISPLAY gosub stopmotors serout 1,i9600,[1,1,"TURN ON "] serout 1,i9600,[2,1,"HAND CONTROLLER "] PAUSE 2000 low SEL shiftout CMD,CLK,FASTLSBPRE,[$1\8,$43\8,$0\8,$1\8,$0\8] ;Config Enable high SEL
low SEL shiftout CMD,CLK,FASTLSBPRE,[$01\8,$44\8,$00\8,$01\8,$03\8,$00\8,$00\8,$00\8,$00\8] ;Set Mode and Fix(Analog high SEL
pause 100
low SEL shiftout CMD,CLK,FASTLSBPRE,[$01\8,$4D\8,$00\8,$00\8,$01\8,$ff\8,$ff\8,$ff\8,$ff\8] ;Vibration Enable high SEL
low SEL shiftout CMD,CLK,FASTLSBPRE,[$01\8,$43\8,$00\8,$00\8,$00\8,$00\8,$00\8,$00\8,$00\8] ;Config Exit high SEL
'end of Ps2 setup
'-----------PS2 Data----------
GOSUB STOPMOTORS
GOSUB CLEARDISPLAY serout 1,i9600,[1,1,"READY "] 'PAUSE 1000 gosub stopmotors HPWM LEFTWHEEL, LEFTMOTORPERIOD, 0 HPWM RIGHTWHEEL, RIGHTMOTORPERIOD, 0
MAIN GOSUB HOLOEYE 'BORED = BORED + 1 'IF BORED >= 250 THEN '500 = 1 MINUTE 'GOSUB RANDOMSOUND 'ENDIF IF OVERTEMPLEFT = 0 THEN GOSUB OVERTEMP IF OVERTEMPRIGHT = 0 THEN GOSUB OVERTEMP
high CLK 'Turns CLK High GOSUB PS2_IN 'Takes the input of the PS2 controller
while(temp(1).bit0 = 0) 'SELECT BUTTON GOSUB SELECTBUTTON GOSUB PS2_IN wend
while(temp(1).bit3 = 0) 'sTART BUTTON GOSUB STARTBUTTON GOSUB PS2_IN wend while(temp(1).bit4 = 0) 'If up arrow is active then robot goes into forward subroutine GOSUB forwardFULL GOSUB PS2_IN wend while(temp(1).bit5 = 0) 'If right arrow is active then robot goes into right subroutine GOSUB RIGHTTURN90 GOSUB PS2_IN wend while(temp(1).bit6 = 0) 'If down arrow is active then robot goes into backward subroutine GOSUB backUP GOSUB PS2_IN wend while(temp(1).bit7 = 0) 'If left arrow is active then robot goes into left subroutine GOSUB leftTURN90 GOSUB PS2_IN wend
WHILE(temp(2).bit4 = 0) 'TRIANGLE is active GOSUB TRIANGLE GOSUB PS2_IN WEND
WHILE(temp(2).bit5 = 0) ' O BUTTON GOSUB OOOO GOSUB PS2_IN WEND WHILE(temp(2).bit6 = 0) GOSUB XXXX ' X BUTTON ACTIVE GOSUB PS2_IN WEND
WHILE(temp(2).bit7 = 0) 'Square is active GOSUB SQUARE GOSUB PS2_IN WEND WHILE(temp(2).bit3 = 0) 'RIGHT TRIGGER BUTTON ACTIVE GOSUB STOPMOTORS GOSUB PS2_IN WEND WHILE(temp(2).bit2 = 0) GOSUB STOPMOTORS GOSUB PS2_IN WEND WHILE(temp(2).bit1 = 0) GOSUB STOPMOTORS GOSUB PS2_IN WEND WHILE(temp(2).bit0 = 0) GOSUB STOPMOTORS GOSUB PS2_IN wend '---------NOT SURE WHY THE JOYSTICK CODE IS WRITTEN DIFFERENTLY ' low P9 ' low P10 ' low p11 ' low p12 LEFT_JOY_X=(TEMP(5)) 'LEFT JOYSTICK X LEFT_JOY_Y=(TEMP(6)) ' LEFT JOYSTICK Y if left_joy_y <=115 then gosub forward '128 being nuetral, allow a dead zone if left_joy_y >=140 then gosub backup '128 nuetral allow a dead zone if left_joy_y >=116 and left_joy_y <=139 then gosub stopmotors 'if left_joy_y <=120 and left_joy_x <=120 then gosub leftturn 'if left_joy_y >=135 and left_joy_y >=135 then gosub rightturn ' if temp(2).bit7 = 0 THEN 'If Square is active then goes into line following mode ' GOSUB start ' Subroutine for line following ' endif
goto MAIN
STOPMOTORS
HPWM LEFTWHEEL, LEFTMOTORPERIOD, 0 HPWM RIGHTWHEEL, RIGHTMOTORPERIOD, 0 LOW P10 LOW P9 ' TMRW.BIT0=0
BORED = 0
RETURN
|