Apollo 10.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.cc28 行定义.

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.cc84 行定义.

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.cc203 行定义.

204 {
205 const auto& vehicle_param =
206 common::VehicleConfigHelper::Instance()->GetConfig().vehicle_param();
207 double max_kappa = 1.0 / vehicle_param.min_turn_radius();
208 double half_wb = 0.5 * vehicle_param.wheel_base();
209 double front_l = vehicle_param.front_edge_to_center() - half_wb;
210 double half_w = 0.5 * vehicle_param.width();
211 double current_heading = lane_info->Heading(s);
212 double heading_f = lane_info->Heading(s + front_l);
213 double heading_b = lane_info->Heading(s - half_wb);
214 // average kappa from front edge to center
215 double kappa_f =
216 apollo::common::math::NormalizeAngle(heading_f - current_heading) /
217 front_l;
218 // average kappa from center to rear axle
219 double kappa_b =
220 apollo::common::math::NormalizeAngle(current_heading - heading_b) /
221 half_wb;
222 *is_left = (kappa_b < 0.0);
223 // prevent devide by 0, and quit if lane bends to difference direction
224 if (kappa_f * kappa_b < 0.0 || fabs(kappa_f) < 1e-6) {
225 return half_w;
226 }
227
228 kappa_f = std::min(fabs(kappa_f), max_kappa);
229 kappa_b = std::min(fabs(kappa_b), max_kappa);
230 double theta = apollo::common::math::Vec2d(1.0, half_wb * kappa_b).Angle();
231 double sint = std::sin(theta);
232 double cost = std::cos(theta);
233 double r_f = 1.0 / kappa_f;
234 double eq_half_w =
235 apollo::common::math::Vec2d(front_l * cost - half_w * sint,
236 r_f + front_l * sint + half_w * cost)
237 .Length() -
238 r_f;
239 return std::max(eq_half_w, half_w);
240}
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.cc159 行定义.

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

114 {
115 const double adc_front_edge_s = reference_line_info.AdcSlBoundary().end_s();
116 const double adc_back_edge_s = reference_line_info.AdcSlBoundary().start_s();
117
118 hdmap::PathOverlap junction_overlap;
119 reference_line_info.GetJunction(adc_front_edge_s, &junction_overlap);
120 if (junction_overlap.object_id.empty()) {
121 return false;
122 }
123
124 static constexpr double kIntersectionPassDist = 2.0; // unit: m
125 const double distance_adc_pass_intersection =
126 adc_back_edge_s - junction_overlap.end_s;
127 ADEBUG << "distance_adc_pass_intersection[" << distance_adc_pass_intersection
128 << "] junction_overlap[" << junction_overlap.object_id << "] start_s["
129 << junction_overlap.start_s << "]";
130
131 return distance_adc_pass_intersection < kIntersectionPassDist;
132}
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.cc83 行定义.

84 {
85 const std::vector<PathOverlap>& stop_sign_overlaps =
86 reference_line_info.reference_line().map_path().stop_sign_overlaps();
87 auto stop_sign_overlap_it =
88 std::find_if(stop_sign_overlaps.begin(), stop_sign_overlaps.end(),
89 [&stop_sign_overlap_id](const PathOverlap& overlap) {
90 return overlap.object_id == stop_sign_overlap_id;
91 });
92 return (stop_sign_overlap_it != stop_sign_overlaps.end());
93}
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.cc98 行定义.

100 {
101 const std::vector<PathOverlap>& traffic_light_overlaps =
102 reference_line_info.reference_line().map_path().signal_overlaps();
103 auto traffic_light_overlap_it =
104 std::find_if(traffic_light_overlaps.begin(), traffic_light_overlaps.end(),
105 [&traffic_light_overlap_id](const PathOverlap& overlap) {
106 return overlap.object_id == traffic_light_overlap_id;
107 });
108 return (traffic_light_overlap_it != traffic_light_overlaps.end());
109}
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.cc57 行定义.

59 {
60 double adc_speed = vehicle_state->linear_velocity();
61 const double max_adc_stop_speed = common::VehicleConfigHelper::Instance()
62 ->GetConfig()
63 .vehicle_param()
64 .max_abs_speed_when_stopped();
65 if (adc_speed < max_adc_stop_speed) {
66 return 0.0;
67 }
68
69 double stop_distance = 0;
70
71 if (stop_line_s > adc_front_edge_s) {
72 stop_distance = stop_line_s - adc_front_edge_s;
73 }
74 if (stop_distance < 1e-5) {
75 return std::numeric_limits<double>::max();
76 }
77 return (adc_speed * adc_speed) / (2 * stop_distance);
78}
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.cc137 行定义.

138 {
139 ACHECK(files);
140 if (!boost::filesystem::exists(path)) {
141 return;
142 }
143 if (boost::filesystem::is_regular_file(path)) {
144 AINFO << "Found record file: " << path.c_str();
145 files->push_back(path.c_str());
146 return;
147 }
148 if (boost::filesystem::is_directory(path)) {
149 for (auto& entry : boost::make_iterator_range(
150 boost::filesystem::directory_iterator(path), {})) {
151 GetFilesByPath(entry.path(), files);
152 }
153 }
154}
#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.cc46 行定义.

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 }
54 return true;
55}
optional apollo::common::Header header

◆ IsVehicleStateValid()

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

在文件 util.cc35 行定义.

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.cc242 行定义.

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

◆ 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.cc271 行定义.

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

◆ right_arc_bound_with_heading()

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

在文件 util.cc257 行定义.

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

◆ 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.cc293 行定义.

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

◆ WorldAngleToObjAngle()

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

在文件 math_util.cc37 行定义.

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.cc26 行定义.

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}