Apollo 11.0
自动驾驶开放平台
apollo::planning::util 命名空间参考

函数

int BuildStopDecision (const std::string &stop_wall_id, const double stop_line_s, const double stop_distance, const StopReasonCode &stop_reason_code, const std::vector< std::string > &wait_for_obstacles, const std::string &decision_tag, Frame *const frame, ReferenceLineInfo *const reference_line_info, double stop_wall_width)
 
int BuildStopDecision (const std::string &stop_wall_id, const std::string &lane_id, const double lane_s, const double stop_distance, const StopReasonCode &stop_reason_code, const std::vector< std::string > &wait_for_obstacles, const std::string &decision_tag, Frame *const frame, ReferenceLineInfo *const reference_line_info)
 
std::pair< double, double > WorldCoordToObjCoord (std::pair< double, double > input_world_coord, std::pair< double, double > obj_world_coord, double obj_world_angle)
 
double WorldAngleToObjAngle (double input_world_angle, double obj_world_angle)
 
bool IsVehicleStateValid (const VehicleState &vehicle_state)
 
bool IsDifferentRouting (const PlanningCommand &first, const PlanningCommand &second)
 
double GetADCStopDeceleration (apollo::common::VehicleStateProvider *vehicle_state, const double adc_front_edge_s, const double stop_line_s)
 
bool CheckStopSignOnReferenceLine (const ReferenceLineInfo &reference_line_info, const std::string &stop_sign_overlap_id)
 
bool CheckTrafficLightOnReferenceLine (const ReferenceLineInfo &reference_line_info, const std::string &traffic_light_overlap_id)
 
bool CheckInsideJunction (const ReferenceLineInfo &reference_line_info)
 
void GetFilesByPath (const boost::filesystem::path &path, std::vector< std::string > *files)
 
double CalculateEquivalentEgoWidth (const ReferenceLineInfo &reference_line_info, double s, bool *is_left)
 
double CalculateEquivalentEgoWidth (const apollo::hdmap::LaneInfoConstPtr lane_info, double s, bool *is_left)
 
bool left_arc_bound_with_heading (double delta_x, double r, double heading, double *result)
 
bool right_arc_bound_with_heading (double delta_x, double r, double heading, double *result)
 
bool left_arc_bound_with_heading_with_reverse_kappa (double delta_x, double r, double heading, double kappa, double *result)
 
bool right_arc_bound_with_heading_with_reverse_kappa (double delta_x, double r, double heading, double kappa, double *result)
 

函数说明

◆ BuildStopDecision() [1/2]

int apollo::planning::util::BuildStopDecision ( const std::string &  stop_wall_id,
const double  stop_line_s,
const double  stop_distance,
const StopReasonCode &  stop_reason_code,
const std::vector< std::string > &  wait_for_obstacles,
const std::string &  decision_tag,
Frame *const  frame,
ReferenceLineInfo *const  reference_line_info,
double  stop_wall_width 
)

在文件 common.cc 第 28 行定义.

34 {
35 CHECK_NOTNULL(frame);
36 CHECK_NOTNULL(reference_line_info);
37
38 // check
39 const auto& reference_line = reference_line_info->reference_line();
40 if (!WithinBound(0.0, reference_line.Length(), stop_line_s)) {
41 AERROR << "stop_line_s[" << stop_line_s << "] is not on reference line";
42 return 0;
43 }
44
45 // create virtual stop wall
46 const auto* obstacle =
47 frame->CreateStopObstacle(reference_line_info, stop_wall_id,
48 stop_line_s, stop_wall_width);
49 if (!obstacle) {
50 AERROR << "Failed to create obstacle [" << stop_wall_id << "]";
51 return -1;
52 }
53 const Obstacle* stop_wall = reference_line_info->AddObstacle(obstacle);
54 if (!stop_wall) {
55 AERROR << "Failed to add obstacle[" << stop_wall_id << "]";
56 return -1;
57 }
58
59 // build stop decision
60 const double stop_s = stop_line_s - stop_distance;
61 const auto& stop_point = reference_line.GetReferencePoint(stop_s);
62 const double stop_heading =
63 reference_line.GetReferencePoint(stop_s).heading();
64
65 ObjectDecisionType stop;
66 auto* stop_decision = stop.mutable_stop();
67 stop_decision->set_reason_code(stop_reason_code);
68 stop_decision->set_distance_s(-stop_distance);
69 stop_decision->set_stop_heading(stop_heading);
70 stop_decision->mutable_stop_point()->set_x(stop_point.x());
71 stop_decision->mutable_stop_point()->set_y(stop_point.y());
72 stop_decision->mutable_stop_point()->set_z(0.0);
73
74 for (size_t i = 0; i < wait_for_obstacles.size(); ++i) {
75 stop_decision->add_wait_for_obstacle(wait_for_obstacles[i]);
76 }
77
78 auto* path_decision = reference_line_info->path_decision();
79 path_decision->AddLongitudinalDecision(decision_tag, stop_wall->Id(), stop);
80
81 return 0;
82}
const Obstacle * CreateStopObstacle(ReferenceLineInfo *const reference_line_info, const std::string &obstacle_id, const double obstacle_s, double stop_wall_width=4.0)
: create static virtual object with lane width, mainly used for virtual stop wall
Definition frame.cc:214
bool AddLongitudinalDecision(const std::string &tag, const std::string &object_id, const ObjectDecisionType &decision)
const ReferenceLine & reference_line() const
Obstacle * AddObstacle(const Obstacle *obstacle)
#define AERROR
Definition log.h:44

◆ BuildStopDecision() [2/2]

int apollo::planning::util::BuildStopDecision ( const std::string &  stop_wall_id,
const std::string &  lane_id,
const double  lane_s,
const double  stop_distance,
const StopReasonCode &  stop_reason_code,
const std::vector< std::string > &  wait_for_obstacles,
const std::string &  decision_tag,
Frame *const  frame,
ReferenceLineInfo *const  reference_line_info 
)

在文件 common.cc 第 84 行定义.

90 {
91 CHECK_NOTNULL(frame);
92 CHECK_NOTNULL(reference_line_info);
93
94 const auto& reference_line = reference_line_info->reference_line();
95
96 // create virtual stop wall
97 const auto* obstacle =
98 frame->CreateStopObstacle(stop_wall_id, lane_id, lane_s);
99 if (!obstacle) {
100 AERROR << "Failed to create obstacle [" << stop_wall_id << "]";
101 return -1;
102 }
103
104 const Obstacle* stop_wall = reference_line_info->AddObstacle(obstacle);
105 if (!stop_wall) {
106 AERROR << "Failed to create obstacle for: " << stop_wall_id;
107 return -1;
108 }
109
110 const auto& stop_wall_box = stop_wall->PerceptionBoundingBox();
111 if (!reference_line.IsOnLane(stop_wall_box.center())) {
112 ADEBUG << "stop point is not on lane. SKIP STOP decision";
113 return 0;
114 }
115
116 // build stop decision
117 auto stop_point = reference_line.GetReferencePoint(
118 stop_wall->PerceptionSLBoundary().start_s() - stop_distance);
119
120 ObjectDecisionType stop;
121 auto* stop_decision = stop.mutable_stop();
122 stop_decision->set_reason_code(stop_reason_code);
123 stop_decision->set_distance_s(-stop_distance);
124 stop_decision->set_stop_heading(stop_point.heading());
125 stop_decision->mutable_stop_point()->set_x(stop_point.x());
126 stop_decision->mutable_stop_point()->set_y(stop_point.y());
127 stop_decision->mutable_stop_point()->set_z(0.0);
128
129 auto* path_decision = reference_line_info->path_decision();
130 path_decision->AddLongitudinalDecision(decision_tag, stop_wall->Id(), stop);
131
132 return 0;
133}
This is the class that associates an Obstacle with its path properties.
Definition obstacle.h:62
const std::string & Id() const
Definition obstacle.h:75
const SLBoundary & PerceptionSLBoundary() const
Definition obstacle.cc:694
const common::math::Box2d & PerceptionBoundingBox() const
Definition obstacle.h:90
#define ADEBUG
Definition log.h:41

◆ CalculateEquivalentEgoWidth() [1/2]

double apollo::planning::util::CalculateEquivalentEgoWidth ( const apollo::hdmap::LaneInfoConstPtr  lane_info,
double  s,
bool *  is_left 
)

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

205 {
206 const auto& vehicle_param =
207 common::VehicleConfigHelper::Instance()->GetConfig().vehicle_param();
208 double max_kappa = 1.0 / vehicle_param.min_turn_radius();
209 double half_wb = 0.5 * vehicle_param.wheel_base();
210 double front_l = vehicle_param.front_edge_to_center() - half_wb;
211 double half_w = 0.5 * vehicle_param.width();
212 double current_heading = lane_info->Heading(s);
213 double heading_f = lane_info->Heading(s + front_l);
214 double heading_b = lane_info->Heading(s - half_wb);
215 // average kappa from front edge to center
216 double kappa_f =
217 apollo::common::math::NormalizeAngle(heading_f - current_heading) /
218 front_l;
219 // average kappa from center to rear axle
220 double kappa_b =
221 apollo::common::math::NormalizeAngle(current_heading - heading_b) /
222 half_wb;
223 *is_left = (kappa_b < 0.0);
224 // prevent devide by 0, and quit if lane bends to difference direction
225 if (kappa_f * kappa_b < 0.0 || fabs(kappa_f) < 1e-6) {
226 return half_w;
227 }
228
229 kappa_f = std::min(fabs(kappa_f), max_kappa);
230 kappa_b = std::min(fabs(kappa_b), max_kappa);
231 double theta = apollo::common::math::Vec2d(1.0, half_wb * kappa_b).Angle();
232 double sint = std::sin(theta);
233 double cost = std::cos(theta);
234 double r_f = 1.0 / kappa_f;
235 double eq_half_w =
236 apollo::common::math::Vec2d(front_l * cost - half_w * sint,
237 r_f + front_l * sint + half_w * cost)
238 .Length() -
239 r_f;
240 return std::max(eq_half_w, half_w);
241}
Implements a class of 2-dimensional vectors.
Definition vec2d.h:42
double Length() const
Gets the length of the vector
Definition vec2d.cc:33
double Angle() const
Gets the angle between the vector and the positive x semi-axis
Definition vec2d.cc:37
double NormalizeAngle(const double angle)
Normalize angle to [-PI, PI).
Definition math_utils.cc:53

◆ CalculateEquivalentEgoWidth() [2/2]

double apollo::planning::util::CalculateEquivalentEgoWidth ( const ReferenceLineInfo &  reference_line_info,
double  s,
bool *  is_left 
)

在文件 util.cc 第 160 行定义.

161 {
162 const auto& vehicle_param =
163 common::VehicleConfigHelper::Instance()->GetConfig().vehicle_param();
164 double max_kappa = 1.0 / vehicle_param.min_turn_radius();
165 double half_wb = 0.5 * vehicle_param.wheel_base();
166 double front_l = vehicle_param.front_edge_to_center() - half_wb;
167 double half_w = 0.5 * vehicle_param.width();
168 double current_heading =
169 reference_line_info.reference_line().GetReferencePoint(s).heading();
170 double heading_f = reference_line_info.reference_line()
171 .GetReferencePoint(s + front_l)
172 .heading();
173 double heading_b = reference_line_info.reference_line()
174 .GetReferencePoint(s - half_wb)
175 .heading();
176 // average kappa from front edge to center
177 double kappa_f =
178 apollo::common::math::NormalizeAngle(heading_f - current_heading) /
179 front_l;
180 // average kappa from center to rear axle
181 double kappa_b =
182 apollo::common::math::NormalizeAngle(current_heading - heading_b) /
183 half_wb;
184 *is_left = (kappa_b < 0.0);
185 // prevent devide by 0, and quit if lane bends to difference direction
186 if (kappa_f * kappa_b < 0.0 || fabs(kappa_f) < 1e-6) {
187 return half_w;
188 }
189
190 kappa_f = std::min(fabs(kappa_f), max_kappa);
191 kappa_b = std::min(fabs(kappa_b), max_kappa);
192 double theta = apollo::common::math::Vec2d(1.0, half_wb * kappa_b).Angle();
193 double sint = std::sin(theta);
194 double cost = std::cos(theta);
195 double r_f = 1.0 / kappa_f;
196 double eq_half_w =
197 apollo::common::math::Vec2d(front_l * cost - half_w * sint,
198 r_f + front_l * sint + half_w * cost)
199 .Length() -
200 r_f;
201 return std::max(eq_half_w, half_w);
202}
double heading() const
Definition path.h:118
ReferencePoint GetReferencePoint(const double s) const

◆ CheckInsideJunction()

bool apollo::planning::util::CheckInsideJunction ( const ReferenceLineInfo &  reference_line_info)

在文件 util.cc 第 115 行定义.

115 {
116 const double adc_front_edge_s = reference_line_info.AdcSlBoundary().end_s();
117 const double adc_back_edge_s = reference_line_info.AdcSlBoundary().start_s();
118
119 hdmap::PathOverlap junction_overlap;
120 reference_line_info.GetJunction(adc_front_edge_s, &junction_overlap);
121 if (junction_overlap.object_id.empty()) {
122 return false;
123 }
124
125 static constexpr double kIntersectionPassDist = 2.0; // unit: m
126 const double distance_adc_pass_intersection =
127 adc_back_edge_s - junction_overlap.end_s;
128 ADEBUG << "distance_adc_pass_intersection[" << distance_adc_pass_intersection
129 << "] junction_overlap[" << junction_overlap.object_id << "] start_s["
130 << junction_overlap.start_s << "]";
131
132 return distance_adc_pass_intersection < kIntersectionPassDist;
133}
int GetJunction(const double s, hdmap::PathOverlap *junction_overlap) const
const SLBoundary & AdcSlBoundary() const
std::string object_id
Definition path.h:95

◆ CheckStopSignOnReferenceLine()

bool apollo::planning::util::CheckStopSignOnReferenceLine ( const ReferenceLineInfo &  reference_line_info,
const std::string &  stop_sign_overlap_id 
)

在文件 util.cc 第 84 行定义.

85 {
86 const std::vector<PathOverlap>& stop_sign_overlaps =
87 reference_line_info.reference_line().map_path().stop_sign_overlaps();
88 auto stop_sign_overlap_it =
89 std::find_if(stop_sign_overlaps.begin(), stop_sign_overlaps.end(),
90 [&stop_sign_overlap_id](const PathOverlap& overlap) {
91 return overlap.object_id == stop_sign_overlap_id;
92 });
93 return (stop_sign_overlap_it != stop_sign_overlaps.end());
94}
const std::vector< PathOverlap > & stop_sign_overlaps() const
Definition path.h:307
const hdmap::Path & map_path() const

◆ CheckTrafficLightOnReferenceLine()

bool apollo::planning::util::CheckTrafficLightOnReferenceLine ( const ReferenceLineInfo &  reference_line_info,
const std::string &  traffic_light_overlap_id 
)

在文件 util.cc 第 99 行定义.

101 {
102 const std::vector<PathOverlap>& traffic_light_overlaps =
103 reference_line_info.reference_line().map_path().signal_overlaps();
104 auto traffic_light_overlap_it =
105 std::find_if(traffic_light_overlaps.begin(), traffic_light_overlaps.end(),
106 [&traffic_light_overlap_id](const PathOverlap& overlap) {
107 return overlap.object_id == traffic_light_overlap_id;
108 });
109 return (traffic_light_overlap_it != traffic_light_overlaps.end());
110}
const std::vector< PathOverlap > & signal_overlaps() const
Definition path.h:301

◆ GetADCStopDeceleration()

double apollo::planning::util::GetADCStopDeceleration ( apollo::common::VehicleStateProvider *  vehicle_state,
const double  adc_front_edge_s,
const double  stop_line_s 
)

在文件 util.cc 第 58 行定义.

60 {
61 double adc_speed = vehicle_state->linear_velocity();
62 const double max_adc_stop_speed = common::VehicleConfigHelper::Instance()
63 ->GetConfig()
64 .vehicle_param()
65 .max_abs_speed_when_stopped();
66 if (adc_speed < max_adc_stop_speed) {
67 return 0.0;
68 }
69
70 double stop_distance = 0;
71
72 if (stop_line_s > adc_front_edge_s) {
73 stop_distance = stop_line_s - adc_front_edge_s;
74 }
75 if (stop_distance < 1e-5) {
76 return std::numeric_limits<double>::max();
77 }
78 return (adc_speed * adc_speed) / (2 * stop_distance);
79}
double linear_velocity() const
Get the vehicle's linear velocity.

◆ GetFilesByPath()

void apollo::planning::util::GetFilesByPath ( const boost::filesystem::path &  path,
std::vector< std::string > *  files 
)

在文件 util.cc 第 138 行定义.

139 {
140 ACHECK(files);
141 if (!boost::filesystem::exists(path)) {
142 return;
143 }
144 if (boost::filesystem::is_regular_file(path)) {
145 AINFO << "Found record file: " << path.c_str();
146 files->push_back(path.c_str());
147 return;
148 }
149 if (boost::filesystem::is_directory(path)) {
150 for (auto& entry : boost::make_iterator_range(
151 boost::filesystem::directory_iterator(path), {})) {
152 GetFilesByPath(entry.path(), files);
153 }
154 }
155}
#define ACHECK(cond)
Definition log.h:80
#define AINFO
Definition log.h:42

◆ IsDifferentRouting()

bool apollo::planning::util::IsDifferentRouting ( const PlanningCommand &  first,
const PlanningCommand &  second 
)

在文件 util.cc 第 46 行定义.

47 {
48 if (first.has_header() && second.has_header()) {
49 const auto& first_header = first.header();
50 const auto& second_header = second.header();
51 return (first_header.sequence_num() != second_header.sequence_num() ||
52 first_header.module_name() != second_header.module_name() ||
53 first_header.timestamp_sec() != second_header.timestamp_sec());
54 }
55 return true;
56}
optional apollo::common::Header header

◆ IsVehicleStateValid()

bool apollo::planning::util::IsVehicleStateValid ( const VehicleState &  vehicle_state)

在文件 util.cc 第 35 行定义.

35 {
36 if (std::isnan(vehicle_state.x()) || std::isnan(vehicle_state.y()) ||
37 std::isnan(vehicle_state.z()) || std::isnan(vehicle_state.heading()) ||
38 std::isnan(vehicle_state.kappa()) ||
39 std::isnan(vehicle_state.linear_velocity()) ||
40 std::isnan(vehicle_state.linear_acceleration())) {
41 return false;
42 }
43 return true;
44}

◆ left_arc_bound_with_heading()

bool apollo::planning::util::left_arc_bound_with_heading ( double  delta_x,
double  r,
double  heading,
double *  result 
)

在文件 util.cc 第 243 行定义.

244 {
245 // calculate △L(positive or negative) with an arc with given radius, and given
246 // init_heading the circle can be written as (x-Rsin)^2 + (y+Rcos)^2 = R^2 the
247 // upper side of the circel = (sqrt(R^2 - (x-Rsin)^2) - Rcos) is what we need
248 if (delta_x > r * (1.0 + std::sin(heading)) - 1e-6) {
249 *result = std::numeric_limits<double>::lowest();
250 return false;
251 }
252
253 *result = std::sqrt(r * r - std::pow(delta_x - r * std::sin(heading), 2)) -
254 r * std::cos(heading);
255 return true;
256}

◆ left_arc_bound_with_heading_with_reverse_kappa()

bool apollo::planning::util::left_arc_bound_with_heading_with_reverse_kappa ( double  delta_x,
double  r,
double  heading,
double  kappa,
double *  result 
)

在文件 util.cc 第 272 行定义.

275 {
276 // calculate △L(positive or negative) with an arc with given radius, and given
277 // init_heading the circle can be written as (x-Rsin)^2 + (y+Rcos)^2 = R^2 the
278 // upper side of the circel = (sqrt(R^2 - (x-Rsin)^2) - Rcos) is what we need
279 if (heading > 0 || kappa < 0 ||
280 delta_x > r * (1.0 - std::sin(heading)) - 1e-6) {
281 *result = std::numeric_limits<double>::lowest();
282 return false;
283 }
284 if (delta_x < -r * std::sin(heading)) {
285 *result = r * std::cos(heading) -
286 std::sqrt(r * r - std::pow(delta_x - r * std::sin(heading), 2));
287 } else {
288 *result = std::sqrt(r * r - std::pow(delta_x + r * std::sin(heading), 2)) -
289 r * (2 - std::cos(heading));
290 }
291 return true;
292}

◆ right_arc_bound_with_heading()

bool apollo::planning::util::right_arc_bound_with_heading ( double  delta_x,
double  r,
double  heading,
double *  result 
)

在文件 util.cc 第 258 行定义.

259 {
260 // calculate △L(positive or negative) with an arc with given radius, and given
261 // init_heading the circle can be written as (x+Rsin)^2 + (y-Rcos)^2 = R^2 the
262 // upper side of the circel = (Rcos - sqrt(R^2 - (x+Rsin)^2) )is what we need
263 if (delta_x > r * (1.0 - std::sin(heading)) - 1e-6) {
264 *result = std::numeric_limits<double>::max();
265 return false;
266 }
267 *result = r * std::cos(heading) -
268 std::sqrt(r * r - std::pow(delta_x + r * std::sin(heading), 2));
269 return true;
270}

◆ right_arc_bound_with_heading_with_reverse_kappa()

bool apollo::planning::util::right_arc_bound_with_heading_with_reverse_kappa ( double  delta_x,
double  r,
double  heading,
double  kappa,
double *  result 
)

在文件 util.cc 第 294 行定义.

297 {
298 // calculate △L(positive or negative) with an arc with given radius, and given
299 // init_heading the circle can be written as (x+Rsin)^2 + (y-Rcos)^2 = R^2 the
300 // upper side of the circel = (Rcos - sqrt(R^2 - (x+Rsin)^2) )is what we need
301 if (heading < 0 || kappa > 0 ||
302 delta_x > r * (1.0 - std::sin(heading)) - 1e-6) {
303 *result = std::numeric_limits<double>::max();
304 return false;
305 }
306 if (delta_x < r * std::sin(heading)) {
307 *result = std::sqrt(r * r - std::pow(delta_x - r * std::sin(heading), 2)) -
308 r * std::cos(heading);
309 } else {
310 *result = r * (2 - std::cos(heading)) -
311 std::sqrt(r * r - std::pow(delta_x - r * std::sin(heading), 2));
312 }
313 return true;
314}

◆ WorldAngleToObjAngle()

double apollo::planning::util::WorldAngleToObjAngle ( double  input_world_angle,
double  obj_world_angle 
)

在文件 math_util.cc 第 37 行定义.

37 {
38 return common::math::NormalizeAngle(input_world_angle - obj_world_angle);
39}

◆ WorldCoordToObjCoord()

std::pair< double, double > apollo::planning::util::WorldCoordToObjCoord ( std::pair< double, double >  input_world_coord,
std::pair< double, double >  obj_world_coord,
double  obj_world_angle 
)

在文件 math_util.cc 第 26 行定义.

28 {
29 double x_diff = input_world_coord.first - obj_world_coord.first;
30 double y_diff = input_world_coord.second - obj_world_coord.second;
31 double rho = std::sqrt(x_diff * x_diff + y_diff * y_diff);
32 double theta = std::atan2(y_diff, x_diff) - obj_world_angle;
33
34 return std::make_pair(std::cos(theta) * rho, std::sin(theta) * rho);
35}