AC_AttitudeControl: constrain input euler roll and pitch in bodyframe roll controls
and limit integrated error in bf_roll_pitch_yaw_3
This commit is contained in:
parent
3e2a253f4a
commit
d72f2feeb5
@ -350,8 +350,8 @@ void AC_AttitudeControl::input_euler_rate_yaw_euler_angle_pitch_bf_roll_m(float
|
|||||||
{
|
{
|
||||||
// Convert from centidegrees on public interface to radians
|
// Convert from centidegrees on public interface to radians
|
||||||
float euler_yaw_rate = radians(euler_yaw_rate_cds*0.01f);
|
float euler_yaw_rate = radians(euler_yaw_rate_cds*0.01f);
|
||||||
float euler_pitch = radians(euler_pitch_cd * 0.01f);
|
float euler_pitch = radians(constrain_float(euler_pitch_cd * 0.01f, -90.0f, 90.0f));
|
||||||
float body_roll = radians(body_roll_cd * 0.01f);
|
float body_roll = radians(constrain_float(body_roll_cd * 0.01f, -90.0f, 90.0f));
|
||||||
|
|
||||||
// new heading
|
// new heading
|
||||||
_attitude_target_euler_angle.z = wrap_PI(_attitude_target_euler_angle.z + euler_yaw_rate * _dt);
|
_attitude_target_euler_angle.z = wrap_PI(_attitude_target_euler_angle.z + euler_yaw_rate * _dt);
|
||||||
@ -369,10 +369,6 @@ void AC_AttitudeControl::input_euler_rate_yaw_euler_angle_pitch_bf_roll_m(float
|
|||||||
bf_yaw_Q.from_axis_angle(Vector3f(-cosf(euler_pitch), 0, 0), body_roll);
|
bf_yaw_Q.from_axis_angle(Vector3f(-cosf(euler_pitch), 0, 0), body_roll);
|
||||||
_attitude_target_quat = _attitude_target_quat * bf_roll_Q * bf_yaw_Q;
|
_attitude_target_quat = _attitude_target_quat * bf_roll_Q * bf_yaw_Q;
|
||||||
|
|
||||||
// calculate the attitude target euler angles
|
|
||||||
_attitude_target_euler_angle.x = _attitude_target_quat.get_euler_roll();
|
|
||||||
_attitude_target_euler_angle.y = _attitude_target_quat.get_euler_pitch();
|
|
||||||
|
|
||||||
// Set rate feedforward requests to zero
|
// Set rate feedforward requests to zero
|
||||||
_attitude_target_euler_rate = Vector3f(0.0f, 0.0f, 0.0f);
|
_attitude_target_euler_rate = Vector3f(0.0f, 0.0f, 0.0f);
|
||||||
_attitude_target_ang_vel = Vector3f(0.0f, 0.0f, 0.0f);
|
_attitude_target_ang_vel = Vector3f(0.0f, 0.0f, 0.0f);
|
||||||
@ -396,8 +392,8 @@ void AC_AttitudeControl::input_euler_rate_yaw_euler_angle_pitch_bf_roll_p(float
|
|||||||
{
|
{
|
||||||
// Convert from centidegrees on public interface to radians
|
// Convert from centidegrees on public interface to radians
|
||||||
float euler_yaw_rate = radians(euler_yaw_rate_cds*0.01f);
|
float euler_yaw_rate = radians(euler_yaw_rate_cds*0.01f);
|
||||||
float euler_pitch = radians(euler_pitch_cd * 0.01f);
|
float euler_pitch = radians(constrain_float(euler_pitch_cd * 0.01f, -90.0f, 90.0f));
|
||||||
float body_roll = radians(body_roll_cd * 0.01f);
|
float body_roll = radians(constrain_float(body_roll_cd * 0.01f, -90.0f, 90.0f));
|
||||||
|
|
||||||
const float cpitch = cosf(euler_pitch);
|
const float cpitch = cosf(euler_pitch);
|
||||||
const float spitch = fabsf(sinf(euler_pitch));
|
const float spitch = fabsf(sinf(euler_pitch));
|
||||||
@ -419,10 +415,6 @@ void AC_AttitudeControl::input_euler_rate_yaw_euler_angle_pitch_bf_roll_p(float
|
|||||||
bf_yaw_Q.from_axis_angle(Vector3f(cpitch, 0, 0), euler_yaw_rate);
|
bf_yaw_Q.from_axis_angle(Vector3f(cpitch, 0, 0), euler_yaw_rate);
|
||||||
_attitude_target_quat = _attitude_target_quat * bf_roll_Q * bf_yaw_Q;
|
_attitude_target_quat = _attitude_target_quat * bf_roll_Q * bf_yaw_Q;
|
||||||
|
|
||||||
// calculate the attitude target euler angles
|
|
||||||
_attitude_target_euler_angle.x = _attitude_target_quat.get_euler_roll();
|
|
||||||
_attitude_target_euler_angle.y = _attitude_target_quat.get_euler_pitch();
|
|
||||||
|
|
||||||
// Set rate feedforward requests to zero
|
// Set rate feedforward requests to zero
|
||||||
_attitude_target_euler_rate = Vector3f(0.0f, 0.0f, 0.0f);
|
_attitude_target_euler_rate = Vector3f(0.0f, 0.0f, 0.0f);
|
||||||
_attitude_target_ang_vel = Vector3f(0.0f, 0.0f, 0.0f);
|
_attitude_target_ang_vel = Vector3f(0.0f, 0.0f, 0.0f);
|
||||||
@ -551,8 +543,18 @@ void AC_AttitudeControl::input_rate_bf_roll_pitch_yaw_3(float roll_rate_bf_cds,
|
|||||||
float yaw_rate_rads = radians(yaw_rate_bf_cds * 0.01f);
|
float yaw_rate_rads = radians(yaw_rate_bf_cds * 0.01f);
|
||||||
|
|
||||||
// Update attitude error
|
// Update attitude error
|
||||||
Vector3f gyro_latest = _ahrs.get_gyro_latest();
|
Vector3f attitude_error_vector;
|
||||||
|
_attitude_ang_error.to_axis_angle(attitude_error_vector);
|
||||||
|
|
||||||
Quaternion attitude_ang_error_update_quat;
|
Quaternion attitude_ang_error_update_quat;
|
||||||
|
// limit the integrated error angle
|
||||||
|
float err_mag = attitude_error_vector.length();
|
||||||
|
if (err_mag > AC_ATTITUDE_THRUST_ERROR_ANGLE) {
|
||||||
|
attitude_error_vector *= AC_ATTITUDE_THRUST_ERROR_ANGLE / err_mag;
|
||||||
|
_attitude_ang_error.from_axis_angle(attitude_error_vector);
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector3f gyro_latest = _ahrs.get_gyro_latest();
|
||||||
attitude_ang_error_update_quat.from_axis_angle(Vector3f((_attitude_target_ang_vel.x-gyro_latest.x) * _dt, (_attitude_target_ang_vel.y-gyro_latest.y) * _dt, (_attitude_target_ang_vel.z-gyro_latest.z) * _dt));
|
attitude_ang_error_update_quat.from_axis_angle(Vector3f((_attitude_target_ang_vel.x-gyro_latest.x) * _dt, (_attitude_target_ang_vel.y-gyro_latest.y) * _dt, (_attitude_target_ang_vel.z-gyro_latest.z) * _dt));
|
||||||
_attitude_ang_error = attitude_ang_error_update_quat * _attitude_ang_error;
|
_attitude_ang_error = attitude_ang_error_update_quat * _attitude_ang_error;
|
||||||
|
|
||||||
@ -577,7 +579,6 @@ void AC_AttitudeControl::input_rate_bf_roll_pitch_yaw_3(float roll_rate_bf_cds,
|
|||||||
ang_vel_to_euler_rate(_attitude_target_euler_angle, _attitude_target_ang_vel, _attitude_target_euler_rate);
|
ang_vel_to_euler_rate(_attitude_target_euler_angle, _attitude_target_ang_vel, _attitude_target_euler_rate);
|
||||||
|
|
||||||
// Compute the angular velocity target from the integrated rate error
|
// Compute the angular velocity target from the integrated rate error
|
||||||
Vector3f attitude_error_vector;
|
|
||||||
_attitude_ang_error.to_axis_angle(attitude_error_vector);
|
_attitude_ang_error.to_axis_angle(attitude_error_vector);
|
||||||
_rate_target_ang_vel = update_ang_vel_target_from_att_error(attitude_error_vector);
|
_rate_target_ang_vel = update_ang_vel_target_from_att_error(attitude_error_vector);
|
||||||
_rate_target_ang_vel += _attitude_target_ang_vel;
|
_rate_target_ang_vel += _attitude_target_ang_vel;
|
||||||
|
Loading…
Reference in New Issue
Block a user