Maintain the Boe-Bot direction using the Compass
heavy-freelancer
Posts: 23
Hey,
I'm trying to use the Compass Module AppMod (#29113) to maintain the direction of my Boe-Bot.
The idea is : to rotate the robot to the left or the right depending on his deviation.
this is the code I'm using :
heading VAR Byte
myVar VAR Word
SEROUT 5, 188+$8000, ["!CM0I"]
SEROUT 5, 32+$8000, ["!CM0?"]
SERIN 5, 32+$8000, [heading]
DEBUG ? heading
FOR myVar = 1 TO 8000
DO
SEROUT 5, 32+$8000, ["!CM0?"]
SERIN 5, 32+$8000, [heading]
DEBUG ? heading
'Go ahead
PULSOUT 13,850
PULSOUT 12,650
PAUSE 20
LOOP UNTIL heading <> 0
IF heading = 1 THEN 'NE -> turn the robot to left
DO
SEROUT 5, 32+$8000, ["!CM0?"]
SERIN 5, 32+$8000, [heading]
DEBUG ? heading
PULSOUT 13,650
PULSOUT 12, 650
PAUSE 20
LOOP UNTIL heading = 0
ELSEIF heading = 7 THEN 'NW -> Turn the robot to the the right
DO
SEROUT 5, 32+$8000, ["!CM0?"]
SERIN 5, 32+$8000, [heading]
DEBUG ? heading
PULSOUT 13,850
PULSOUT 12, 850
PAUSE 20
LOOP UNTIL heading = 0
ENDIF
NEXT
My problem is that the robot consider a different norths everytime I run the program.
Thanks.
I'm trying to use the Compass Module AppMod (#29113) to maintain the direction of my Boe-Bot.
The idea is : to rotate the robot to the left or the right depending on his deviation.
this is the code I'm using :
heading VAR Byte
myVar VAR Word
SEROUT 5, 188+$8000, ["!CM0I"]
SEROUT 5, 32+$8000, ["!CM0?"]
SERIN 5, 32+$8000, [heading]
DEBUG ? heading
FOR myVar = 1 TO 8000
DO
SEROUT 5, 32+$8000, ["!CM0?"]
SERIN 5, 32+$8000, [heading]
DEBUG ? heading
'Go ahead
PULSOUT 13,850
PULSOUT 12,650
PAUSE 20
LOOP UNTIL heading <> 0
IF heading = 1 THEN 'NE -> turn the robot to left
DO
SEROUT 5, 32+$8000, ["!CM0?"]
SERIN 5, 32+$8000, [heading]
DEBUG ? heading
PULSOUT 13,650
PULSOUT 12, 650
PAUSE 20
LOOP UNTIL heading = 0
ELSEIF heading = 7 THEN 'NW -> Turn the robot to the the right
DO
SEROUT 5, 32+$8000, ["!CM0?"]
SERIN 5, 32+$8000, [heading]
DEBUG ? heading
PULSOUT 13,850
PULSOUT 12, 850
PAUSE 20
LOOP UNTIL heading = 0
ENDIF
NEXT
My problem is that the robot consider a different norths everytime I run the program.
Thanks.
Comments
But what do you suggest to do in my code to improve the direction of my Boe-Bot.
Thanks again.