33 {
34 std::shared_ptr<PiecewiseAccelerationTrajectory1d> ptr_trajectory =
35 std::make_shared<PiecewiseAccelerationTrajectory1d>(s_curr, v_curr);
36
37 double s_dist = s_target - s_curr;
38
40
41
42 if (comfort_stop_dist > s_dist) {
44 double stop_t = v_curr / stop_d;
45 ptr_trajectory->AppendSegment(-stop_d, stop_t);
46
47 if (ptr_trajectory->ParamLength() < max_time) {
48 ptr_trajectory->AppendSegment(0.0,
49 max_time - ptr_trajectory->ParamLength());
50 }
51 return ptr_trajectory;
52 }
53
54
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;
59
60 ptr_trajectory->AppendSegment(-d_comfort, t_rampdown);
61 ptr_trajectory->AppendSegment(0.0, t_cruise);
62 ptr_trajectory->AppendSegment(-d_comfort, t_dec);
63
64 if (ptr_trajectory->ParamLength() < max_time) {
65 ptr_trajectory->AppendSegment(0.0,
66 max_time - ptr_trajectory->ParamLength());
67 }
68 return ptr_trajectory;
69
70 } else {
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;
74
75 double s_rest = s_dist - s_ramp - comfort_stop_dist;
76 if (s_rest > 0) {
77 double t_cruise = s_rest / v_target;
78 double t_dec = v_target / d_comfort;
79
80
81 ptr_trajectory->AppendSegment(a_comfort, t_rampup);
82 ptr_trajectory->AppendSegment(0.0, t_cruise);
83 ptr_trajectory->AppendSegment(-d_comfort, t_dec);
84
85 if (ptr_trajectory->ParamLength() < max_time) {
86 ptr_trajectory->AppendSegment(0.0,
87 max_time - ptr_trajectory->ParamLength());
88 }
89 return ptr_trajectory;
90 } else {
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 *
93 s_rampup_rampdown /
94 (a_comfort + d_comfort));
95
96 double t_acc = (v_max - v_curr) / a_comfort;
97 double t_dec = v_max / d_comfort;
98
99
100 ptr_trajectory->AppendSegment(a_comfort, t_acc);
101 ptr_trajectory->AppendSegment(-d_comfort, t_dec);
102
103 if (ptr_trajectory->ParamLength() < max_time) {
104 ptr_trajectory->AppendSegment(0.0,
105 max_time - ptr_trajectory->ParamLength());
106 }
107 return ptr_trajectory;
108 }
109 }
110}
static double ComputeStopDistance(const double v, const double dec)
static double ComputeStopDeceleration(const double dist, const double v)