Apollo 11.0
自动驾驶开放平台
apollo::planning::DpStCost类 参考

#include <dp_st_cost.h>

apollo::planning::DpStCost 的协作图:

Public 成员函数

 DpStCost (const DpStSpeedOptimizerConfig &config, const double total_t, const double total_s, const std::vector< const Obstacle * > &obstacles, const STDrivableBoundary &st_drivable_boundary, const common::TrajectoryPoint &init_point)
 
double GetObstacleCost (const StGraphPoint &point)
 
double GetSpatialPotentialCost (const StGraphPoint &point)
 
double GetReferenceCost (const STPoint &point, const STPoint &reference_point) const
 
double GetSpeedCost (const STPoint &first, const STPoint &second, const double speed_limit, const double cruise_speed) const
 
double GetAccelCostByTwoPoints (const double pre_speed, const STPoint &first, const STPoint &second)
 
double GetAccelCostByThreePoints (const STPoint &first, const STPoint &second, const STPoint &third)
 
double GetJerkCostByTwoPoints (const double pre_speed, const double pre_acc, const STPoint &pre_point, const STPoint &curr_point)
 
double GetJerkCostByThreePoints (const double first_speed, const STPoint &first_point, const STPoint &second_point, const STPoint &third_point)
 
double GetJerkCostByFourPoints (const STPoint &first, const STPoint &second, const STPoint &third, const STPoint &fourth)
 

详细描述

在文件 dp_st_cost.h 第 39 行定义.

构造及析构函数说明

◆ DpStCost()

apollo::planning::DpStCost::DpStCost ( const DpStSpeedOptimizerConfig &  config,
const double  total_t,
const double  total_s,
const std::vector< const Obstacle * > &  obstacles,
const STDrivableBoundary &  st_drivable_boundary,
const common::TrajectoryPoint &  init_point 
)

在文件 dp_st_cost.cc 第 36 行定义.

41 : config_(config),
42 obstacles_(obstacles),
43 st_drivable_boundary_(st_drivable_boundary),
44 init_point_(init_point),
45 unit_t_(config.unit_t()),
46 total_s_(total_s) {
47 int index = 0;
48 for (const auto& obstacle : obstacles) {
49 boundary_map_[obstacle->path_st_boundary().id()] = index++;
50 }
51
52 AddToKeepClearRange(obstacles);
53
54 const auto dimension_t =
55 static_cast<uint32_t>(std::ceil(total_t / static_cast<double>(unit_t_))) +
56 1;
57 boundary_cost_.resize(obstacles_.size());
58 for (auto& vec : boundary_cost_) {
59 vec.resize(dimension_t, std::make_pair(-1.0, -1.0));
60 }
61 accel_cost_.fill(-1.0);
62 jerk_cost_.fill(-1.0);
63}

成员函数说明

◆ GetAccelCostByThreePoints()

double apollo::planning::DpStCost::GetAccelCostByThreePoints ( const STPoint &  first,
const STPoint &  second,
const STPoint &  third 
)

在文件 dp_st_cost.cc 第 274 行定义.

276 {
277 double accel = (first.s() + third.s() - 2 * second.s()) / (unit_t_ * unit_t_);
278 return GetAccelCost(accel);
279}

◆ GetAccelCostByTwoPoints()

double apollo::planning::DpStCost::GetAccelCostByTwoPoints ( const double  pre_speed,
const STPoint &  first,
const STPoint &  second 
)

在文件 dp_st_cost.cc 第 281 行定义.

283 {
284 double current_speed = (curr_point.s() - pre_point.s()) / unit_t_;
285 double accel = (current_speed - pre_speed) / unit_t_;
286 return GetAccelCost(accel);
287}

◆ GetJerkCostByFourPoints()

double apollo::planning::DpStCost::GetJerkCostByFourPoints ( const STPoint &  first,
const STPoint &  second,
const STPoint &  third,
const STPoint &  fourth 
)

在文件 dp_st_cost.cc 第 314 行定义.

317 {
318 double jerk = (fourth.s() - 3 * third.s() + 3 * second.s() - first.s()) /
319 (unit_t_ * unit_t_ * unit_t_);
320 return JerkCost(jerk);
321}

◆ GetJerkCostByThreePoints()

double apollo::planning::DpStCost::GetJerkCostByThreePoints ( const double  first_speed,
const STPoint &  first_point,
const STPoint &  second_point,
const STPoint &  third_point 
)

在文件 dp_st_cost.cc 第 333 行定义.

336 {
337 const double pre_speed = (second.s() - first.s()) / unit_t_;
338 const double pre_acc = (pre_speed - first_speed) / unit_t_;
339 const double curr_speed = (third.s() - second.s()) / unit_t_;
340 const double curr_acc = (curr_speed - pre_speed) / unit_t_;
341 const double jerk = (curr_acc - pre_acc) / unit_t_;
342 return JerkCost(jerk);
343}

◆ GetJerkCostByTwoPoints()

double apollo::planning::DpStCost::GetJerkCostByTwoPoints ( const double  pre_speed,
const double  pre_acc,
const STPoint &  pre_point,
const STPoint &  curr_point 
)

在文件 dp_st_cost.cc 第 323 行定义.

326 {
327 const double curr_speed = (curr_point.s() - pre_point.s()) / unit_t_;
328 const double curr_accel = (curr_speed - pre_speed) / unit_t_;
329 const double jerk = (curr_accel - pre_acc) / unit_t_;
330 return JerkCost(jerk);
331}

