-
Notifications
You must be signed in to change notification settings - Fork 18k
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
Add AP_INVERTED_FLIGHT_ENABLED #24332
base: master
Are you sure you want to change the base?
Add AP_INVERTED_FLIGHT_ENABLED #24332
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you dont have the action for an RC switch shouldn't you remove the init so as to cause a prearm?
909d0d4
to
2fd262e
Compare
Quite right. Fixed. |
Tested in SITL, both with and without compiled in, without issue. |
be good to test inverted in manual with code compiled out, and change to FBWA and it recovers with correct elevator direction |
flight tested and elevator does right thing |
@bnsgeyer I've had a look at this and I don't think we really want to not commit the Copter changes as part of this. We would end up with the Copter code trying to set state in the motors library which doesn't exist, so we'd not compile any more with the new option used (breaking CI IIRC). Could you have a think about these changes and OK them at some stage, please? |
agreed on DevCall that it's OK to lose these bits in their entirety (they're only used internally)
2fd262e
to
85ff579
Compare
031d424
to
307bcd4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like it.
@@ -144,7 +145,9 @@ class RC_Channel { | |||
AVOID_PROXIMITY = 40, // enable object avoidance using proximity sensors (ie. horizontal lidar) | |||
ARMDISARM_UNUSED = 41, // UNUSED | |||
SMART_RTL = 42, // change to SmartRTL flight mode | |||
#if AP_INVERTED_FLIGHT_ENABLED |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the first example of using a define to remove something from the enum. This would start a new pattern.
I do think it is a good idea. The "KILL_IMU" option would be a good candidate too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True.
However, we do it a lot in other enumerations, and I'd put down a little bit of money we'll find at least one thing that's Not Quite when we gate them.
#if AP_INVERTED_FLIGHT_ENABLED | ||
plane.nav_pitch_cd = constrain_float(fw_transition_initial_pitch - (quadplane.tailsitter.transition_rate_fw * dt) * 0.1f * (plane.fly_inverted()?-1.0f:1.0f), -8500, 8500); | ||
#else | ||
plane.nav_pitch_cd = constrain_float(fw_transition_initial_pitch - (quadplane.tailsitter.transition_rate_fw * dt) * 0.1f, -8500, 8500); | ||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer to pull out either the sign or the fly inverted bool and keep just one line of the constrain. I think the maths is easier to understand if there is only one copy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we could take the opportunity to break it up a little.
#if AP_INVERTED_FLIGHT_ENABLED | |
plane.nav_pitch_cd = constrain_float(fw_transition_initial_pitch - (quadplane.tailsitter.transition_rate_fw * dt) * 0.1f * (plane.fly_inverted()?-1.0f:1.0f), -8500, 8500); | |
#else | |
plane.nav_pitch_cd = constrain_float(fw_transition_initial_pitch - (quadplane.tailsitter.transition_rate_fw * dt) * 0.1f, -8500, 8500); | |
#endif | |
float pitch_ramp = quadplane.tailsitter.transition_rate_fw * dt * 0.1; | |
#if AP_INVERTED_FLIGHT_ENABLED | |
if (plane.fly_inverted()) { | |
// Transitioning to inverted flight, pitch up rather than down | |
pitch_ramp *= -1.0; | |
} | |
#endif | |
plane.nav_pitch_cd = constrain_float(fw_transition_initial_pitch - pitch_ramp, -8500, 8500); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we could take the opportunity to break it up a little.
Yep, I did that, and random other changes like it.
And reverted those changes, because I really like to keep these add-defines things as completely no compiler output change in the case that you have not turned the option on. It means that no existing user will ever run into problems with the code.
I've achieved that with this PR now, and updated the blocks in the opening comment appropriately.
It does uglify the code a bit, but I do plan on going back to the places and cleaning it up by factoring bits and pieces. Especially the bit in takeoff.cpp. The block that patch is in will make for a nice new method with earl returns etc, something like:
if (do_takeoff_attitude_check &&
!takeoff_attitude_is_good()) {
gcs().send_text(MAV_SEVERITY_WARNING, "Bad launch AUTO");
takeoff_state.accel_event_counter = 0;
goto no_launch;
}
}
// Check aircraft attitude for bad launch
bool takeoff_attitude_is_good(void) const
{
if (ahrs.pitch_sensor <= -3000 || ahrs.pitch_sensor >= 4500) {
return false;
}
#if AP_INVERTED_FLIGHT_ENABLED
if (fly_inverted()) {
// skip roll check if we're *supposed* to be upside-down
return true;
}
#if endif
if (labs(ahrs.roll_sensor) > 3000) {
return false;
}
return true;
}
}
I think that's the same logic, but I'm not convinced it's good logic.... e.g. should those pitch limits be the other way around if you're inverted? Why aren't we checking roll when inverted?
Give I think we now have a partner who flies this way, we should probably give it more serious consideration now, and I think this would make for a good separate PR...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've created a patch on top of this over here which shows things prettied up a bit:
https://github.com/ArduPilot/ardupilot/compare/master...peterbarker:ardupilot:pr/inverted-flight-tidy?expand=1
ead7871
to
2b89777
Compare
2b89777
to
355df40
Compare
355df40
to
a33c31c
Compare
Not so much for the space, but to avoid accidents.
... and with it disabled: