Go Down

Topic: Using a compass for Navigation - Control method? (Read 1 time) previous topic - next topic


Sep 10, 2011, 01:01 am Last Edit: Sep 10, 2011, 01:26 am by jsmith29 Reason: 1
I want to navigate a boat based on input from a compass.  I am trying to figure out which control method would be best, proportional or PID.  With either method, I am also trying to figure out the best way to handle the error calculation of the actual heading vs. the desired heading since the compass is 0-360°.  The problem is that 0° and 360° are essentially the same point and they keep repeating from 0 to 360.  I have done alot of research on using a PID loop with feedback values that repeat itself and alot of people say that it isn't really suited for that.  I would appreciate anyone's thoughts on what the best way to do this would be.


Given the desired heading it should be easy enough to calculate an error term in the range -180 to +180.

If simple proportional control gives too much of a dead band (error term too low to cause a correction but too high to be on course) you can change to a PI control.  If the heading oscillates, you can go to PID control.

One thing you should be aware of is that your course (direction of travel) will not necessarily be the same as your heading (direction the boat is pointing).  If there is a side force (current or wind) then the boat will drift sideways relative to the heading.
Send Bitcoin tips to: 1G2qoGwMRXx8az71DVP1E81jShxtbSh5Hp


Given the desired heading it should be easy enough to calculate an error term in the range -180 to +180.

Can you clarify this? 



something like this...?

Code: [Select]

compass = readCompass();  // 0..360;
heading = H;                       // 0..360;

error = heading - compass;  // or compass - heading if you want the sign inverted

// mapping to -179 .. 180
if (error <= -180) error = 360 - error;
if (error > 180) error = -360 + error ;

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Go Up