Fixed heading calculation, fixed heading controller

This commit is contained in:
Lorenz Meier
2012-09-29 18:00:01 +02:00
parent 1725069c18
commit 7949ac1ad8
3 changed files with 47 additions and 15 deletions
+6 -3
View File
@@ -79,9 +79,12 @@ __EXPORT float get_bearing_to_next_waypoint(double lat_now, double lon_now, doub
/* conscious mix of double and float trig function to maximize speed and efficiency */
float theta = atan2f(sin(d_lon) * cos(lat_next_rad) , cos(lat_now_rad) * sin(lat_next_rad) - sin(lat_now_rad) * cos(lat_next_rad) * cos(d_lon));
// XXX wrapping check is incomplete
if (theta < 0.0f) {
theta = theta + 2.0f * M_PI_F;
if (theta < M_PI_F) {
theta += 2.0f * M_PI_F;
}
if (theta > M_PI_F) {
theta -= 2.0f * M_PI_F;
}
return theta;
+1 -1
View File
@@ -179,7 +179,7 @@ __EXPORT float pid_calculate(PID_t *pid, float sp, float val, float val_dot, flo
pid->error_previous = error;
}
float output = (error * pid->kp) + (i * pid->ki) + (d * pid->kd);
float output = (pid->error_previous * pid->kp) + (i * pid->ki) + (d * pid->kd);
if (isfinite(output)) {
pid->last_output = output;