Rover Autopilot swerving when heading set to 0 degrees (the northward drunkard bug)
MafiaMoe opened this issue ยท 3 comments
When setting the heading control directly north (0 degrees or 360 degrees) the rover tends to swerve randomly and immediately correcting.
This looks to be due to a simple rounding error with a potentially simple fix. The code currently shows:
public static double ClampDegrees180(double angle)
{
angle = ClampDegrees360(angle);
if (angle > 180) angle -= 360;
return angle;
}
The following change may fix this bug
public static double ClampDegrees180(double angle)
{
angle = angle % 180.0;
if (angle < 0) return angle + 180.0;
else return angle;
}
Great program and very clean code.
OK, I reproduced the issue, but I don't think it's due to rounding errors. Rather, the problem is that the autopilot is using a moving average of the vessel heading to determine how to steer. But this moving average is not well behaved when the heading crosses from 360 degrees to 0 degrees, or vice versa, which causes the glitches. I'll try changing it to use the instantaneous heading, which should be free of this problem.
The above change should fix it; if you want to try out a dev build with the fix, replace your MechJeb2.dll with the one available here: http://jenkins.mumech.com/job/MechJeb2/