mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-28 06:03:34 +08:00
Fixed heading calculation, fixed heading controller
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user