|
|
|
@ -13,7 +13,6 @@ bool ModeLoiter::_enter()
@@ -13,7 +13,6 @@ bool ModeLoiter::_enter()
|
|
|
|
|
|
|
|
|
|
// initialise heading to current heading
|
|
|
|
|
_desired_yaw_cd = ahrs.yaw_sensor; |
|
|
|
|
_yaw_error_cd = 0.0f; |
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
@ -28,7 +27,6 @@ void ModeLoiter::update()
@@ -28,7 +27,6 @@ void ModeLoiter::update()
|
|
|
|
|
// sailboats do not stop
|
|
|
|
|
const float desired_speed_within_radius = g2.motors.has_sail() ? 0.1f : 0.0f; |
|
|
|
|
_desired_speed = attitude_control.get_desired_speed_accel_limited(desired_speed_within_radius, rover.G_Dt); |
|
|
|
|
_yaw_error_cd = 0.0f; |
|
|
|
|
} else { |
|
|
|
|
// P controller with hard-coded gain to convert distance to desired speed
|
|
|
|
|
// To-Do: make gain configurable or calculate from attitude controller's maximum accelearation
|
|
|
|
@ -36,17 +34,17 @@ void ModeLoiter::update()
@@ -36,17 +34,17 @@ void ModeLoiter::update()
|
|
|
|
|
|
|
|
|
|
// calculate bearing to destination
|
|
|
|
|
_desired_yaw_cd = rover.current_loc.get_bearing_to(_destination); |
|
|
|
|
_yaw_error_cd = wrap_180_cd(_desired_yaw_cd - ahrs.yaw_sensor); |
|
|
|
|
float yaw_error_cd = wrap_180_cd(_desired_yaw_cd - ahrs.yaw_sensor); |
|
|
|
|
// if destination is behind vehicle, reverse towards it
|
|
|
|
|
if (fabsf(_yaw_error_cd) > 9000 && g2.loit_type == 0) { |
|
|
|
|
if (fabsf(yaw_error_cd) > 9000 && g2.loit_type == 0) { |
|
|
|
|
_desired_yaw_cd = wrap_180_cd(_desired_yaw_cd + 18000); |
|
|
|
|
_yaw_error_cd = wrap_180_cd(_desired_yaw_cd - ahrs.yaw_sensor); |
|
|
|
|
yaw_error_cd = wrap_180_cd(_desired_yaw_cd - ahrs.yaw_sensor); |
|
|
|
|
_desired_speed = -_desired_speed; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// reduce desired speed if yaw_error is large
|
|
|
|
|
// 45deg of error reduces speed to 75%, 90deg of error reduces speed to 50%
|
|
|
|
|
float yaw_error_ratio = 1.0f - constrain_float(fabsf(_yaw_error_cd / 9000.0f), 0.0f, 1.0f) * 0.5f; |
|
|
|
|
float yaw_error_ratio = 1.0f - constrain_float(fabsf(yaw_error_cd / 9000.0f), 0.0f, 1.0f) * 0.5f; |
|
|
|
|
_desired_speed *= yaw_error_ratio; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|