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

Feature/First iteration on MC failsafe #5863

Closed

Conversation

anton-matosov
Copy link
Contributor

Add failsafe tune
Fix LED blinking for Pixracer
Pass rc_loss_mode instead of simple bool flag
Add setting of failsafe PWM outputs in case of force_failsafe

@LorenzMeier
Copy link
Member

Nice!

@LorenzMeier
Copy link
Member

@kd0aij Can you test?

@kd0aij
Copy link
Contributor

kd0aij commented Nov 15, 2016

What is rc_loss_mode supposed to do? I guess this should fix the flight termination bug I mentioned in the RC loss PR... need to reference it from here.

@anton-matosov anton-matosov mentioned this pull request Nov 15, 2016
@kd0aij
Copy link
Contributor

kd0aij commented Nov 16, 2016

what about #5388?

@anton-matosov
Copy link
Contributor Author

Rc_loss_mode is enum that's is not used right now, but it should define behavior of RC loss failsafe action. With current code it switches to "land" mode, and there is no way to force termination
I took a brief look at your PR and it does some of what I am missing right now regarding applying failsafe during termination. But it also does some stuff a bit brute force (e.g. applying lockdown from commander state machine)
I will incorporate your fixes into my PR, so it will be a complete solution (right now it drops output to minimum pwm upon termination)

@@ -2881,7 +2881,7 @@ int commander_thread_main(int argc, char *argv[])
_mission_result.stay_in_failsafe,
&status_flags,
land_detector.landed,
(rc_loss_enabled > 0),
rc_loss_mode,
Copy link
Contributor

Choose a reason for hiding this comment

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

I like this change but does it change the behaviour at all like this?

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, it doesn't, yet.
I have never seen Navigator before. What is it used for?
It looks like it has very similar logic as commander for data/rc links and GPS, but handles it in its own way.

Copy link
Member

Choose a reason for hiding this comment

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

In my opinion, the handling of RC and DL loss should move back from the navigator to the state machine (as done here with offboard actions: #4655)

Copy link
Member

Choose a reason for hiding this comment

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

The navigation states itself can still implement complex logic as it is the case for things that got added for OBC 2014, but no separate/duplicate state switching

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I read more commander and navigator code and now feel the difference of their responsibilities.
(Please correct me if I am wrong)
Navigator simply performs 'pieces' of the autonomous navigation, it doesn't make a decision.
Commander is that one that maintains the global state of the vehicle based on params, user and sensor inputs and makes all the decisions of what action to take in particular situation.

If my understanding is correct then I am 100% agree that rc_loss_mode should be handled in commander (SM helper), not navigator.

My only concern is that SM helper keeps growing and already has a big chunk of copy-pasted code. I feel a bit worried of breaking things by doing change to RC loss like this without having really good understanding and having unit tests covering the logic.

Copy link
Contributor

Choose a reason for hiding this comment

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

@anton-matosov I think you got it right, that's very much the way it was designed. If you're concerned about breaking the state machine helper the way to resolve that would be to add tests to and then extend or refactor it.

@anton-matosov
Copy link
Contributor Author

Ok. I think that's what I am going to do then. I will write tests at least for code I am going to modify for SM Helper and navigator. Are there any existing tests?

@dagar
Copy link
Member

dagar commented Nov 17, 2016

@AndreasAntener
Copy link
Member

@anton-matosov what do you plan to change in the state machine helper? Because I'm reworking this at the moment and implemented a different way of how the failures are handled (more comprehensive), also adding unit tests.

@anton-matosov
Copy link
Contributor Author

@AndreasAntener I am planning to refactor RC and Datalink loss code to get rid of the copy-paste and migrate RC/Data loss mode switching to commander out from Navigator the same way offboard loss modes are handled.
Also I will extend loss mode to force termination mode. (that is what I need for FPV racers)

1 similar comment
@anton-matosov
Copy link
Contributor Author

@AndreasAntener I am planning to refactor RC and Datalink loss code to get rid of the copy-paste and migrate RC/Data loss mode switching to commander out from Navigator the same way offboard loss modes are handled.
Also I will extend loss mode to force termination mode. (that is what I need for FPV racers)

@LorenzMeier LorenzMeier added this to the Release v1.5.0 milestone Nov 19, 2016
@anton-matosov
Copy link
Contributor Author

@AndreasAntener are you done with your refactoring of the commander's SM?
Which fork/branch are you working in? (so I can merge in your changes and keep going)

@AndreasAntener
Copy link
Member

@anton-matosov I think we should separate the refactoring from your functionality change (termination handling). I'll push a branch in a sec that contains the move from navigator, after I can build upon that again.

@AndreasAntener
Copy link
Member

AndreasAntener commented Nov 20, 2016

@anton-matosov added a PR for you (#5884), please have a look. You can integrate the changes from there into your branch and delete it, or whatever is easier for you

@anton-matosov
Copy link
Contributor Author

@AndreasAntener @LorenzMeier @kd0aij @Tumbili @julianoes PR is ready for review

@LorenzMeier
Copy link
Member

Thanks! I did a first pass and it overall looks good. A couple of questions:

  • What was the driver behind adding manual_lockdown in addition to the lockdown flag? Was it necessary to have both?
  • Do you require manual RC input in SITL? I saw you added it back?
  • Can you explain more about the build system changes? They look ok, but I'd like to understand the use case.

Please try to describe this in general when submitting a PR, since those are changes that need context. Thanks!

@anton-matosov
Copy link
Contributor Author

anton-matosov commented Nov 30, 2016

What was the driver behind adding manual_lockdown in addition to the lockdown flag? Was it necessary to have both?

If you have kill switch configured on RC, lockdown will be constantly reset to the killswitch position and it can't be used from other code.

Do you require manual RC input in SITL? I saw you added it back?

I was using manual RC for the RC loss testing and I made it off by default (configurable in CMakeLists). I will also need it for RC expo rates code testing in simulator.

Can you explain more about the build system changes? They look ok, but I'd like to understand the use case.

I have added wrapper for px4 that includes paths originally provided via the command line by cmake+sitl_run.sh. The original approach was not allowing easy debugging from IDE (I use CLion). With current approach you can simply chose simulator target you want to debug, e.g. px4_iris and simply hit debug button and it will build and start debug session with no need to configure bunch of run parameters.
I have also added IDE parameter to debuggers which is handled in a way of skipping launching px4 from sitl_run.sh that allows simple start/stop of px4 debugging from IDE without the need to restart viewer (I was using gazebo)

Please try to describe this in general when submitting a PR, since those are changes that need context. Thanks!

Sure. I will definitely do this next time

@anton-matosov
Copy link
Contributor Author

@LorenzMeier any updates?

@julianoes
Copy link
Contributor

@anton-matosov will review this weekend, thanks for your work.

@anton-matosov
Copy link
Contributor Author

Thanks @julianoes

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.

Reviewed, this already looks cleaner but I need to review the failsafe nav state part in detail.

I'm a bit confused what the build system changes are for.

@@ -135,6 +135,15 @@ then
elif [ "$debugger" == "valgrind" ]
then
valgrind $sitl_command
elif [ "$debugger" == "ide" ]
Copy link
Contributor

Choose a reason for hiding this comment

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

Make sure to document this somewhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Any suggestions on where to put docs for this?

/* overwrite outputs in case of force_failsafe */
if (_failsafe) {
for (size_t i = 0; i < num_outputs; i++) {
outputs.output[i] = 600;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why 600? That seems very low. Usually we have 900 in that case, and there should be a define.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I chose 600 as a magic for PWM Simulator failsafe as it doesn't read values from settings (might need to add this instead) and I needed some distinguishable value from disarmed to easily debug failsafe and not confuse with other states.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have moved 600 and 900 to named constants.
It doesn't make sense to read params as they are not configured for any simulator

FILES ${CMAKE_CURRENT_BINARY_DIR}/${APP_NAME}
${PX4_SOURCE_DIR}/posix-configs/eagle/flight/mainapp.config
DEPENDS ${APP_NAME}
DEST /home/linaro)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'll need to test this on Snapdragon to make sure there are no regressions.

offboard_loss_act,
offboard_loss_rc_act);
/* now set navigation state according to failsafe and main state */
bool nav_state_changed = set_nav_state(&status,
Copy link
Contributor

Choose a reason for hiding this comment

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

Strange, so here the indent has changed but I think it was correct before.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, will fix that

Copy link
Contributor Author

Choose a reason for hiding this comment

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

make format doesn't catch this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indent have changed from tabs to spaces.
Many files have mixed formatting...
What does the coding standard for px4 says about tab/spaces and what is the tab size used on the project (needed for mixed lines)?

Copy link
Member

Choose a reason for hiding this comment

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

Everything has to be tabs and default is 8 width (if you use Sublime, you get a decent default). Anything having mixed formatting is the result of style checking not being enforced yet (e.g. in the commander). We're cleaning up module-by-module and probably should enforce style when this PR is in.

}
} else {
/* armed, solid */
led_on(LED_BLUE);
Copy link
Contributor

Choose a reason for hiding this comment

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

Am I right that LED_GREEN is undefined in the non failsafe case and left at whatever it was toggled to last?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Most likely you are right. I will double check and fix. Good catch!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added missing led_off(LED_GREEN);

@@ -1040,6 +1040,63 @@ MulticopterAttitudeControl::task_main()
_controller_status_pub = orb_advertise(ORB_ID(mc_att_ctrl_status), &_controller_status);
}
}

