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

Position Control Refactoring Part 5 #13701

Merged
merged 9 commits into from
Dec 18, 2019
Merged

Conversation

MaEtUgR
Copy link
Member

@MaEtUgR MaEtUgR commented Dec 8, 2019

Describe problem solved by this pull request
This is part 5 of the refactoring from the monster pr #12072 and should be easy to understand and review since the diff is manageable.

Describe your solution

  • Switched naming and definition order of the PositionControl library to a clear interface best shown in the unit test for it: https://github.com/PX4/Firmware/blob/6bd543156eab2ccfe639e90d9214e2e0128daa09/src/modules/mc_pos_control/PositionControl/PositionControlTest.cpp#L105-L109 with better doxygen descriptions and internal naming.
  • Simplified constraints checks above global limit e.g. !(constraints.tilt < _lim_tilt) to (constraints.tilt > _lim_tilt).
  • When working on Commander: start pulling arming related parts into separate folder #13224 I was told we should rather write full include paths if they are in a subfolder of the same module such that it's more clear where the libreries are located even though cmake can do it all for you. That's why I also adapted the position control local includes to e.g. #include "PositiopnControl/PositionControl.hpp".
  • Added a takeoff unit test for basic functionality of states and ramp. It's harder to cover all corner cases but at least we see if it directly breaks.
  • Replaced all = Vector3f(NAN, NAN, NAN); with .setNaN();, initialized all FlightTask members with {}.
  • Simplified thrustToAttitude() implementation.
  • constraints.speed_xy is not used in the controller for a long time so I remove the processing to avoid confusion. Once tasks don't use it internally for communicating speeds accross inheritance anymore we can get rid of the message field.
  • Remove control flags logic for correct logging, adding unit tests to make sure it's still correct.
  • Removing the skip_controller flag is not yet possible with the old _interfaceMapping() but this will be replaced in the next pr.

Test data / coverage
SITL hover goto tested and unit tests pass.

Additional context
Part 4 that goes before this: #13347

@MaEtUgR MaEtUgR requested review from Stifael and bresch December 8, 2019 11:53
@MaEtUgR MaEtUgR self-assigned this Dec 8, 2019
@MaEtUgR MaEtUgR force-pushed the position-control-refactoring5 branch 2 times, most recently from bdcc15c to ffc35f9 Compare December 11, 2019 16:16
Copy link
Member

@bresch bresch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one comment, the reset looks good

