Shop OBEX P1 Docs P2 Docs Learn Events
Maintain the Boe-Bot direction using the Compass — Parallax Forums

Maintain the Boe-Bot direction using the Compass

heavy-freelancerheavy-freelancer Posts: 23
edited 2010-12-20 15:34 in Robotics
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.

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2010-12-20 12:39
    Unfortunately, that's the nature of the compass module. It doesn't have a lot of accuracy and the resolution isn't high either. I think the AppMod uses an HM55B compass and this provides only a 6 bit value for the whole 360 degrees of the compass circle and that's after calibration. To improve the resolution, you can pivot the BoeBot and look for the transitions from one compass value to another (about every 6 degrees). The BoeBot can follow one of these "transition lines" and correct its navigation periodically by moving for a time at right angles to one of these lines.
  • Mike GreenMike Green Posts: 23,101
    edited 2010-12-20 12:45
    Well, it's worse than I thought. This compass module is really pretty old and it only determines the quadrant of magnetic north (N, E, S, W). You could still try pivoting the BoeBot to look for transitions from one quadrant to another and estimate where the middle of the quadrant is (N) based on the amount of pivoting needed to go from N to E and back to W, then reposition the BoeBot based on the estimated middle of the quadrant.
  • heavy-freelancerheavy-freelancer Posts: 23
    edited 2010-12-20 13:03
    Thank you for your explanations.

    But what do you suggest to do in my code to improve the direction of my Boe-Bot.

    Thanks again.
  • Mike GreenMike Green Posts: 23,101
    edited 2010-12-20 15:34
    I already suggested a way. Essentially the BoeBot has to stop and orient itself from time to time. You pivot the BoeBot to the right reading the Compass after each small turn until the compass reading changes from N to E. At that point, you know the BoeBot is pointing just slightly east of NE. You then pivot the BoeBot to the left reading the Compass until it changes first back from E to N, then from N to W. At that point, you know the BoeBot is pointing just slightly west of NW. You know how long and how fast you had to move the wheels to go from NE to NW, so you pivot back one half the distance. Now the BoeBot should be pointing roughly N. There are all sorts of potential errors in this scheme, but it's probably the best you can do with this compass. Over a series of readings along a path, some of the errors should cancel out. You may be able to improve this technique over time and apply some corrections as you see what the errors are.
Sign In or Register to comment.