31 const double s_target,
const double s_curr,
const double v_target,
32 const double v_curr,
const double a_comfort,
const double d_comfort,
33 const double max_time) {
34 std::shared_ptr<PiecewiseAccelerationTrajectory1d> ptr_trajectory =
35 std::make_shared<PiecewiseAccelerationTrajectory1d>(s_curr, v_curr);
37 double s_dist = s_target - s_curr;
42 if (comfort_stop_dist > s_dist) {
44 double stop_t = v_curr / stop_d;
45 ptr_trajectory->AppendSegment(-stop_d, stop_t);
47 if (ptr_trajectory->ParamLength() < max_time) {
48 ptr_trajectory->AppendSegment(0.0,
49 max_time - ptr_trajectory->ParamLength());
51 return ptr_trajectory;
55 if (v_curr > v_target) {
56 double t_cruise = (s_dist - comfort_stop_dist) / v_target;
57 double t_rampdown = (v_curr - v_target) / d_comfort;
58 double t_dec = v_target / d_comfort;
60 ptr_trajectory->AppendSegment(-d_comfort, t_rampdown);
61 ptr_trajectory->AppendSegment(0.0, t_cruise);
62 ptr_trajectory->AppendSegment(-d_comfort, t_dec);
64 if (ptr_trajectory->ParamLength() < max_time) {
65 ptr_trajectory->AppendSegment(0.0,
66 max_time - ptr_trajectory->ParamLength());
68 return ptr_trajectory;
71 double t_rampup = (v_target - v_curr) / a_comfort;
72 double t_rampdown = (v_target - v_curr) / d_comfort;
73 double s_ramp = (v_curr + v_target) * (t_rampup + t_rampdown) * 0.5;
75 double s_rest = s_dist - s_ramp - comfort_stop_dist;
77 double t_cruise = s_rest / v_target;
78 double t_dec = v_target / d_comfort;
81 ptr_trajectory->AppendSegment(a_comfort, t_rampup);
82 ptr_trajectory->AppendSegment(0.0, t_cruise);
83 ptr_trajectory->AppendSegment(-d_comfort, t_dec);
85 if (ptr_trajectory->ParamLength() < max_time) {
86 ptr_trajectory->AppendSegment(0.0,
87 max_time - ptr_trajectory->ParamLength());
89 return ptr_trajectory;
91 double s_rampup_rampdown = s_dist - comfort_stop_dist;
92 double v_max = std::sqrt(v_curr * v_curr + 2.0 * a_comfort * d_comfort *
94 (a_comfort + d_comfort));
96 double t_acc = (v_max - v_curr) / a_comfort;
97 double t_dec = v_max / d_comfort;
100 ptr_trajectory->AppendSegment(a_comfort, t_acc);
101 ptr_trajectory->AppendSegment(-d_comfort, t_dec);
103 if (ptr_trajectory->ParamLength() < max_time) {
104 ptr_trajectory->AppendSegment(0.0,
105 max_time - ptr_trajectory->ParamLength());
107 return ptr_trajectory;