◆ GetObstacleCost()

double apollo::planning::DpStCost::GetObstacleCost ( const StGraphPoint &  point)

在文件 dp_st_cost.cc 第 113 行定义.

113 {
114 const double s = st_graph_point.point().s();
115 const double t = st_graph_point.point().t();
116
117 double cost = 0.0;
118
119 if (FLAGS_use_st_drivable_boundary) {
120 // TODO(Jiancheng): move to configs
121 static constexpr double boundary_resolution = 0.1;
122 int index = static_cast<int>(t / boundary_resolution);
123 const double lower_bound =
124 st_drivable_boundary_.st_boundary(index).s_lower();
125 const double upper_bound =
126 st_drivable_boundary_.st_boundary(index).s_upper();
127
128 if (s > upper_bound || s < lower_bound) {
129 return kInf;
130 }
131 }
132
133 for (const auto* obstacle : obstacles_) {
134 // Not applying obstacle approaching cost to virtual obstacle like created
135 // stop fences
136 if (obstacle->IsVirtual()) {
137 continue;
138 }
139
140 // Stop obstacles are assumed to have a safety margin when mapping them out,
141 // so repelling force in dp st is not needed as it is designed to have adc
142 // stop right at the stop distance we design in prior mapping process
143 if (obstacle->LongitudinalDecision().has_stop()) {
144 continue;
145 }
146
147 auto boundary = obstacle->path_st_boundary();
148
149 if (boundary.min_s() > FLAGS_speed_lon_decision_horizon) {
150 continue;
151 }
152 if (t < boundary.min_t() || t > boundary.max_t()) {
153 continue;
154 }
155 if (boundary.IsPointInBoundary(st_graph_point.point())) {
156 return kInf;
157 }
158 double s_upper = 0.0;
159 double s_lower = 0.0;
160
161 int boundary_index = boundary_map_[boundary.id()];
162 if (boundary_cost_[boundary_index][st_graph_point.index_t()].first < 0.0) {
163 boundary.GetBoundarySRange(t, &s_upper, &s_lower);
164 boundary_cost_[boundary_index][st_graph_point.index_t()] =
165 std::make_pair(s_upper, s_lower);
166 } else {
167 s_upper = boundary_cost_[boundary_index][st_graph_point.index_t()].first;
168 s_lower = boundary_cost_[boundary_index][st_graph_point.index_t()].second;
169 }
170 if (s < s_lower) {
171 const double follow_distance_s = config_.safe_distance();
172 if (s + follow_distance_s < s_lower) {
173 continue;
174 } else {
175 auto s_diff = follow_distance_s - s_lower + s;
176 cost += config_.obstacle_weight() * config_.default_obstacle_cost() *
177 s_diff * s_diff;
178 }
179 } else if (s > s_upper) {
180 const double overtake_distance_s =
182 if (s > s_upper + overtake_distance_s) { // or calculated from velocity
183 continue;
184 } else {
185 auto s_diff = overtake_distance_s + s_upper - s;
186 cost += config_.obstacle_weight() * config_.default_obstacle_cost() *
187 s_diff * s_diff;
188 }
189 }
190 }
191 return cost * unit_t_;
192}
repeated STDrivableBoundaryInstance st_boundary

◆ GetReferenceCost()

double apollo::planning::DpStCost::GetReferenceCost ( const STPoint &  point,
const STPoint &  reference_point 
) const

在文件 dp_st_cost.cc 第 198 行定义.

199 {
200 return config_.reference_weight() * (point.s() - reference_point.s()) *
201 (point.s() - reference_point.s()) * unit_t_;
202}

◆ GetSpatialPotentialCost()

double apollo::planning::DpStCost::GetSpatialPotentialCost ( const StGraphPoint &  point)

在文件 dp_st_cost.cc 第 194 行定义.

194 {
195 return (total_s_ - point.point().s()) * config_.spatial_potential_penalty();
196}

◆ GetSpeedCost()

double apollo::planning::DpStCost::GetSpeedCost ( const STPoint &  first,
const STPoint &  second,
const double  speed_limit,
const double  cruise_speed 
) const

在文件 dp_st_cost.cc 第 204 行定义.

206 {
207 double cost = 0.0;
208 const double speed = (second.s() - first.s()) / unit_t_;
209 if (speed < 0) {
210 return kInf;
211 }
212
213 const double max_adc_stop_speed = common::VehicleConfigHelper::Instance()
214 ->GetConfig()
215 .vehicle_param()
216 .max_abs_speed_when_stopped();
217 if (speed < max_adc_stop_speed && InKeepClearRange(second.s())) {
218 // first.s in range
219 cost += config_.keep_clear_low_speed_penalty() * unit_t_ *
220 config_.default_speed_cost();
221 }
222
223 double det_speed = (speed - speed_limit) / speed_limit;
224 if (det_speed > 0) {
225 cost += config_.exceed_speed_penalty() * config_.default_speed_cost() *
226 (det_speed * det_speed) * unit_t_;
227 } else if (det_speed < 0) {
228 cost += config_.low_speed_penalty() * config_.default_speed_cost() *
229 -det_speed * unit_t_;
230 }
231
232 if (config_.enable_dp_reference_speed()) {
233 double diff_speed = speed - cruise_speed;
234 cost += config_.reference_speed_penalty() * config_.default_speed_cost() *
235 fabs(diff_speed) * unit_t_;
236 }
237
238 return cost;
239}

该类的文档由以下文件生成: