AndyGadget
Senior Member
This is one of those things which should be simple, but by brain is refusing to co-operate on this one.
I'm using a Honeywell compass sensor with an 18M2 for a small robot, and trying to calculate the difference between the desired (btgt) and actual bearing (babs). Getting data from the sensor is fine but I'm having trouble with the logic of the bearing difference (berr). The simple code below is fine as long as the zero / 71 heading does not fall between the desired and actual bearing - If it does, the > and < tests reverse and an incorrect error reading is returned.
How do I cope with this situation?
Edit : Think I've found a clue in Fast Freddy's code here : http://www.picaxeforum.co.uk/showthread.php?17616-Relative-Compass-Heading&highlight=heading+error
I'm using a Honeywell compass sensor with an 18M2 for a small robot, and trying to calculate the difference between the desired (btgt) and actual bearing (babs). Getting data from the sensor is fine but I'm having trouble with the logic of the bearing difference (berr). The simple code below is fine as long as the zero / 71 heading does not fall between the desired and actual bearing - If it does, the > and < tests reverse and an incorrect error reading is returned.
How do I cope with this situation?
Code:
GetBearing:
' HMC6352 outputs 0 to 3599
' 72 steps complete turn when divided by 50.
' 18 steps / quadrant.
hi2cout ("A")
pause 10
hi2cin (bngh,bngl)
babs = babs/50 ' 72 points ' babs is compass reading. btgt is target bearing.
brglft = 0 : brgrgt = 0 ' Flags for L or R of desired bearing.
berr = 0 ' Bearing error. Zero if on course.
if btgt > babs then
berr = btgt - babs
brgrgt = 1
end if
if btgt < babs then
berr = babs - btgt
brglft = 1
end if
return
Last edited: