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

commander: move more static variables to class #13613

Merged
merged 21 commits into from
Dec 24, 2019
Merged

Conversation

dagar
Copy link
Member

@dagar dagar commented Nov 27, 2019

No description provided.

@dagar
Copy link
Member Author

dagar commented Nov 27, 2019

The next little incremental step that would help is if we transition (or kill) the command line helpers to vehicle commands (calibrate, arm, disarm, mode, etc).

https://github.com/PX4/Firmware/blob/214e9c8244bfca72a319694ae222727f658ca6c1/src/modules/commander/Commander.cpp#L334-L491

@dagar
Copy link
Member Author

dagar commented Nov 27, 2019

Future work

  1. command line
    • commander calibrate move to vehicle_command
    • commander check move to vehicle_command? (not currently possible)
    • commander arm move to vehicle_command
    • commander disarm move to vehicle_command
    • commander takeoff move to vehicle_command
    • commander land move to vehicle_command
    • commander transition move to vehicle_command
    • commander mode move to vehicle_command
    • commander lockdown move to vehicle_command
  2. commander_low_prio_loop
    • VEHICLE_CMD_PREFLIGHT_REBOOT_SHUTDOWN move to commander?
      • likely in the low priority loop to sleep first while sending the update to the user
    • VEHICLE_CMD_PREFLIGHT_CALIBRATION
      • needs to change arming state with a vehicle_command instead of directly
      • stop touching status and status_flags directly (eg status_flags.rc_input_blocked = false)
      • if all interaction moves to vehicle_commands then calibrate can be moved out of command entirely
    • VEHICLE_CMD_START_RX_PAIR move to commander?

@MaEtUgR
Copy link
Member

MaEtUgR commented Nov 27, 2019

transition (or kill) the command line helpers to vehicle commands

Makes sense, @julianoes also brought that up today. What about the acks? For the developer it's nice to have a response but e.g. for the calibration state command it's safety critical.

commander check

I wouldn't worry about this one too much. I want to run the checks periodically and the commander status will give read-only output about that. Credit to @bkueng , came up when dicussing with him.

VEHICLE_CMD_PREFLIGHT_REBOOT_SHUTDOWN move to commander?

I would say so. The check if it's possible has to be lightweight and when it's actually executed blockage if any is likely not a huge issue anymore.

VEHICLE_CMD_START_RX_PAIR move to commander?

The command executing RC driver should directly acknowledge instead of the commander.

Very good inputs, thanks!!

@dagar dagar force-pushed the pr-commander_minor branch 2 times, most recently from 2e7562d to 494fe6a Compare November 27, 2019 20:58
@dagar dagar requested a review from julianoes November 27, 2019 20:59
@dagar
Copy link
Member Author

dagar commented Nov 27, 2019

We can update the vehicle command helper to send the command, then poll vehicle_command_ack for a response.

https://github.com/PX4/Firmware/blob/494fe6ab388e5fa8b191347924cabcb8d2349d98/src/modules/commander/Commander.cpp#L169-L198

@dagar dagar requested a review from a team November 27, 2019 21:21
@dagar dagar force-pushed the pr-commander_minor branch from b09ca4c to e43439b Compare November 27, 2019 21:53
@dagar
Copy link
Member Author

dagar commented Nov 27, 2019

I removed the power_button_state callback handling from commander. If anyone still wants it we can find a more appropriate location for it. Updated: I'll save this for a followup.

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.

I went through all the changes in great detail. Overall it looks like a very nice improvement of readability, scopes, initialization and parameter handling.

I report the most significant comments that came to my mind the rest are just ideas for further improvement that I can follow up with.

src/modules/commander/Commander.hpp Outdated Show resolved Hide resolved
src/modules/commander/Commander.hpp Outdated Show resolved Hide resolved
src/modules/commander/Commander.cpp Outdated Show resolved Hide resolved
src/modules/commander/Commander.hpp Show resolved Hide resolved
src/modules/commander/Commander.cpp Show resolved Hide resolved
src/modules/commander/Commander.cpp Show resolved Hide resolved
src/modules/commander/Commander.cpp Show resolved Hide resolved
src/modules/commander/Commander.cpp Outdated Show resolved Hide resolved
src/modules/commander/Commander.cpp Outdated Show resolved Hide resolved
src/modules/commander/Commander.cpp Outdated Show resolved Hide resolved
@dagar
Copy link
Member Author

dagar commented Nov 29, 2019

