Skip to content

Commit ad922f7

Browse files
committed
AC_AttitudeControl: Split centidegree and radian interfaces
1 parent 3038c70 commit ad922f7

File tree

2 files changed

+82
-9
lines changed

2 files changed

+82
-9
lines changed

libraries/AC_AttitudeControl/AC_AttitudeControl.cpp

Lines changed: 70 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -345,10 +345,14 @@ void AC_AttitudeControl::input_quaternion(Quaternion& attitude_desired_quat, Vec
345345
void AC_AttitudeControl::input_euler_angle_roll_pitch_euler_rate_yaw_cd(float euler_roll_angle_cd, float euler_pitch_angle_cd, float euler_yaw_rate_cds)
346346
{
347347
// Convert from centidegrees on public interface to radians
348-
float euler_roll_angle_rad = cd_to_rad(euler_roll_angle_cd);
348+
const float euler_roll_angle_rad = cd_to_rad(euler_roll_angle_cd);
349349
const float euler_pitch_angle_rad = cd_to_rad(euler_pitch_angle_cd);
350350
const float euler_yaw_rate_rads = cd_to_rad(euler_yaw_rate_cds);
351+
input_euler_angle_roll_pitch_euler_rate_yaw_rad(euler_roll_angle_rad, euler_pitch_angle_rad, euler_yaw_rate_rads);
352+
}
351353

354+
void AC_AttitudeControl::input_euler_angle_roll_pitch_euler_rate_yaw_rad(float euler_roll_angle_rad, float euler_pitch_angle_rad, float euler_yaw_rate_rads)
355+
{
352356
// update attitude target
353357
update_attitude_target();
354358

@@ -399,10 +403,15 @@ void AC_AttitudeControl::input_euler_angle_roll_pitch_euler_rate_yaw_cd(float eu
399403
void AC_AttitudeControl::input_euler_angle_roll_pitch_yaw_cd(float euler_roll_angle_cd, float euler_pitch_angle_cd, float euler_yaw_angle_cd, bool slew_yaw)
400404
{
401405
// Convert from centidegrees on public interface to radians
402-
float euler_roll_angle_rad = cd_to_rad(euler_roll_angle_cd);
406+
const float euler_roll_angle_rad = cd_to_rad(euler_roll_angle_cd);
403407
const float euler_pitch_angle_rad = cd_to_rad(euler_pitch_angle_cd);
404408
const float euler_yaw_angle_rad = cd_to_rad(euler_yaw_angle_cd);
405409

410+
input_euler_angle_roll_pitch_yaw_rad(euler_roll_angle_rad, euler_pitch_angle_rad, euler_yaw_angle_rad, slew_yaw);
411+
}
412+
413+
void AC_AttitudeControl::input_euler_angle_roll_pitch_yaw_rad(float euler_roll_angle_rad, float euler_pitch_angle_rad, float euler_yaw_angle_rad, bool slew_yaw)
414+
{
406415
// update attitude target
407416
update_attitude_target();
408417

@@ -465,6 +474,11 @@ void AC_AttitudeControl::input_euler_rate_roll_pitch_yaw_cds(float euler_roll_ra
465474
const float euler_pitch_rate_rads = cd_to_rad(euler_pitch_rate_cds);
466475
const float euler_yaw_rate_rads = cd_to_rad(euler_yaw_rate_cds);
467476

477+
input_euler_rate_roll_pitch_yaw_rads(euler_roll_rate_rads, euler_pitch_rate_rads, euler_yaw_rate_rads);
478+
}
479+
480+
void AC_AttitudeControl::input_euler_rate_roll_pitch_yaw_rads(float euler_roll_rate_rads, float euler_pitch_rate_rads, float euler_yaw_rate_rads)
481+
{
468482
// update attitude target
469483
update_attitude_target();
470484

@@ -511,6 +525,11 @@ void AC_AttitudeControl::input_rate_bf_roll_pitch_yaw_cds(float roll_rate_bf_cds
511525
const float pitch_rate_bf_rads = cd_to_rad(pitch_rate_bf_cds);
512526
const float yaw_rate_bf_rads = cd_to_rad(yaw_rate_bf_cds);
513527

528+
input_rate_bf_roll_pitch_yaw_rads(roll_rate_bf_rads, pitch_rate_bf_rads, yaw_rate_bf_rads);
529+
}
530+
531+
void AC_AttitudeControl::input_rate_bf_roll_pitch_yaw_rads(float roll_rate_bf_rads, float pitch_rate_bf_rads, float yaw_rate_bf_rads)
532+
{
514533
// update attitude target
515534
update_attitude_target();
516535

@@ -552,6 +571,11 @@ void AC_AttitudeControl::input_rate_bf_roll_pitch_yaw_2_cds(float roll_rate_bf_c
552571
const float pitch_rate_bf_rads = cd_to_rad(pitch_rate_bf_cds);
553572
const float yaw_rate_bf_rads = cd_to_rad(yaw_rate_bf_cds);
554573

574+
input_rate_bf_roll_pitch_yaw_2_rads(roll_rate_bf_rads, pitch_rate_bf_rads, yaw_rate_bf_rads);
575+
}
576+
577+
void AC_AttitudeControl::input_rate_bf_roll_pitch_yaw_2_rads(float roll_rate_bf_rads, float pitch_rate_bf_rads, float yaw_rate_bf_rads)
578+
{
555579
// Compute acceleration-limited body frame rates
556580
// When acceleration limiting is enabled, the input shaper constrains angular acceleration about the axis, slewing
557581
// the output rate towards the input rate.
@@ -578,6 +602,11 @@ void AC_AttitudeControl::input_rate_bf_roll_pitch_yaw_3_cds(float roll_rate_bf_c
578602
const float pitch_rate_bf_rads = cd_to_rad(pitch_rate_bf_cds);
579603
const float yaw_rate_bf_rads = cd_to_rad(yaw_rate_bf_cds);
580604

605+
input_rate_bf_roll_pitch_yaw_3_rads(roll_rate_bf_rads, pitch_rate_bf_rads, yaw_rate_bf_rads);
606+
}
607+
608+
void AC_AttitudeControl::input_rate_bf_roll_pitch_yaw_3_rads(float roll_rate_bf_rads, float pitch_rate_bf_rads, float yaw_rate_bf_rads)
609+
{
581610
// Update attitude error
582611
Vector3f attitude_error;
583612
_attitude_ang_error.to_axis_angle(attitude_error);
@@ -637,6 +666,12 @@ void AC_AttitudeControl::input_rate_bf_roll_pitch_yaw_no_shaping_cds(float roll_
637666
const float pitch_rate_bf_rads = cd_to_rad(pitch_rate_bf_cds);
638667
const float yaw_rate_bf_rads = cd_to_rad(yaw_rate_bf_cds);
639668

669+
input_rate_bf_roll_pitch_yaw_no_shaping_rads(roll_rate_bf_rads, pitch_rate_bf_rads, yaw_rate_bf_rads);
670+
}
671+
672+
void AC_AttitudeControl::input_rate_bf_roll_pitch_yaw_no_shaping_rads(float roll_rate_bf_rads, float pitch_rate_bf_rads, float yaw_rate_bf_rads)
673+
{
674+
640675
_ang_vel_target_rads.x = roll_rate_bf_rads;
641676
_ang_vel_target_rads.y = pitch_rate_bf_rads;
642677
_ang_vel_target_rads.z = yaw_rate_bf_rads;
@@ -661,6 +696,11 @@ void AC_AttitudeControl::input_angle_step_bf_roll_pitch_yaw_cd(float roll_angle_
661696
const float pitch_angle_step_bf_rad = cd_to_rad(pitch_angle_step_bf_cd);
662697
const float yaw_angle_step_bf_rad = cd_to_rad(yaw_angle_step_bf_cd);
663698

699+
input_angle_step_bf_roll_pitch_yaw_rad(roll_angle_step_bf_rad, pitch_angle_step_bf_rad, yaw_angle_step_bf_rad);
700+
}
701+
702+
void AC_AttitudeControl::input_angle_step_bf_roll_pitch_yaw_rad(float roll_angle_step_bf_rad, float pitch_angle_step_bf_rad, float yaw_angle_step_bf_rad)
703+
{
664704
// rotate attitude target by desired step
665705
Quaternion attitude_target_update;
666706
attitude_target_update.from_axis_angle(Vector3f{roll_angle_step_bf_rad, pitch_angle_step_bf_rad, yaw_angle_step_bf_rad});
@@ -682,6 +722,16 @@ void AC_AttitudeControl::input_angle_step_bf_roll_pitch_yaw_cd(float roll_angle_
682722
// Used to command a step in rate without exciting the orthogonal axis during autotune
683723
// Done as a single thread-safe function to avoid intermediate zero values being seen by the attitude controller
684724
void AC_AttitudeControl::input_rate_step_bf_roll_pitch_yaw_cds(float roll_rate_step_bf_cds, float pitch_rate_step_bf_cds, float yaw_rate_step_bf_cds)
725+
{
726+
// Convert from centidegrees on public interface to radians
727+
const float roll_rate_step_bf_rads = cd_to_rad(roll_rate_step_bf_cds);
728+
const float pitch_rate_step_bf_rads = cd_to_rad(pitch_rate_step_bf_cds);
729+
const float yaw_rate_step_bf_rads = cd_to_rad(yaw_rate_step_bf_cds);
730+
731+
input_rate_step_bf_roll_pitch_yaw_rads(roll_rate_step_bf_rads, pitch_rate_step_bf_rads, yaw_rate_step_bf_rads);
732+
}
733+
734+
void AC_AttitudeControl::input_rate_step_bf_roll_pitch_yaw_rads(float roll_rate_step_bf_rads, float pitch_rate_step_bf_rads, float yaw_rate_step_bf_rads)
685735
{
686736
// Update the unused targets attitude based on current attitude to condition mode change
687737
_ahrs.get_quat_body_to_ned(_attitude_target);
@@ -691,17 +741,21 @@ void AC_AttitudeControl::input_rate_step_bf_roll_pitch_yaw_cds(float roll_rate_s
691741
// Convert body-frame angular velocity into euler angle derivative of desired attitude
692742
_euler_rate_target_rads.zero();
693743

694-
Vector3f ang_vel_body_rads {roll_rate_step_bf_cds, pitch_rate_step_bf_cds, yaw_rate_step_bf_cds};
695-
ang_vel_body_rads = ang_vel_body_rads * 0.01f * DEG_TO_RAD;
696744
// finally update the attitude target
697-
_ang_vel_body_rads = ang_vel_body_rads;
745+
_ang_vel_body_rads = Vector3f{roll_rate_step_bf_rads, pitch_rate_step_bf_rads, yaw_rate_step_bf_rads};
698746
}
699747

700748
// Command a thrust vector and heading rate
701749
void AC_AttitudeControl::input_thrust_vector_rate_heading_cds(const Vector3f& thrust_vector, float heading_rate_cds, bool slew_yaw)
702750
{
703751
// Convert from centidegrees on public interface to radians
704-
float heading_rate_rads = cd_to_rad(heading_rate_cds);
752+
const float heading_rate_rads = cd_to_rad(heading_rate_cds);
753+
754+
input_thrust_vector_rate_heading_rads(thrust_vector, heading_rate_rads, slew_yaw);
755+
}
756+
757+
void AC_AttitudeControl::input_thrust_vector_rate_heading_rads(const Vector3f& thrust_vector, float heading_rate_rads, bool slew_yaw)
758+
{
705759
if (slew_yaw) {
706760
// a zero _angle_vel_yaw_max means that setting is disabled
707761
const float slew_yaw_max_rads = get_slew_yaw_max_rads();
@@ -755,13 +809,21 @@ void AC_AttitudeControl::input_thrust_vector_rate_heading_cds(const Vector3f& th
755809

756810
// Command a thrust vector, heading and heading rate
757811
void AC_AttitudeControl::input_thrust_vector_heading_cd(const Vector3f& thrust_vector, float heading_angle_cd, float heading_rate_cds)
812+
{
813+
// Convert from centidegrees on public interface to radians
814+
const float heading_rate_rads = cd_to_rad(heading_rate_cds);
815+
const float heading_angle_rad = cd_to_rad(heading_angle_cd);
816+
817+
input_thrust_vector_heading_rad(thrust_vector, heading_angle_rad, heading_rate_rads);
818+
}
819+
820+
void AC_AttitudeControl::input_thrust_vector_heading_rad(const Vector3f& thrust_vector, float heading_angle_rad, float heading_rate_rads)
758821
{
759822
// a zero _angle_vel_yaw_max means that setting is disabled
760823
const float slew_yaw_max_rads = get_slew_yaw_max_rads();
761824

762825
// Convert from centidegrees on public interface to radians
763-
const float heading_rate_rads = constrain_float(cd_to_rad(heading_rate_cds), -slew_yaw_max_rads, slew_yaw_max_rads);
764-
const float heading_angle_rad = cd_to_rad(heading_angle_cd);
826+
heading_rate_rads = constrain_float(heading_rate_rads, -slew_yaw_max_rads, slew_yaw_max_rads);
765827

766828
// update attitude target
767829
update_attitude_target();

libraries/AC_AttitudeControl/AC_AttitudeControl.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,40 +203,51 @@ class AC_AttitudeControl {
203203

204204
// Command an euler roll and pitch angle and an euler yaw rate with angular velocity feedforward and smoothing
205205
virtual void input_euler_angle_roll_pitch_euler_rate_yaw_cd(float euler_roll_angle_cd, float euler_pitch_angle_cd, float euler_yaw_rate_cds);
206+
virtual void input_euler_angle_roll_pitch_euler_rate_yaw_rad(float euler_roll_angle_rad, float euler_pitch_angle_rad, float euler_yaw_rate_rads);
206207

207208
// Command an euler roll, pitch and yaw angle with angular velocity feedforward and smoothing
208209
virtual void input_euler_angle_roll_pitch_yaw_cd(float euler_roll_angle_cd, float euler_pitch_angle_cd, float euler_yaw_angle_cd, bool slew_yaw);
210+
virtual void input_euler_angle_roll_pitch_yaw_rad(float euler_roll_angle_rad, float euler_pitch_angle_rad, float euler_yaw_angle_rad, bool slew_yaw);
209211

210212
// Command an euler roll, pitch, and yaw rate with angular velocity feedforward and smoothing
211213
virtual void input_euler_rate_roll_pitch_yaw_cds(float euler_roll_rate_cds, float euler_pitch_rate_cds, float euler_yaw_rate_cds);
214+
virtual void input_euler_rate_roll_pitch_yaw_rads(float euler_roll_rate_rads, float euler_pitch_rate_rads, float euler_yaw_rate_rads);
212215

213216
// Fully stabilized acro
214217
// Command an angular velocity with angular velocity feedforward and smoothing
215218
virtual void input_rate_bf_roll_pitch_yaw_cds(float roll_rate_bf_cds, float pitch_rate_bf_cds, float yaw_rate_bf_cds);
219+
virtual void input_rate_bf_roll_pitch_yaw_rads(float roll_rate_bf_rads, float pitch_rate_bf_rads, float yaw_rate_bf_rads);
216220

217221
// Rate-only acro with no attitude feedback - used only by Copter rate-only acro
218222
// Command an angular velocity with angular velocity smoothing using rate loops only with no attitude loop stabilization
219223
virtual void input_rate_bf_roll_pitch_yaw_2_cds(float roll_rate_bf_cds, float pitch_rate_bf_cds, float yaw_rate_bf_cds);
224+
virtual void input_rate_bf_roll_pitch_yaw_2_rads(float roll_rate_bf_rads, float pitch_rate_bf_rads, float yaw_rate_bf_rads);
220225

221226
// Acro with attitude feedback that does not rely on attitude - used only by Plane acro
222227
// Command an angular velocity with angular velocity smoothing using rate loops only with integrated rate error stabilization
223228
virtual void input_rate_bf_roll_pitch_yaw_3_cds(float roll_rate_bf_cds, float pitch_rate_bf_cds, float yaw_rate_bf_cds);
229+
virtual void input_rate_bf_roll_pitch_yaw_3_rads(float roll_rate_bf_rads, float pitch_rate_bf_rads, float yaw_rate_bf_rads);
224230

225231
// set the body frame target rates to the specified rates, used by the
226232
// quadplane code when we want to slave the VTOL controller rates to
227233
// the fixed wing rates
228234
void input_rate_bf_roll_pitch_yaw_no_shaping_cds(float roll_rate_bf_cds, float pitch_rate_bf_cds, float yaw_rate_bf_cds);
235+
void input_rate_bf_roll_pitch_yaw_no_shaping_rads(float roll_rate_bf_rads, float pitch_rate_bf_rads, float yaw_rate_bf_rads);
229236

230237
// Applies a one-time angular offset in body-frame roll/pitch/yaw angles (centidegrees)
231238
virtual void input_angle_step_bf_roll_pitch_yaw_cd(float roll_angle_step_bf_cd, float pitch_angle_step_bf_cd, float yaw_angle_step_bf_cd);
239+
virtual void input_angle_step_bf_roll_pitch_yaw_rad(float roll_angle_step_bf_rad, float pitch_angle_step_bf_rad, float yaw_angle_step_bf_rad);
232240

233241
// Applies a one-time angular velocity offset in body-frame roll/pitch/yaw (centidegrees per second)
234-
virtual void input_rate_step_bf_roll_pitch_yaw_cds(float roll_rate_step_bf_cd, float pitch_rate_step_bf_cd, float yaw_rate_step_bf_cd);
242+
virtual void input_rate_step_bf_roll_pitch_yaw_cds(float roll_rate_step_bf_cds, float pitch_rate_step_bf_cds, float yaw_rate_step_bf_cds);
243+
virtual void input_rate_step_bf_roll_pitch_yaw_rads(float roll_rate_step_bf_rads, float pitch_rate_step_bf_rads, float yaw_rate_step_bf_rads);
235244

236245
// Command a thrust vector in the earth frame and a heading angle and/or rate
237246
virtual void input_thrust_vector_rate_heading_cds(const Vector3f& thrust_vector, float heading_rate_cds, bool slew_yaw = true);
247+
virtual void input_thrust_vector_rate_heading_rads(const Vector3f& thrust_vector, float heading_rate_rads, bool slew_yaw = true);
238248

239249
virtual void input_thrust_vector_heading_cd(const Vector3f& thrust_vector, float heading_angle_cd, float heading_rate_cds);
250+
virtual void input_thrust_vector_heading_rad(const Vector3f& thrust_vector, float heading_angle_rad, float heading_rate_rads);
240251
void input_thrust_vector_heading_cd(const Vector3f& thrust_vector, float heading_cd) {input_thrust_vector_heading_cd(thrust_vector, heading_cd, 0.0f);}
241252

242253
////// end rate update functions //////

0 commit comments

Comments
 (0)