PX4 Firmware
PX4 Autopilot Software http://px4.io
|
TODO: document the algorithm |T1| T2 |T3|
__| |____ __ Jerk |_|
/ \ Acceleration ___/ ___
;" / / Velocity ; -—". More...
#include <VelocitySmoothing.hpp>
Public Member Functions | |
VelocitySmoothing (float initial_accel=0.f, float initial_vel=0.f, float initial_pos=0.f) | |
~VelocitySmoothing ()=default | |
void | reset (float accel, float vel, float pos) |
Reset the state. More... | |
void | updateDurations (float vel_setpoint) |
Compute T1, T2, T3 depending on the current state and velocity setpoint. More... | |
void | updateTraj (float dt, float time_stretch=1.f) |
Generate the trajectory (acceleration, velocity and position) by integrating the current jerk. More... | |
float | getMaxJerk () const |
Getters and setters. More... | |
void | setMaxJerk (float max_jerk) |
float | getMaxAccel () const |
void | setMaxAccel (float max_accel) |
float | getMaxVel () const |
void | setMaxVel (float max_vel) |
float | getCurrentJerk () const |
void | setCurrentAcceleration (const float accel) |
float | getCurrentAcceleration () const |
void | setCurrentVelocity (const float vel) |
float | getCurrentVelocity () const |
void | setCurrentPosition (const float pos) |
float | getCurrentPosition () const |
float | getVelSp () const |
float | getT1 () const |
float | getT2 () const |
float | getT3 () const |
float | getTotalTime () const |
Static Public Member Functions | |
static void | timeSynchronization (VelocitySmoothing *traj, int n_traj) |
Synchronize several trajectories to have the same total time. More... | |
Private Member Functions | |
void | updateDurationsMinimizeTotalTime () |
Compute T1, T2, T3 depending on the current state and velocity setpoint. More... | |
void | updateDurationsGivenTotalTime (float T123) |
Compute T1, T2, T3 depending on the current state and velocity setpoint. More... | |
int | computeDirection () |
Compute the direction of the jerk to be applied in order to drive the current state to the desired one. More... | |
float | computeVelAtZeroAcc () |
Compute the velocity at which the trajectory will be if the maximum jerk is applied during the time required to cancel the current acceleration. More... | |
float | computeT1 (float a0, float v3, float j_max, float a_max) |
Compute increasing acceleration time. More... | |
float | computeT1 (float T123, float a0, float v3, float j_max, float a_max) |
Compute increasing acceleration time using total time constraint. More... | |
float | saturateT1ForAccel (float a0, float j_max, float T1, float a_max) |
Saturate T1 in order to respect the maximum acceleration constraint. More... | |
float | computeT2 (float T1, float T3, float a0, float v3, float j_max) |
Compute constant acceleration time. More... | |
float | computeT2 (float T123, float T1, float T3) |
Compute constant acceleration time using total time constraint. More... | |
float | computeT3 (float T1, float a0, float j_max) |
Compute decreasing acceleration time. More... | |
Trajectory | evaluatePoly (float j, float a0, float v0, float x0, float t, int d) |
Compute the jerk, acceleration, velocity and position of a jerk-driven polynomial trajectory at a given time t. More... | |
Private Attributes | |
float | _vel_sp {0.0f} |
float | _max_jerk = 22.f |
float | _max_accel = 8.f |
float | _max_vel = 6.f |
Trajectory | _state {} |
int | _direction {0} |
Trajectory | _state_init {} |
float | _T1 = 0.f |
Increasing acceleration [s]. More... | |
float | _T2 = 0.f |
Constant acceleration [s]. More... | |
float | _T3 = 0.f |
Decreasing acceleration [s]. More... | |
float | _local_time = 0.f |
Current local time. More... | |
TODO: document the algorithm |T1| T2 |T3|
__| |____ __ Jerk |_|
/ \ Acceleration ___/ ___
;" / / Velocity ; -—".
Definition at line 61 of file VelocitySmoothing.hpp.
VelocitySmoothing::VelocitySmoothing | ( | float | initial_accel = 0.f , |
float | initial_vel = 0.f , |
||
float | initial_pos = 0.f |
||
) |
Definition at line 40 of file VelocitySmoothing.cpp.
References reset().
|
default |
|
private |
Compute the direction of the jerk to be applied in order to drive the current state to the desired one.
Definition at line 179 of file VelocitySmoothing.cpp.
References _state, _vel_sp, Trajectory::a, computeVelAtZeroAcc(), and math::sign().
Referenced by updateDurations().
|
inlineprivate |
Compute increasing acceleration time.
Definition at line 71 of file VelocitySmoothing.cpp.
References f(), math::max(), and saturateT1ForAccel().
Referenced by updateDurationsGivenTotalTime(), and updateDurationsMinimizeTotalTime().
|
inlineprivate |
Compute increasing acceleration time using total time constraint.
Definition at line 101 of file VelocitySmoothing.cpp.
References f(), math::max(), and saturateT1ForAccel().
|
inlineprivate |
Compute constant acceleration time.
Definition at line 138 of file VelocitySmoothing.cpp.
References math::abs_t(), f(), FLT_EPSILON, and math::max().
Referenced by updateDurationsGivenTotalTime(), and updateDurationsMinimizeTotalTime().
|
inlineprivate |
Compute constant acceleration time using total time constraint.
Definition at line 151 of file VelocitySmoothing.cpp.
References f(), and math::max().
|
inlineprivate |
Compute decreasing acceleration time.
Definition at line 157 of file VelocitySmoothing.cpp.
References f(), and math::max().
Referenced by updateDurationsGivenTotalTime(), and updateDurationsMinimizeTotalTime().
|
private |
Compute the velocity at which the trajectory will be if the maximum jerk is applied during the time required to cancel the current acceleration.
Definition at line 197 of file VelocitySmoothing.cpp.
References _max_jerk, _state, Trajectory::a, FLT_EPSILON, math::sign(), and Trajectory::v.
Referenced by computeDirection().
|
inlineprivate |
Compute the jerk, acceleration, velocity and position of a jerk-driven polynomial trajectory at a given time t.
j | jerk |
a0 | initial acceleration at t = 0 |
v0 | initial velocity |
x0 | initial postion |
t | current time |
d | direction |
Definition at line 225 of file VelocitySmoothing.cpp.
References Trajectory::a, Trajectory::j, t2, t3, Trajectory::v, and Trajectory::x.
Referenced by updateTraj().
|
inline |
Definition at line 104 of file VelocitySmoothing.hpp.
Referenced by ManualVelocitySmoothingZ::updateTrajectories().
|
inline |
Definition at line 102 of file VelocitySmoothing.hpp.
Referenced by ManualVelocitySmoothingZ::updateTrajectories().
|
inline |
Definition at line 108 of file VelocitySmoothing.hpp.
Referenced by ManualVelocitySmoothingZ::updateTrajectories().
|
inline |
Definition at line 106 of file VelocitySmoothing.hpp.
Referenced by ManualVelocitySmoothingZ::updateTrajectories().
|
inline |
Definition at line 96 of file VelocitySmoothing.hpp.
Referenced by ManualVelocitySmoothingXY::getMaxAccel().
|
inline |
Getters and setters.
Definition at line 93 of file VelocitySmoothing.hpp.
Referenced by ManualVelocitySmoothingXY::getMaxJerk().
|
inline |
Definition at line 99 of file VelocitySmoothing.hpp.
Referenced by ManualVelocitySmoothingXY::getMaxVel().
|
inline |
Definition at line 112 of file VelocitySmoothing.hpp.
|
inline |
Definition at line 113 of file VelocitySmoothing.hpp.
|
inline |
Definition at line 114 of file VelocitySmoothing.hpp.
|
inline |
Definition at line 115 of file VelocitySmoothing.hpp.
References Trajectory::j.
Referenced by main(), and timeSynchronization().
|
inline |
Definition at line 110 of file VelocitySmoothing.hpp.
void VelocitySmoothing::reset | ( | float | accel, |
float | vel, | ||
float | pos | ||
) |
Reset the state.
accel | Current acceleration |
vel | Current velocity |
pos | Current position |
Definition at line 45 of file VelocitySmoothing.cpp.
References _state, _state_init, Trajectory::a, Trajectory::j, Trajectory::v, and Trajectory::x.
Referenced by ManualVelocitySmoothingZ::reset(), and VelocitySmoothing().
|
inlineprivate |
Saturate T1 in order to respect the maximum acceleration constraint.
Definition at line 55 of file VelocitySmoothing.cpp.
Referenced by computeT1().
|
inline |
Definition at line 103 of file VelocitySmoothing.hpp.
Referenced by main().
|
inline |
Definition at line 107 of file VelocitySmoothing.hpp.
Referenced by ManualVelocitySmoothingZ::checkPositionLock(), ManualVelocitySmoothingZ::setCurrentPosition(), and ManualVelocitySmoothingXY::setCurrentPosition().
|
inline |
Definition at line 105 of file VelocitySmoothing.hpp.
Referenced by ManualVelocitySmoothingZ::checkPositionLock(), main(), ManualVelocitySmoothingZ::setCurrentVelocity(), and ManualVelocitySmoothingXY::setCurrentVelocity().
|
inline |
Definition at line 97 of file VelocitySmoothing.hpp.
Referenced by main(), ManualVelocitySmoothingXY::setMaxAccel(), and ManualVelocitySmoothingZ::updateTrajConstraints().
|
inline |
Definition at line 94 of file VelocitySmoothing.hpp.
Referenced by main(), ManualVelocitySmoothingZ::setMaxJerk(), and ManualVelocitySmoothingXY::setMaxJerk().
|
inline |
Definition at line 100 of file VelocitySmoothing.hpp.
Referenced by main(), ManualVelocitySmoothingXY::setMaxVel(), and ManualVelocitySmoothingZ::updateTrajConstraints().
|
static |
Synchronize several trajectories to have the same total time.
This is required to generate straight lines. The resulting total time is the one of the longest trajectory.
traj | an array of VelocitySmoothing objects |
n_traj | the number of trajectories to be synchronized |
Definition at line 266 of file VelocitySmoothing.cpp.
References FLT_EPSILON, getTotalTime(), and updateDurationsGivenTotalTime().
Referenced by FlightTaskAutoLineSmoothVel::_generateTrajectory(), main(), ManualVelocitySmoothingXY::updateTrajDurations(), and VelocitySmoothingTest::updateTrajectories().
void VelocitySmoothing::updateDurations | ( | float | vel_setpoint | ) |
Compute T1, T2, T3 depending on the current state and velocity setpoint.
This should be called on every cycle and before updateTraj().
vel_setpoint | velocity setpoint input |
Definition at line 163 of file VelocitySmoothing.cpp.
References _direction, _local_time, _max_vel, _state, _state_init, _T1, _T2, _T3, _vel_sp, computeDirection(), math::constrain(), and updateDurationsMinimizeTotalTime().
Referenced by main(), and ManualVelocitySmoothingZ::update().
|
private |
Compute T1, T2, T3 depending on the current state and velocity setpoint.
T123 | desired total time of the trajectory |
Definition at line 289 of file VelocitySmoothing.cpp.
References _direction, _max_accel, _max_jerk, _state, _T1, _T2, _T3, _vel_sp, Trajectory::a, computeT1(), computeT2(), computeT3(), and Trajectory::v.
Referenced by timeSynchronization().
|
private |
Compute T1, T2, T3 depending on the current state and velocity setpoint.
Minimize the total time of the trajectory
Definition at line 210 of file VelocitySmoothing.cpp.
References _direction, _max_accel, _max_jerk, _state, _T1, _T2, _T3, _vel_sp, Trajectory::a, computeT1(), computeT2(), computeT3(), and Trajectory::v.
Referenced by updateDurations().
void VelocitySmoothing::updateTraj | ( | float | dt, |
float | time_stretch = 1.f |
||
) |
Generate the trajectory (acceleration, velocity and position) by integrating the current jerk.
dt | integration period |
time_stretch | (optional) used to scale the integration period. This can be used to slow down or fast-forward the trajectory |
Definition at line 240 of file VelocitySmoothing.cpp.
References _direction, _local_time, _max_jerk, _state, _state_init, _T1, _T2, _T3, Trajectory::a, evaluatePoly(), f(), math::min(), t1, t2, t3, Trajectory::v, and Trajectory::x.
Referenced by main(), and ManualVelocitySmoothingZ::updateTrajectories().
|
private |
Definition at line 204 of file VelocitySmoothing.hpp.
Referenced by updateDurations(), updateDurationsGivenTotalTime(), updateDurationsMinimizeTotalTime(), and updateTraj().
|
private |
Current local time.
Definition at line 214 of file VelocitySmoothing.hpp.
Referenced by updateDurations(), and updateTraj().
|
private |
Definition at line 199 of file VelocitySmoothing.hpp.
Referenced by updateDurationsGivenTotalTime(), and updateDurationsMinimizeTotalTime().
|
private |
Definition at line 198 of file VelocitySmoothing.hpp.
Referenced by computeVelAtZeroAcc(), updateDurationsGivenTotalTime(), updateDurationsMinimizeTotalTime(), and updateTraj().
|
private |
Definition at line 200 of file VelocitySmoothing.hpp.
Referenced by updateDurations().
|
private |
Definition at line 203 of file VelocitySmoothing.hpp.
Referenced by computeDirection(), computeVelAtZeroAcc(), reset(), updateDurations(), updateDurationsGivenTotalTime(), updateDurationsMinimizeTotalTime(), and updateTraj().
|
private |
Definition at line 207 of file VelocitySmoothing.hpp.
Referenced by reset(), updateDurations(), and updateTraj().
|
private |
Increasing acceleration [s].
Definition at line 210 of file VelocitySmoothing.hpp.
Referenced by updateDurations(), updateDurationsGivenTotalTime(), updateDurationsMinimizeTotalTime(), and updateTraj().
|
private |
Constant acceleration [s].
Definition at line 211 of file VelocitySmoothing.hpp.
Referenced by updateDurations(), updateDurationsGivenTotalTime(), updateDurationsMinimizeTotalTime(), and updateTraj().
|
private |
Decreasing acceleration [s].
Definition at line 212 of file VelocitySmoothing.hpp.
Referenced by updateDurations(), updateDurationsGivenTotalTime(), updateDurationsMinimizeTotalTime(), and updateTraj().
|
private |
Definition at line 195 of file VelocitySmoothing.hpp.
Referenced by computeDirection(), updateDurations(), updateDurationsGivenTotalTime(), and updateDurationsMinimizeTotalTime().