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: do not reboot on USB disconnect when armed #9664

Merged

Conversation

korigod
Copy link
Contributor

@korigod korigod commented Jun 13, 2018

This commit fixes in-flight reboot on USB disconnect. Flying with USB can be discussed in issue #9663, but whether it's recommended or not it is possible on the default firmware so it looks reasonable to fix this unnecessary risk of crash because of in-flight reboot.

@dagar
Copy link
Member

dagar commented Jun 13, 2018

Isn't the core problem that we aren't respecting the arming state machine for reboot?

image

@korigod
Copy link
Contributor Author

korigod commented Jun 13, 2018

Using arming_state_transition to reboot can be a solution but reboot is not implemented in state_machine_helper.cpp. Is it intentional or just not done yet?

Of course it's possible to call arming_state_transition and then call px4_shutdown_request if that call haven't returned TRANSITION_DENIED, but it's significantly more complicated than direct !armed.armed check.

@dagar
Copy link
Member

dagar commented Jun 13, 2018

It's a bit messy, but not that complicated.

	if (TRANSITION_DENIED != arming_state_transition(&status, battery, safety, vehicle_status_s::ARMING_STATE_REBOOT,
		&armed, false, &mavlink_log_pub, &status_flags, arm_requirements, hrt_elapsed_time(&commander_boot_timestamp))
	) {
		// reboot
	}

You could wrap that mouthful in a bool reboot() helper or similar and we could start addressing the other questionable areas.

The point is that no one other than the state machine should have ever been deciding this. As easy as it is to do the quick fix, at some point we have to start taking the first steps towards a proper safe fix before commander complexity gets completely out of hand.

@korigod
Copy link
Contributor Author

korigod commented Jun 13, 2018

Ok, but in commander.cpp there are not only reboot requests (px4_shutdown_request(true, false)), but also requests for shutdown (px4_shutdown_request(false, false)). If the former are controlled by a state machine, shouldn't the latter be controlled by it too? Or maybe it should be only ARMING_STATE_SHUTDOWN as it is more generic? Then we request transition to ARMING_STATE_SHUTDOWN in cases of both reboot and shutdown.

@korigod korigod force-pushed the pr-commander-do_not_reboot_when_armed branch from 873234b to 18dd8a2 Compare June 13, 2018 21:34
@korigod
Copy link
Contributor Author

korigod commented Jun 19, 2018

@dagar, please review. If you believe ARMING_STATE_REBOOT renaming is questionable, I can remove these commits and open another pull request for them.

@dagar dagar self-requested a review August 3, 2018 23:13
@dagar dagar added this to the Release v1.9.0 milestone Jan 2, 2019
@PX4 PX4 deleted a comment from stale bot Jul 15, 2019
@stale stale bot removed the Admin: Wont fix label Jul 15, 2019
julianoes
julianoes previously approved these changes Jul 15, 2019
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.

Looks correct to me, thanks!

@julianoes
Copy link
Contributor

@korigod could you rebase this and fix the conflicts so we can get it in? Thanks.

@korigod korigod force-pushed the pr-commander-do_not_reboot_when_armed branch 3 times, most recently from 4937a7f to 692aea5 Compare July 15, 2019 20:28
@korigod
Copy link
Contributor Author

korigod commented Jul 15, 2019

@julianoes, my colleagues will perform test flights in a few days to make sure everything is all right and then we can merge. Thanks!

@mcsauder
Copy link
Contributor

@korigod , I discussed this recently with @dagar , and the good point he brought up was the additional CPU load for each running mavlink instance, roughly 6%-8% per instance. Be sure to post a log that the CPU load can be scrutinized. For the general population, it won't matter as this only impacts post-arm, but that is also when it will be most important for CPU loads.

You PR looks good to me.

@sfalexrog
Copy link
Contributor

As per @korigod's request, I've performed some bench tests on a Pixracer-based drone. In all cases I've armed the drone manually, increased the throttle slightly, disconnected and reconnected the USB cable. In order to get the second MAVLink stream I've used the mavlink_shell.py script from PX4.

The results are as follows:

@mcsauder
Copy link
Contributor

mcsauder commented Aug 1, 2019

@korigod , would you rebase again? (It looks like it will pass CI once you rebase it.)

@korigod korigod force-pushed the pr-commander-do_not_reboot_when_armed branch from 692aea5 to b9dac93 Compare August 1, 2019 14:17
@korigod
Copy link
Contributor Author

korigod commented Aug 3, 2019

@mcsauder, indeed, it passes the checks now.

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.

Thanks everyone.

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