Apollo 11.0
自动驾驶开放平台
piecewise_braking_trajectory_generator.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2018 The Apollo Authors. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *****************************************************************************/
16
22
23#include <cmath>
24
25#include "cyber/common/log.h"
26
27namespace apollo {
28namespace planning {
29
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);
36
37 double s_dist = s_target - s_curr;
38
39 double comfort_stop_dist = ComputeStopDistance(v_curr, d_comfort);
40
41 // if cannot stop using comfort deceleration, then brake in the beginning.
42 if (comfort_stop_dist > s_dist) {
43 double stop_d = ComputeStopDeceleration(s_dist, v_curr);
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 // otherwise, the vehicle can stop from current speed with comfort brake.
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 // construct the trajectory
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 // construct the trajectory
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}
111
113 const double v, const double dec) {
114 ACHECK(dec > 0.0);
115 return v * v / dec * 0.5;
116}
117
119 const double dist, const double v) {
120 return v * v / dist * 0.5;
121}
122
123} // namespace planning
124} // namespace apollo
static double ComputeStopDeceleration(const double dist, const double v)
static std::shared_ptr< Curve1d > Generate(const double s_target, const double s_curr, const double v_target, const double v_curr, const double a_comfort, const double d_comfort, const double max_time)
Planning module main class.
#define ACHECK(cond)
Definition log.h:80
class register implement
Definition arena_queue.h:37