Thanks for the thorough review. I have a few more commits coming that get everything except vehicle_status, vehicle_status_flags, and actuator_armed into the class.

To get the rest under control (and kill/move the commander low priority loop) what we're missing is a mechanism to specifically enter ARMING_STATE_INIT during calibration, and then back to ARMING_STATE_STANDBY once complete.

@jorge789
Copy link

jorge789 commented Dec 2, 2019

Tested on PixRacer V4:

Flight Card 1

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 were noted, good flight in general.

Logs: https://review.px4.io/plot_app?log=eddc7cef-5af6-40af-b39e-eccaa4d5bed4

Flight Card 2

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

Procedure

Armed form QGC.
Took-off on mission plan mode
. Note that commands were sent form QGC (Armed and takeoff)
Once all waypoint completed vehicle switched to RTL and landed as expected.
Good flight in general.
Note:
No issues were noted, good flight in general.

Logs: https://review.px4.io/plot_app?log=7c08c14f-a8b1-4a77-9996-c52f75517a0d

Flight Card 3
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 see landing behavior.
Good flight in general.
Note:
No issues were noted, good flight in general.

Logs: https://review.px4.io/plot_app?log=f1d090ec-c406-49ff-b0e8-14ba29b16f94

Flight Card 4
Modes Tested
Fail safe:The radio control turned off and the vehicle returned and landed correctly.
Tested good.

Logs: https://review.px4.io/plot_app?log=faf21f96-c658-4cd0-9bd0-3219d9d6346c

@dannyfpv
Copy link

dannyfpv commented Dec 2, 2019

Tested on Pixhawk 4 v5 f-450
Flight Card 1

Modes Tested:
Position Mode: Good.
Altitude Mode: Good.
Stabilized Mode: Good.

Procedure:
Arm and Takeoff in position mode, after flying for approximately one minute, switched to altitude then stabilized mode.
Notes:
No issues were noted, good flight in general.

Log:
https://review.px4.io/plot_app?log=75494cfe-3c3d-42a0-9626-fba45b1f0de4

Flight Card 2

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

Procedure

Armed form QGC.
Took-off on mission plan mode
Note that commands were sent form QGC (Armed and takeoff)
Once all waypoint completed vehicle switched to RTL and landed as expected.
Good flight in general.
Note:
No issues were noted, good flight in general.

Logs:
https://review.px4.io/plot_app?log=3907135f-036d-401e-8ae9-c472817bb2de

Flight Card 3
Modes Tested
Position Mode: Good.
Mission Plan Mode (Automated): Good.
RTL (Return To Land): Good.

Procedure
Arm and Takeoff 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 see landing behavior.
Good flight in general.
Note:
No issues were noted, good flight in general.

Logs:

https://review.px4.io/plot_app?log=d26ed441-b2d9-4b59-aaa4-4c13b56c483a

Flight Card 4
Modes Tested
Fail-safe:The radio control turned off and the vehicle returned and landed correctly.
Tested good.

log:
https://review.px4.io/plot_app?log=d1655753-fb5c-474d-be17-59790869e2c8

Copy link
Contributor

@julianoes julianoes left a comment

Choose a reason for hiding this comment

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

Better!

if (TRANSITION_DENIED == arm_disarm(false, true, &mavlink_log_pub, "command line")) {
PX4_ERR("rejected disarm");
}
send_vehicle_command(vehicle_command_s::VEHICLE_CMD_COMPONENT_ARM_DISARM, 0.f, 0.f);
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice, that's safer!


return 0;
}

if (!strcmp(argv[1], "takeoff")) {
// switch to takeoff mode and arm
send_vehicle_command(vehicle_command_s::VEHICLE_CMD_NAV_TAKEOFF);
send_vehicle_command(vehicle_command_s::VEHICLE_CMD_COMPONENT_ARM_DISARM, 1.f, 0.f);
Copy link
Contributor

Choose a reason for hiding this comment

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

Hang on, first you need to arm and then send a takeoff, right?

Copy link
Member

Choose a reason for hiding this comment

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

That's indeed how it was done before: https://github.com/PX4/Firmware/blob/fbcc6a96bc89d14806126c14d70b9a0585dcdb6d/src/modules/commander/Commander.cpp#L412-L413
but I think QGC also switches to takeoff first and then arms.
If you'd ask me a takeoff command should do whatever is necassary to take off...

if (shutdown_if_allowed()) {
bool shutdown_ret_val = PX4_ERROR;

if (((int)(cmd.param1)) == 1) {
Copy link
Contributor

Choose a reason for hiding this comment

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

No, I think we should be using roundf everywhere for these params.

bool StateMachineHelperTest::run_tests()
{
ut_run_test(armingStateTransitionTest);
ut_run_test(mainStateTransitionTest);
ut_run_test(isSafeTest);
Copy link
Contributor

Choose a reason for hiding this comment

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

no more isSafe? 😁

Copy link
Member

Choose a reason for hiding this comment

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

sounds good, turns out to be useless 😄

@dagar
Copy link
Member Author

dagar commented Dec 14, 2019

@dagar Should I add a commit for my suggestions? Or do we merge since I don't see any blocking problem and I can follow up with my suggestions in a new pr?

In general you should feel free to commit the ones you're sure about. At this point let's try to get the current state merged with most, but not all suggestions applied and keep going with smaller followup PRs.

@dagar
Copy link
Member Author

dagar commented Dec 14, 2019

I'm hitting issues with the designated initializers, which don't seem to actually be a part of c++11.

@dagar dagar force-pushed the pr-commander_minor branch from 9d82e9e to abb7539 Compare December 14, 2019 16:46
@dagar
Copy link
Member Author

dagar commented Dec 14, 2019

@PX4/testflights could we please get another round of testing on this one?

@julianoes @MaEtUgR if you can, please give this PR a quick run through with anything you normally use (eg the command line helpers for takeoff, arm, etc). There's a lot more change in this PR than originally intended, including areas with no code coverage.

@Junkim3DR
Copy link

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=0034b2d7-43ff-4ec7-abab-fcdad5d0cbe7

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 see landing behavior.

Notes
Good flight in general.

Logs
https://review.px4.io/plot_app?log=8dc6e083-3bd7-48b3-80ac-3ace1ff36a45

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 see landing behavior.

Notes
Good flight in general.

Logs
https://review.px4.io/plot_app?log=3b1599f1-4bb7-4304-82ae-282502b02559

@jorge789
Copy link

Tested on PixRacer V4:

Maximum wind 10.2 m/s

Flight Card 1

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:
Maximum wind 10.2 m / s

Logs: https://review.px4.io/plot_app?log=17f640c2-9418-47bc-8d83-85edcd9f656c

Flight Card 2

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

Procedure

Armed form QGC.
Took-off on mission plan mode
. Note that commands were sent form QGC (Armed and takeoff)
Once all waypoint completed vehicle switched to RTL and landed as expected.
Good flight in general.
Note: Maximum wind 10.2 m / s
Note:When the vehicle was landing, it did not descend vertically, drifted away with the wind and landed the vehicle manually

Logs: https://review.px4.io/plot_app?log=b0f1f872-fc9e-41ee-89e3-4e146862efc7

Flight Card 3
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 see landing behavior.
Good flight in general.
Note: Maximum wind 10.2 m / s
Note: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=a8a1391c-06c0-475e-943a-48bea5da2e24

@dannyfpv
Copy link

dannyfpv commented Dec 16, 2019

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

log:
https://review.px4.io/plot_app?log=239897f0-7312-4206-909a-cf2e38da969b

@dagar
Copy link
Member Author

dagar commented Dec 17, 2019

Thanks everyone! I'm going to merge this so we can keep going. Please pay particular attention to any potential commander regressions. We still have quite a lot to do before this module is under control.

@dagar
Copy link
Member Author

dagar commented Dec 17, 2019

This pushes the flash slightly over the v2 limit. Looks like I'll need to bring it something like #12601 first.

@MaEtUgR
Copy link
Member

MaEtUgR commented Dec 18, 2019

#13596 might give you some space

@dagar dagar merged commit 0e70578 into master Dec 24, 2019
@dagar dagar deleted the pr-commander_minor branch December 24, 2019 04:38
bkueng added a commit that referenced this pull request Feb 20, 2020
Regression from #13613.

VEHICLE_CMD_COMPONENT_ARM_DISARM from CLI would enter the
ARMING_STATE_IN_AIR_RESTORE logic. This was never intended for disarming
(and leads to state machine transition failures), and IMO it is also not
intended for commands from CLI.
dagar pushed a commit that referenced this pull request Feb 20, 2020
Regression from #13613.

VEHICLE_CMD_COMPONENT_ARM_DISARM from CLI would enter the
ARMING_STATE_IN_AIR_RESTORE logic. This was never intended for disarming
(and leads to state machine transition failures), and IMO it is also not
intended for commands from CLI.
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.

7 participants