@@ -113,7 +113,6 @@ void PositionControl::setConstraints(const vehicle_constraints_s &constraints)
void PositionControl::update(const float dt)
{
if (_skip_controller) {

// Already received a valid thrust set-point.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you maybe extract those next lines

                // Already received a valid thrust set-point.
		// Limit the thrust vector.
		float thr_mag = _thr_sp.length();

		if (thr_mag > _lim_thr_max) {
			_thr_sp = _thr_sp.normalized() * _lim_thr_max;

		} else if (thr_mag < _lim_thr_min && thr_mag > FLT_EPSILON) {
			_thr_sp = _thr_sp.normalized() * _lim_thr_min;
		}

Into a "constrainThrustSetpoint" function?

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 could but this snippet will be gone in the next step so I didn't want to make an effort:
https://github.com/PX4/Firmware/pull/12072/files#diff-dcd121f41884535de662c42a30c6f928R107-R120

Copy link
Member Author

@MaEtUgR MaEtUgR Dec 14, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There will be one place at the end of the update sequence where thrust is limited for all cases and that one I can then break out into a function, good input 👍 :
position-control-refactoring5...acceleration-based-input#diff-dcd121f41884535de662c42a30c6f928R151-R158

@MaEtUgR MaEtUgR force-pushed the position-control-refactoring5 branch from ffc35f9 to 08c397a Compare December 14, 2019 15:53
@MaEtUgR
Copy link
Member Author

MaEtUgR commented Dec 14, 2019

I rebased without conflicts on master.

@bresch
Copy link
Member

bresch commented Dec 14, 2019

@PX4/testflights can you please test this PR in all flight modes on several multicopters?
Thanks in advance!

@MaEtUgR MaEtUgR force-pushed the position-control-refactoring5 branch from 08c397a to 0d2e346 Compare December 14, 2019 18:16
@MaEtUgR MaEtUgR force-pushed the position-control-refactoring5 branch from 0d2e346 to 312e10e Compare December 15, 2019 09:55
@Junkim3DR
Copy link

Junkim3DR commented Dec 16, 2019

Tested on NXP FMUK66 v3

Modes Tested

  • Position Mode: Good.
  • Altitude Mode: Good.
  • Stabilized Mode: Good.

Procedure
Arm and Take off in position mode, after flying for approximately one minute, switched to altitude then stabilized mode.

Notes
No issues noted, good flight in general.

Logs
https://review.px4.io/plot_app?log=920329d4-7468-435a-b258-17a4cfcb860e

Modes Tested

  • Mission Plan Mode (Automated): Good.
  • RTL (Return To Land): Good.

Procedure
Arm and Take off in mission plan mode then make sure that vehicle follows all waypoints as shown in QGC, once completed all waypoint.

Notes
Good flight in general.

Logs
https://review.px4.io/plot_app?log=cc006579-0704-4735-a0fb-d88350890309

Modes Tested

  • Position Mode: Good.
  • Mission Plan Mode (Automated): Good.
  • RTL (Return To Land): Good.

Procedure
Arm and Take off in position mode, after flying for approximately one minute, switched to mission plan mode then make sure that vehicle follows all waypoints as shown in QGC, once completed all waypoint.

Notes
Good flight in general.

Logs
https://review.px4.io/plot_app?log=bf4ef893-d4c3-4c22-bdd9-f63f0f3654d1

@dannyfpv
Copy link

dannyfpv commented Dec 16, 2019

Tested on Pixhawk 4 v5 f450
position mode: no issues
mission mode: no issues
altitude mode: no issues
stabilize mode: no issues

log:
https://review.px4.io/plot_app?log=fef4dbeb-5b69-4b3d-9630-82258cf2f898

@jorge789
Copy link

Tested on PixRacer V4:

Maximum wind 10.2 m/s

Modes Tested

Position Mode: Good.
Altitude Mode: Good.
Stabilized Mode: Good.
Mission Plan Mode (Automated): Good.
RTL: Good.

- Procedure
Arm and Take off in position mode, after flying for approximately one minute, switched to altitude then stabilized mode proceed to switch to mission plan mode then make sure that vehicle follows all waypoints as shown in QGC, once completed all waypoin activate RTL and see landing behaviour.

Notes:
When the vehicle was landing, it did not descend vertically, drifted away with the wind and landed the vehicle manually

Log: https://review.px4.io/plot_app?log=1221ea62-3709-4c9d-bb9a-943495a3ccc3

Log https://review.px4.io/plot_app?log=d6764bd5-f1e4-48cd-a8aa-79828a80ab2e

Copy link
Member

@bresch bresch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went again through the changes and it seems fine to me. You can merge this if the reported log files looks good to you and that CI passes.

@bresch
Copy link
Member

bresch commented Dec 18, 2019

When the vehicle was landing, it did not descend vertically, drifted away with the wind and landed the vehicle manually

@MaEtUgR This is because the tilt is limited to 12 degrees during the whole landing phase. Should be do like for the horizontal and vertical speed: gradually limit the tilt between alt1 and alt2 ?

@MaEtUgR
Copy link
Member Author

MaEtUgR commented Dec 18, 2019

This is because the tilt is limited to 12 degrees during the whole landing phase. Should be do like for the horizontal and vertical speed: gradually limit the tilt between alt1 and alt2 ?

I know this issue. I mostly see when I do some crazy user test going full stick and shortly after takeoff it does a twitch because the tilt limit jumps. The problem is we can't get rid of the tilt limit, that is worse I figured out. Let's do something gradual but I'm fairly confident it's unrelated to this pr.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants