-
Notifications
You must be signed in to change notification settings - Fork 13.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MC stabilized mode: move from mc_pos_control to mc_att_control #10805
Conversation
…nning Previously when switching e.g. from stabilized from acro, the stabilized flight task kept running and publishing setpoints. Luckily it caused no problems, but the log showed arbitrary attitude setpoints.
use nullptr for instance to make sure we always get the first instance.
- better in terms of dependencies: - the position controller code depended on position topics for yaw - mc_pos_control does not have to be run for Stabilized mode - the code path is much simpler, and thus less error prone. This is especially important since Stabilized is often used as a fail-safe flight mode.
When switching back from rate to attitude control, the code depended on a vehicle_control_mode topics update, but the publication frequency of that is low. So the switch was noticeably delayed.
ef8eeaf
to
78da9ff
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thoughts on the first glance. Does the weather vane feature need to run in stabilized?
I might have some more questions after testing and studying completely.
bool ret = FlightTaskManualStabilized::activate(); | ||
_thrust_setpoint(2) = NAN; // altitude is controlled from position/velocity | ||
bool ret = FlightTaskManual::activate(); | ||
_yaw_setpoint = _yaw; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The _yaw_setpoint should be set to NAN on activation because we don't know if the vehicle has a yawspeed upon mode switch. If the vehicle has no yawspeed and the commanded yaw_speed is 0 it will by design very quickly switch to yaw lock which does a _yaw_setpoint = _yaw
once. But if the vehicle has a yawspeed it should first brake down and not start in yaw lock.
// reuse same scaling as for stabilized | ||
FlightTaskManualStabilized::_scaleSticks(); | ||
/* Scale sticks to yaw and thrust using | ||
* linear scale for yaw and piecewise linear map for thrust. */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the comment doesn't fit anymore in this spot
my suggestion:
// Use sticks input with deadzone and exponential curve for vertical velocity and yawspeed
(ParamFloat<px4::params::MPC_HOLD_MAX_Z>) MPC_HOLD_MAX_Z, | ||
(ParamInt<px4::params::MPC_ALT_MODE>) MPC_ALT_MODE, | ||
(ParamFloat<px4::params::MPC_HOLD_MAX_XY>) MPC_HOLD_MAX_XY, | ||
(ParamFloat<px4::params::MPC_Z_P>) MPC_Z_P | ||
(ParamFloat<px4::params::MPC_Z_P>) MPC_Z_P, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not related but /**< position controller altitude propotional gain */
@@ -334,7 +334,7 @@ PARAM_DEFINE_FLOAT(MPC_TILTMAX_AIR, 45.0f); | |||
* | |||
* @unit deg | |||
* @min 0.0 | |||
* @max 90.0 | |||
* @max 170.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
feeling adventurous? 😄 It's a good idea to check corner angles (first in simulation!) to verify the implementation. 180 should theoretically also work or do we run into gimbal lock problems with the setpoint generation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, see the commit message: 78da9ff. 180 is fine setpoint-wise, beyond that the yaw inverts. I wanted to account for overshoots, but I realize now that even with overshoots the attitude should be tracked correctly up to 180 degrees setpoints.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested it again and 180 works fine. Interestingly even above that works now. I increased the limit to 180.
if (_wv_controller->weathervane_enabled() && !(_control_mode.flag_control_manual_enabled | ||
&& !_control_mode.flag_control_position_enabled)) { | ||
if (_wv_controller->weathervane_enabled() && (!_control_mode.flag_control_manual_enabled | ||
|| _control_mode.flag_control_position_enabled)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
!(A && !B) -> (!A || B) ✔️
according to de morgan
src/lib/FlightTasks/tasks/ManualAltitude/FlightTaskManualAltitude.cpp
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good in general.
Tested on pixhawk 4. Good flight, no issues. |
This is especially useful for testing (the vehicle must behave correctly even at high tilt angles).
Also update some comments. In case we activate the task and don't have a locked yaw, we should initialize the yaw setpoint with NAN to avoid any abrupt changes.
78da9ff
to
454786c
Compare
All comments addressed. |
during a transition - this regression most likely comes from PR #10805 Signed-off-by: Roman <bapstroman@gmail.com>
during a transition - this regression most likely comes from PR #10805 Signed-off-by: Roman <bapstroman@gmail.com>
during a transition - this regression most likely comes from PR #10805 Signed-off-by: Roman <bapstroman@gmail.com>
during a transition - this regression most likely comes from PR #10805 Signed-off-by: Roman <bapstroman@gmail.com>
during a transition - this regression most likely comes from PR PX4#10805 Signed-off-by: Roman <bapstroman@gmail.com>
This was only necessary for stabilized mode before #10805. The unit length thrust setpoint will anyways not be available anymore soon because it gets replaced with the acceleration setpoint in m/s².
This was only necessary for stabilized mode before #10805. The unit length thrust setpoint will anyways not be available anymore soon because it gets replaced with the acceleration setpoint in m/s².
This was only necessary for stabilized mode before #10805. The unit length thrust setpoint will anyways not be available anymore soon because it gets replaced with the acceleration setpoint in m/s².
This was only necessary for stabilized mode before #10805. The unit length thrust setpoint will anyways not be available anymore soon because it gets replaced with the acceleration setpoint in m/s².
Handling the Stabilized fight mode in mc_pos_control adds unnecessary dependencies. This recently became apparent that Stabilized would not work correctly anymore if there was not position published.
So this PR moves the complete handling into mc_att_control.
Additional benefits:
Testing
Additional changes