-
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
Trajectory generator for Auto mode #10746
Conversation
41e89e3
to
b851b17
Compare
Cool! I see that this causes the vehicle to deviate quite far from the waypoints and the straight lines connecting them. What guarantees can be made about maximum deviation of the vehicle position from the straight lines? How hard will it be to predict the actual trajectory ahead of flight (e.g. drawing the red lines from above in QGC as the waypoints are placed)? |
Hi, @ndepal As it directly depends on the parameters of the trajectory and is completely independent of the vehicle's dynamics, the trajectory (and path) is deterministic. The green line from above could then be displayed on QGC. |
f478733
to
b95323c
Compare
Thanks for the explanation @bresch. A while ago there was an effort to implement spline/bezier trajectories. These would be smooth and feasible trajectories, allowing for a controller that closely tracks the planned path. And there are algorithms for planning such paths in an obstacle map. Do you know what the plans are in that regard? Does this PR replace those efforts? |
@ndepal The bad tracking is mostly due to the poorly tuned model I have in jMAVSim. The tracking will also be improved by adding the acceleration trajectory as a feedforward to the velocity controller. I'm not 100% sure, but I think the spline/bezier trajectories you're mentioning are in fact paths and not trajectories. |
1afd26c
to
70bb4a3
Compare
We'll need to figure out something to get this to fit in px4fmu-v2, but in the meantime let's test on other platforms. @PX4/testflights please test this on a few multicopter platforms that aren't px4fmu-v2. |
@PX4/testflights Could you please test that on a quad? Something like a F450
The following parameters should be good for a small quad: Thanks in advance! |
I tested in pixhawk 4 and pixhawk 4 mini. in both, there is no difference with the master. Pixhawk 4 mini logs. |
@Avysuarez Thanks! Could you also try with those specific parameters please: #10746 (comment) |
@bresch |
With |
9edaf84
to
1631789
Compare
rebased on Master |
I tested again with the same vehicles but with the suggested parameters. The flight is smoother. Pixhawk 4 mini. |
@Avysuarez Great! Thanks a lot. |
@dannyfpv Awesome, thanks! |
Here are some plots of a real flight (extracted from a flight made by @dannyfpv ) A general good result is that all the discontinuities have been removed up to the rate setpoints. |
Derivation by Mathieu Bresciani: https://github.com/Auterion/trajectory_generator
… getters to public section
- move the update after the integration: a new computed jerk has an impact at the next epoch only - add jerk reduction in case of too large integration time: when a jerk of "min_jerk" during dt is too much - add jerk reduction if the integration time is larger than the predicted one and that integrating that jerk would lead to an acceleration overshoot - rename some variables
c9b19a6
to
22d178a
Compare
@dagar Rebased on Master. |
Hi, I'm trying to confingure this mode in master but the parameters to configure it are mising. What I am doing wrong? |
Hi @VTOLDavid , |
This parameters do not show up: |
Yes. Try a daily build. Though you should normally still see the parameters as long as you are using firmware based on the master codeline (ie param metadata is in firmware, not QGC). The parameters are in master - you can tell because they show up in the docs here: https://docs.px4.io/en/advanced_config/parameter_reference.html#MPC_AUTO_MODE (QGC firmware gets params from the same source). |
Thanks, solved! |
@bresch I am a bit confused about your _generateTrajectory() code. It looks like you computed the desired velocity_setpoint in _prepareSetpoints(). But you immediately change that _velocity_setpoint to vel_sp_smooth in generateTrajectory(), which does integration based on the jerk and vel_prev. I failed to see how the computed _velocity_setpoint factors into the new vel_sp_smooth. Can you explain that? |
Hi @bangyanz , |
Based on #10696
Needs #10772 to work with VTOL planes.
Overview
This new FlightTask uses the velocity-based trajectory generator developed for manual control in #10696 to generate a smooth trajectory between waypoints. The strategy is quite simple: for each axis (north-east-down), a velocity target is generated using simple proportional controllers:
v_target = K * (x_waypoint - x_trajectory)
where x_... is the position. The controller then "drives" the trajectory to the waypoint like a servo controls its position by controlling the velocity of the motor. Furthermore, to ensure that the trajectory asymptotically converges to the line connecting the waypoints, a cross-track controller is added (here also, a simple proportional controller is used).To robustify the algorithm, a time stretch strategy is used:
At each epoch, the increasing acceleration, constant acceleration and decreasing periods are computed. To generate the trajectory, the jerk is integrated using
dt*time_stretch
wheretime_stretch
is a value between 0.0 and 1.0. This time stretch value is computed as a function of "how far the drone is behind the position of the trajectory". In summary, we can say that the trajectory will wait for the drone if it's too far from it.Takeoff and landing
The advantage is that for takeoff and landing waypoints, the trajectory is still continuous. The new
AutoMapper2
flight task is used to provide proper position and velocity setpoints given the type of waypoint:The interface used is similar to the basic FlightTask idea:
Tests
Raw setpoints
Position along North axis:
Generated path:
Using this trajectory generator
Position along North axis:
Generated path:
How to use it
MPC_AUTO_MODE
to 1MPC_YAW_MODE
to 3 (coordinated turns)MPC_ACC_HOR
is used as the maximum acceleration/deceleration for x and yMPC_JERK_MIN
is used as the maximum jerk for x, y and zMPC_XY_CRUISE
is the cruise speed, the max velocity of the trajectoryMPC_XY_VEL_MAX
is the max velocity at the input of the velocity controller (has to be bigger than the cruise speed to allow the position loop to do its job)MPC_ACC_DOWN_MAX
MPC_ACC_UP_MAX
MPC_Z_VEL_MAX_DN
MPC_Z_VEL_MAX_UP
MPC_XY_TRAJ_P
controls the "aggressiveness" of the horizontal trajectory.MPC_Z_TRAJ_P
controls the "aggressiveness" of the vertical trajectory.