Skip to content
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

Merged
merged 12 commits into from
Nov 13, 2018

Conversation

bkueng
Copy link
Member

@bkueng bkueng commented Nov 5, 2018

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:

  • ability to stop the position controller completely in Stabilized.
  • Easier code path for Stabilized as there are less transformations. I find this important especially since Stabilized is often used as a fail-safe flight mode.

Testing

Additional changes

…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.
@bkueng bkueng force-pushed the mc_stabilized_to_mc_att_control branch from ef8eeaf to 78da9ff Compare November 7, 2018 18:45
@bkueng bkueng requested a review from a team November 7, 2018 19:51
Copy link
Member

@MaEtUgR MaEtUgR left a 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;
Copy link
Member

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. */
Copy link
Member

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,
Copy link
Member

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
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member Author

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)) {
Copy link
Member

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

Copy link
Contributor

@RomanBapst RomanBapst left a 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.

@Avysuarez
Copy link

Tested on pixhawk 4. Good flight, no issues.
https://review.px4.io/plot_app?log=9cdf5b96-d563-4163-8dee-9d0066add5e8

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.
@bkueng bkueng force-pushed the mc_stabilized_to_mc_att_control branch from 78da9ff to 454786c Compare November 9, 2018 07:27
@bkueng
Copy link
Member Author

bkueng commented Nov 9, 2018

All comments addressed.

@bkueng bkueng merged commit 9a9c17b into master Nov 13, 2018
@bkueng bkueng deleted the mc_stabilized_to_mc_att_control branch November 13, 2018 08:30
RomanBapst added a commit that referenced this pull request Dec 8, 2018
during a transition

- this regression most likely comes from PR #10805

Signed-off-by: Roman <bapstroman@gmail.com>
RomanBapst added a commit that referenced this pull request Dec 10, 2018
during a transition

- this regression most likely comes from PR #10805

Signed-off-by: Roman <bapstroman@gmail.com>
RomanBapst added a commit that referenced this pull request Dec 11, 2018
during a transition

- this regression most likely comes from PR #10805

Signed-off-by: Roman <bapstroman@gmail.com>
RomanBapst added a commit that referenced this pull request Jan 22, 2019
during a transition

- this regression most likely comes from PR #10805

Signed-off-by: Roman <bapstroman@gmail.com>
sfuhrer pushed a commit to sfuhrer/Firmware that referenced this pull request Mar 19, 2019
during a transition

- this regression most likely comes from PR PX4#10805

Signed-off-by: Roman <bapstroman@gmail.com>
@MaEtUgR MaEtUgR mentioned this pull request Oct 16, 2019
8 tasks
MaEtUgR added a commit that referenced this pull request Mar 9, 2020
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².
MaEtUgR added a commit that referenced this pull request Mar 18, 2020
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².
MaEtUgR added a commit that referenced this pull request Mar 18, 2020
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².
bkueng pushed a commit that referenced this pull request May 19, 2020
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².
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants