(Untitled)
I am currently converting a power wheels jeep into an autonomous vehicle. I am using 2 HB25 motor controllers and a BS2 Bot . 1 controller is used for steering and 1 for the drive motor. I have most of the code written but I am stuck on the steering. I am using a potentiometer to track position, but, I can not get the motor to go to a given position on the pot. Any help anyone can give would be greatly appreciated. I am also posting the code i have
Comments
HB25 PIN 14 ' I/O Pin For HB-25
'
[noparse][[/noparse] Variables ]
result VAR Word
true CON 1
false CON 0
index VAR Word ' Counter For Ramping
counter VAR Word
DO : LOOP UNTIL HB25 = 1 ' Wait For HB-25 Power Up
LOW HB25 ' Make I/O Pin Output/Low
PAUSE 6 ' Wait For HB-25 To Initialize
PULSOUT HB25, 750 ' Stop Motor 1
PAUSE 1 ' 1 mS Delay
PULSOUT HB25, 750
Main:
DO
GOSUB POT_READING
DEBUG DEC result, LF
'ruleFired = false
Rule1:
IF (result < 2112) THEN'AND (ruleFired = false) THEN
PULSOUT 12, 650
GOSUB RIGHT
'ruleFired = True
DEBUG "rule 1 ",CR,LF
ENDIF
PAUSE 200
'Rule2:
' IF (result > 2112) THEN'AND (ruleFired = false) THEN
' GOSUB Rightcenter
'ruleFired = True
' DEBUG "rule 2 ", CR, LF
' ENDIF
' PAUSE 200
Rule3:
IF (result > 2112) THEN'AND (ruleFired = false) THEN
PULSOUT 12, 650
GOSUB left
'ruleFired = True
DEBUG "rule 3 ", CR, LF
ENDIF
LOOP
'SUB POT READING'''''''''''''''''''''
POT_READING:
HIGH 7
PAUSE 200
RCTIME 7,1,RESULT
DEBUG ? RESULT
'GOTO POT_READIN
RETURN
'SUB TURNE RIGHT
Right:
FOR counter = 1 TO 100
PULSOUT 14, 650
PAUSE 20
NEXT
GOTO MAIN
Left:
FOR counter = 1 TO 100
PULSOUT 14, 850
PAUSE 2
NEXT
GOTO Main
forward:
DO
PULSOUT 12, 650
PAUSE 20
LOOP
END
Rightcenter:
FOR counter = 1 TO 100
PULSOUT 14, 760
PAUSE 2
NEXT
HB25 PIN 14 ' I/O Pin For HB-25
'
[noparse][[/noparse] Variables ]
result VAR Word
true CON 1
false CON 0
index VAR Word ' Counter For Ramping
counter VAR Word
DO : LOOP UNTIL HB25 = 1 ' Wait For HB-25 Power Up
LOW HB25 ' Make I/O Pin Output/Low
PAUSE 6 ' Wait For HB-25 To Initialize
PULSOUT HB25, 750 ' Stop Motor 1
PAUSE 1 ' 1 mS Delay
PULSOUT HB25, 750
Main:
DO
GOSUB POT_READING
DEBUG DEC result, LF
'ruleFired = false
Rule1:
IF (result < 2112) THEN'AND (ruleFired = false) THEN
PULSOUT 12, 650
GOSUB RIGHT
'ruleFired = True
DEBUG "rule 1 ",CR,LF
ENDIF
PAUSE 200
'Rule2:
' IF (result > 2112) THEN'AND (ruleFired = false) THEN
' GOSUB Rightcenter
'ruleFired = True
' DEBUG "rule 2 ", CR, LF
' ENDIF
' PAUSE 200
Rule3:
IF (result > 2112) THEN'AND (ruleFired = false) THEN
PULSOUT 12, 650
GOSUB left
'ruleFired = True
DEBUG "rule 3 ", CR, LF
ENDIF
LOOP
'SUB POT READING'''''''''''''''''''''
POT_READING:
HIGH 7
PAUSE 200
RCTIME 7,1,RESULT
DEBUG ? RESULT
'GOTO POT_READIN
RETURN
'SUB TURNE RIGHT
Right:
FOR counter = 1 TO 100
PULSOUT 14, 650
PAUSE 20
NEXT
GOTO MAIN
Left:
FOR counter = 1 TO 100
PULSOUT 14, 850
PAUSE 2
NEXT
GOTO Main
forward:
DO
PULSOUT 12, 650
PAUSE 20
LOOP
END
Rightcenter:
FOR counter = 1 TO 100
PULSOUT 14, 760
PAUSE 2
NEXT
If you edit your original post with a descriptive "subject", you will probably get some feedback.
rpdb