ardupilot
ardupilot copied to clipboard
AC_AttitudeControl: keep _euler_angle_target up to date with _attitude_target quaternion in attitude_controller_run_quat
This ensures _euler_angle_target is updated to stay in sync with the _attitude_target quaternion in the attitude_controller_run_quat call.
This should mean its a better representation of what is actually going on, otherwise the _euler_angle_target is updated in the "input..." methods meaning its actually the target from the last loop when fetched for logging ect.
Really I think we should look to remove the _euler_angle_target completely, and pull it out of the quaternion when we need it. But that is a much bigger re-work that will also cost some extra computation each time. It will however guarantee both values are always in sync.
@lthall This is a more complete re-work. I'm fairly sure we now keep _euler_angle_target upto date whenever _attitude_target is changed. Either immediately or in the call to attitude_controller_run_quat.
There are a couple of places in your list where we can't remove completely as the value is used in ang_vel_to_euler_rate or euler_rate_to_ang_vel but we can move down into the no input shaping case since it is the only one to change _attitude_target.
Thanks to https://github.com/ArduPilot/ardupilot/pull/26266 this now a much smaller change. We just set _euler_angle_target at the end of the possible outcomes this adds the set in attitude_controller_run_quat or reset_yaw_target_and_rate, the other paths already keep it up to date correctly.
Added a minor tidy up to use the vector method for euler to quaternion. So:
_attitude_target.from_euler(_euler_angle_target.x, _euler_angle_target.y, _euler_angle_target.z);
becomes:
_attitude_target.from_euler(_euler_angle_target);
I have spotted a bug in this (I removed a update that we need). I think it might be clearer to just remove the copy in one go. To make that a little easyer I have done this PR which removes a lots of uses of the euler target in heli.
https://github.com/ArduPilot/ardupilot/pull/27052
I have marked as draft for now.