38 #include <mathlib/mathlib.h> 42 reset(initial_accel, initial_vel, initial_pos);
58 float accel_T1 = a0 + j_max * T1;
61 if (accel_T1 > a_max) {
62 T1_new = (a_max - a0) / j_max;
64 }
else if (accel_T1 < -a_max) {
65 T1_new = (-a_max - a0) / j_max;
73 float delta = 2.f * a0 * a0 + 4.f * j_max * v3;
80 float sqrt_delta = sqrtf(delta);
81 float T1_plus = (-a0 + 0.5f * sqrt_delta) / j_max;
82 float T1_minus = (-a0 - 0.5f * sqrt_delta) / j_max;
84 float T3_plus = a0 / j_max + T1_plus;
85 float T3_minus = a0 / j_max + T1_minus;
89 if (T1_plus >= 0.
f && T3_plus >= 0.
f) {
92 }
else if (T1_minus >= 0.
f && T3_minus >= 0.
f) {
104 float b = j_max * T123 - a0;
105 float delta = T123 * T123 * j_max * j_max + 2.f * T123 * a0 * j_max - a0 * a0 - 4.f * j_max * v3;
112 float sqrt_delta = sqrtf(delta);
113 float denominator_inv = 1.f / (2.f * a);
114 float T1_plus =
math::max((-b + sqrt_delta) * denominator_inv, 0.
f);
115 float T1_minus =
math::max((-b - sqrt_delta) * denominator_inv, 0.
f);
117 float T3_plus = a0 / j_max + T1_plus;
118 float T3_minus = a0 / j_max + T1_minus;
120 float T13_plus = T1_plus + T3_plus;
121 float T13_minus = T1_minus + T3_minus;
125 if (T13_plus > T123) {
128 }
else if (T13_minus > T123) {
142 float den = a0 + j_max * T1;
145 T2 = (-0.5f * T1 * T1 * j_max - T1 * T3 * j_max - T1 * a0 + 0.5f * T3 * T3 * j_max - T3 * a0 + v3) / den;
153 float T2 = T123 - T1 - T3;
159 float T3 = a0 / j_max + T1;
188 if (direction == 0) {
203 float t_zero_acc = -
_state.
a / j_zero_acc;
204 vel_zero_acc =
_state.
v +
_state.
a * t_zero_acc + 0.5f * j_zero_acc * t_zero_acc * t_zero_acc;
233 traj.
a = a0 + jt * t;
234 traj.
v = v0 + a0 * t + 0.5f * jt *
t2;
235 traj.
x = x0 + v0 * t + 0.5f * a0 * t2 + 1.f / 6.f * jt *
t3;
249 if (t_remain > 0.
f) {
255 if (t_remain > 0.
f) {
261 if (t_remain > 0.
f) {
268 float desired_time = 0.f;
269 int longest_traj_index = 0;
271 for (
int i = 0; i < n_traj; i++) {
274 if (T123 > desired_time) {
276 longest_traj_index = i;
281 for (
int i = 0; i < n_traj; i++) {
282 if (i != longest_traj_index) {
constexpr _Tp constrain(_Tp val, _Tp min_val, _Tp max_val)
int computeDirection()
Compute the direction of the jerk to be applied in order to drive the current state to the desired on...
float computeVelAtZeroAcc()
Compute the velocity at which the trajectory will be if the maximum jerk is applied during the time r...
void updateDurationsGivenTotalTime(float T123)
Compute T1, T2, T3 depending on the current state and velocity setpoint.
static struct hrt_call t1
TODO: document the algorithm |T1| T2 |T3| __| |____ __ Jerk |_| / \ Acceleration ___/ ___ ;" / / V...
void updateTraj(float dt, float time_stretch=1.f)
Generate the trajectory (acceleration, velocity and position) by integrating the current jerk...
float computeT2(float T1, float T3, float a0, float v3, float j_max)
Compute constant acceleration time.
Vector< float, 6 > f(float t, const Matrix< float, 6, 1 > &, const Matrix< float, 3, 1 > &)
void reset(float accel, float vel, float pos)
Reset the state.
float getTotalTime() const
void updateDurations(float vel_setpoint)
Compute T1, T2, T3 depending on the current state and velocity setpoint.
void updateDurationsMinimizeTotalTime()
Compute T1, T2, T3 depending on the current state and velocity setpoint.
float computeT1(float a0, float v3, float j_max, float a_max)
Compute increasing acceleration time.
constexpr _Tp min(_Tp a, _Tp b)
float _local_time
Current local time.
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 giv...
VelocitySmoothing(float initial_accel=0.f, float initial_vel=0.f, float initial_pos=0.f)
constexpr _Tp max(_Tp a, _Tp b)
static void timeSynchronization(VelocitySmoothing *traj, int n_traj)
Synchronize several trajectories to have the same total time.
float _T1
Increasing acceleration [s].
float computeT3(float T1, float a0, float j_max)
Compute decreasing acceleration time.
float _T3
Decreasing acceleration [s].
float _T2
Constant acceleration [s].
float saturateT1ForAccel(float a0, float j_max, float T1, float a_max)
Saturate T1 in order to respect the maximum acceleration constraint.