if (_v_control_mode.flag_control_termination_enabled) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this be taken care off in the drivers instead of the controllers?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This where I have stared based on the FW_att_control but I couldn't stop motors from here.
For lockdown we don't really need anything, but for termination it is the a kind of only place to do something.
IMO drivers should not know about flight control modes and take actions based on this.

Copy link
Member

Choose a reason for hiding this comment

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

@anton-matosov The whole diff / PR makes sense, this is the only section I don't get yet entirely.

Are you trying to prevent an integrator windup here or is this needed to stop the props?

} else { /* if == 2 or unknown, RTL */
_navigation_mode = &_rtl;
}
_navigation_mode = &_rcLoss;
Copy link
Contributor

Choose a reason for hiding this comment

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

This is much cleaner and moves the responsibility to the commander. I think that's the right approach.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Cudos to @AndreasAntener

@@ -0,0 +1,39 @@
/****************************************************************************
*
* Copyright (c) 2016 Anton Matosov. All rights reserved.
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be PX4 Development Team, I think.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Emmm... I am not part of that team, so I don't think I should put your name on my changes.

Copy link
Contributor

Choose a reason for hiding this comment

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

It's just the default header in general, not sure.

@@ -1,6 +1,7 @@
/****************************************************************************
*
* Copyright (c) 2015 Mark Charlebois. All rights reserved.
* Copyright (c) 2016 Anton Matosov. All rights reserved.
Copy link
Contributor

Choose a reason for hiding this comment

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

And the same here actually.

return errno;
}
const char *argsOverride[] = {argv[0], "@SITL_RUNNER_SOURCE_DIR@", "@SITL_RUNNER_MODEL_FILE@"};
return SITL_MAIN(sizeof(argsOverride) / sizeof(argsOverride[0]), (char**)argsOverride);
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm gonna push back on this change, I think it conflicts heavily with upcoming changes in #5162.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't see any conflicts with your PR (on logic/behavior level, didn't dive in code yet)
But to make it cleaner I will separate build system/debugging changes from failsafe code and submit them as separate PR

Copy link
Contributor

Choose a reason for hiding this comment

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

That would be better, thanks.

set_link_loss_nav_state(status, armed, status_flags, link_loss_act, vehicle_status_s::NAVIGATION_STATE_AUTO_RTGS);
}

void set_link_loss_nav_state(struct vehicle_status_s* status,
Copy link
Contributor

Choose a reason for hiding this comment

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

Oh I realize now what you are doing here. It seems quite complicated, in my opinion we need to simplify this all.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What exactly looks complicated here? This is mostly port of the link loss code from the navigator to commander + 2 new action types.
I have introduced enum for actions instead of using magic numbers and merged handlers for RC and data loss as the are the same except 1 nav state.

Copy link
Contributor

Choose a reason for hiding this comment

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

Got it. Were you already able to test most/all the cases?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have not tested all the cases.

@anton-matosov
Copy link
Contributor Author

@julianoes can you please take a look at the latest changes that address your comments?

@anton-matosov
Copy link
Contributor Author

@LorenzMeier @julianoes I have applied suggested changes. Please review again.

Move RC and DL failsafe actions handling from navigator to commander (credits to @AndreasAntener)
Separate manual kill switch handling via manual_lockdown to prevent override and release of software lockdown by RC switch

Other changes:
Add failsafe tune
Fix LED blinking for Pixracer
Return back support for rc inputs in simulator but now it is configurable via cmake
@LorenzMeier
Copy link
Member

@anton-matosov Thanks, much appreciated! I'm going to try to get this in tomorrow.

@LorenzMeier
Copy link
Member

Awesome! This is ready to go, one last question. @anton-matosov Great work!

@LorenzMeier
Copy link
Member

Rebased and continuing here:
#6177

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.

None yet

8 participants