-
Notifications
You must be signed in to change notification settings - Fork 13.7k
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
[WIP] Legacy auto manual replacement #9368
Conversation
a3ff249
to
1bf9803
Compare
@RomanBapst Could you please review? Given the current flash limitations, I think we will make a full switch. |
64c4e35
to
b261530
Compare
27c5079
to
d04b1ae
Compare
About this PR:
FlightTaskThe details about FlightTask were already covered in other PRs and discussions (for instance here). Flight-mode specific functionality were moved from mc_pos_control_main to a new task within FlightTask. The tasks are the following:
All tasks should be identical to the legacy code except with some changes to make it better fit into the FlightTask-framework:
PositionControlThis class contains the CORE-position/velocity controllers. The inputs are the position-, velocity-, acceleration- (not supported), thrust-, yaw- and yawspeed setpoints and outputs a thrust vector and yaw-/yawspeed-septoint. mc_pos_control_mainThis module is basically the interface between FlightTask and PositionControl. It makes adjustments to FlightTask setpoints based on vehicle state. For instance, it enables a smooth-takeoff, it keeps throttle low when being landed, it adjusts the thrust setpoint based on the landdetector state and so on. It also converts the thrust and yaw setpoint from PositionControl to a desired attitude and publishes it. Flight-testsSo far I have tested the following modes:
It would be great if we can start to collect more flight hours for all different modes. When testing position and altitude mode, please keep in mind that NO smoothing is active. This is on purpose to make it easier to track down any unexpected bug. As I mentioned above, in any manual controlled mode the speed downwards/upwards close to ground is only limited by the global limits MPC_Z_VEL_MAX_DN/UP. ConventionsI started to use a different style method for parameters and comments. It is not consistent yet and If I am the only one who sees the benefit in it, then I will revert it of course. commentsthe doxygen style that I started to use is the one already present in most modules:
parameter namingInstead of creating a name for a parameter, I just reused the meta-data parameter name. For instance, the parameter within a module that uses the MPC_XY_CRUISE parameter would be called MPC_XY_CRUISE as well. In my opinion, this has the following benefits:
Independent of this PR, I think it could be highly beneficial if we have more style related guidelines which are not covered by astyle. I can open a new issue to discuss possible code guidelines if desired. Currently this branch fails because of: I saw that this error has popped up in the past already (https://github.com/PX4/Firmware/blob/master/src/systemcmds/tests/test_matrix.cpp#L628-L629). |
the ci fails for one of the unit-tests. In the worst case I can just remove the unit test to make the ci pass |
It's a compiler issue, if you drill down into ControlMathTest::testPrioritizeVector() it's likely only 1 or 2 offending lines. |
I found now the line that caused the compilation problem. |
// until he toggles the switch to avoid retracting the gear immediately on takeoff. | ||
int8_t gear_switch = _sub_manual_control_setpoint->get().gear_switch; | ||
|
||
if (!_constraints.landing_gear) { |
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 think _evaluateSticks()
should only get the gear switch state and all the logic executing on it should be in a different function, here _applyGearSwitch()
.
|
||
} else { | ||
// altitude based on locale coordinate system | ||
_dist_to_ground_lock = NAN; // reset boolean since not used |
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.
It's not a boolean...
Altitude mode takeoff and altitude hold near the floor is sadly broken. I had the following cases tested with
I'm trying to find out what the root cause is but it needs to have something to do with EDIT:
Still doesn't explain why somethimes I cannot take off with my SITL. I'll try to reproduce with some conditions hardcoded like a unit test... EDIT2: EDIT3: I didn't have a valid local position with flow because my computer ran the simulation too slow and the data didn't pass the checks but the same problem applies if you loose your last position estimate source which is usually GPS. -> @Stifael That's a problem. |
|
||
float32 yawspeed # in radians/sec | ||
float32 speed_xy # in meters/sec | ||
float32 speed_up # in meters/sec |
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.
the setpoint which gets constrained is called vz
so why not call the constraint constraint.vz_up
?
|
||
matrix::Dcmf _R_setpoint; | ||
hrt_abstime _last_warn = 0; /**< timer when the last warn message was sent out */ | ||
static constexpr uint64_t IDLE_BOFORE_TAKEOFF_TIME_US = |
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.
Why should we wait for a hardcoded 2.5 seconds until the position controller realizes that the vehicle was armed?
_vel_sp_prev(0) = _vel(0); | ||
_vel_sp_prev(1) = _vel(1); | ||
// Fill attitude setpoint. Attitude is computed from yaw and thrust setpoint. | ||
_att_sp = ControlMath::thrustToAttitude(thr_sp, _control.getYawSetpoint()); |
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.
thrustToAttitude()
holds its own copy of the complete attitude setpoint message. That overhead can be saved by reseting the outside attitude setpoint message and passing a reference to the function such that it can fill the fields.
matrix::Eulerf euler = R_sp; | ||
att_sp.roll_body = euler(0); | ||
att_sp.pitch_body = euler(1); | ||
|
||
/* fill and publish att_sp message */ | ||
// fill and publish att_sp message |
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.
it's actually not published here...
@MaEtUgR thanks for the testing and comments. |
91205bb
to
7952da6
Compare
Rebase? |
…ctive and below minimum distance to ground.
…hich corresponds to position lock.
d9e1e79
to
45d5767
Compare
@santiago3dr @Avysuarez thanks again for testing. Would it also be possible to test position control with flow enabled? |
couple flights with the new commit . |
This is currently required because it can cause conflit with offboard attitude control where attitude setpoint are sent from mavlink_receiver and from mc_pos_control simultaneously.
I'm starting to rebase with a similar scheme like the flight task introduction pr from last time. We (@Stifael @RomanBapst) dicussed this yesterday in a call. The functionality should not change except for the yawspeed setpoint rescaling (see https://github.com/YUNEEC/Firmware/pull/2069/commits/500ffe5a622f85c0de409f0c9da233b8b5be3d7b for reference) which I will point out afterwards. |
I pushed first rebase work to a new branch https://github.com/PX4/Firmware/tree/pr-flight-task-iteration to reduce confusion because the it's in terms of history quite different. The principle is the same as with the first flight task pr: I rebase all the files except for mc_pos_control_main.cpp because that is the file generating the huge pile of conflicts. Now I'll adjust that file to match the diff and not loose any of the changes in between. |
Rebase pr with only small things open is now here: #9731 |
This Pr is the follow up of #9253.
Eventually this PR will remove the entire legacy code of the multicopter position control.