Apollo 10.0
自动驾驶开放平台
apollo::prediction::predictor_util 命名空间参考

函数

void TranslatePoint (const double translate_x, const double translate_y, common::TrajectoryPoint *point)
 Translate a point.
 
void GenerateFreeMoveTrajectoryPoints (Eigen::Matrix< double, 6, 1 > *state, const Eigen::Matrix< double, 6, 6 > &transition, double theta, const double start_time, const std::size_t num, const double period, std::vector< TrajectoryPoint > *points)
 Generate a set of free move trajectory points
 
double AdjustSpeedByCurvature (const double speed, const double curvature)
 Adjust a speed value according to a curvature.
 
void GenerateFreeMoveTrajectoryPoints (Eigen::Matrix< double, 6, 1 > *state, const Eigen::Matrix< double, 6, 6 > &transition, double theta, const double start_time, const std::size_t num, const double period, std::vector< common::TrajectoryPoint > *points)
 Generate a set of free move trajectory points
 

函数说明

◆ AdjustSpeedByCurvature()

double apollo::prediction::predictor_util::AdjustSpeedByCurvature ( const double  speed,
const double  curvature 
)

Adjust a speed value according to a curvature.

If the input speed is okay on the input curvature, return the original speed, otherwise, adjust the speed.

参数
speedThe original speed value.
curvatureThe curvature value.
返回
The adjusted speed according to the curvature.

在文件 prediction_util.cc322 行定义.

322 {
323 if (std::abs(curvature) < FLAGS_turning_curvature_lower_bound) {
324 return speed;
325 }
326 if (std::abs(curvature) > FLAGS_turning_curvature_upper_bound) {
327 return FLAGS_speed_at_upper_curvature;
328 }
330 FLAGS_speed_at_lower_curvature, FLAGS_turning_curvature_lower_bound,
331 FLAGS_speed_at_upper_curvature, FLAGS_turning_curvature_upper_bound,
332 curvature);
333}
T lerp(const T &x0, const double t0, const T &x1, const double t1, const double t)
Linear interpolation between two points of type T.

◆ GenerateFreeMoveTrajectoryPoints() [1/2]

void apollo::prediction::predictor_util::GenerateFreeMoveTrajectoryPoints ( Eigen::Matrix< double, 6, 1 > *  state,
const Eigen::Matrix< double, 6, 6 > &  transition,
double  theta,
const double  start_time,
const std::size_t  num,
const double  period,
std::vector< common::TrajectoryPoint > *  points 
)

Generate a set of free move trajectory points

参数
statematrix
transitionmatrix
heading
starttime
totalnumber of generated trajectory points required
trajectorypoint interval period
generatedtrajectory points

在文件 prediction_util.cc240 行定义.

244 {
245 double x = (*state)(0, 0);
246 double y = (*state)(1, 0);
247 double v_x = (*state)(2, 0);
248 double v_y = (*state)(3, 0);
249 double acc_x = (*state)(4, 0);
250 double acc_y = (*state)(5, 0);
251
252 for (std::size_t i = 0; i < num; ++i) {
253 double speed = std::hypot(v_x, v_y);
254 double acc = 0.0;
255 if (speed <= std::numeric_limits<double>::epsilon()) {
256 speed = 0.0;
257 v_x = 0.0;
258 v_y = 0.0;
259 acc_x = 0.0;
260 acc_y = 0.0;
261 acc = 0.0;
262 } else {
263 speed = std::fmin(speed, FLAGS_vehicle_max_speed);
264 }
265
266 // update theta and acc
267 if (speed > std::numeric_limits<double>::epsilon()) {
268 if (points->size() > 0) {
269 TrajectoryPoint& prev_trajectory_point = points->back();
270 PathPoint* prev_path_point = prev_trajectory_point.mutable_path_point();
271 theta = std::atan2(y - prev_path_point->y(), x - prev_path_point->x());
272 prev_path_point->set_theta(theta);
273 acc = (speed - prev_trajectory_point.v()) / period;
274 prev_trajectory_point.set_a(acc);
275 }
276 } else {
277 if (points->size() > 0) {
278 theta = points->back().path_point().theta();
279 }
280 }
281
282 // update state
283 if (!FLAGS_free_move_predict_with_accelerate) {
284 acc_x = 0.0;
285 acc_y = 0.0;
286 }
287
288 (*state)(2, 0) = v_x;
289 (*state)(3, 0) = v_y;
290 (*state)(4, 0) = acc_x;
291 (*state)(5, 0) = acc_y;
292
293 // obtain position
294 x = (*state)(0, 0);
295 y = (*state)(1, 0);
296
297 // Generate trajectory point
298 TrajectoryPoint trajectory_point;
299 PathPoint path_point;
300 path_point.set_x(x);
301 path_point.set_y(y);
302 path_point.set_z(0.0);
303 path_point.set_theta(theta);
304 trajectory_point.mutable_path_point()->CopyFrom(path_point);
305 trajectory_point.set_v(speed);
306 trajectory_point.set_a(acc);
307 trajectory_point.set_relative_time(start_time +
308 static_cast<double>(i) * period);
309 points->emplace_back(std::move(trajectory_point));
310
311 // Update position, velocity and acceleration
312 (*state) = transition * (*state);
313 x = (*state)(0, 0);
314 y = (*state)(1, 0);
315 v_x = (*state)(2, 0);
316 v_y = (*state)(3, 0);
317 acc_x = (*state)(4, 0);
318 acc_y = (*state)(5, 0);
319 }
320}

◆ GenerateFreeMoveTrajectoryPoints() [2/2]

void apollo::prediction::predictor_util::GenerateFreeMoveTrajectoryPoints ( Eigen::Matrix< double, 6, 1 > *  state,
const Eigen::Matrix< double, 6, 6 > &  transition,
double  theta,
const double  start_time,
const std::size_t  num,
const double  period,
std::vector< common::TrajectoryPoint > *  points 
)

Generate a set of free move trajectory points

参数
statematrix
transitionmatrix
heading
starttime
totalnumber of generated trajectory points required
trajectorypoint interval period
generatedtrajectory points

在文件 prediction_util.cc240 行定义.

244 {
245 double x = (*state)(0, 0);
246 double y = (*state)(1, 0);
247 double v_x = (*state)(2, 0);
248 double v_y = (*state)(3, 0);
249 double acc_x = (*state)(4, 0);
250 double acc_y = (*state)(5, 0);
251
252 for (std::size_t i = 0; i < num; ++i) {
253 double speed = std::hypot(v_x, v_y);
254 double acc = 0.0;
255 if (speed <= std::numeric_limits<double>::epsilon()) {
256 speed = 0.0;
257 v_x = 0.0;
258 v_y = 0.0;
259 acc_x = 0.0;
260 acc_y = 0.0;
261 acc = 0.0;
262 } else {
263 speed = std::fmin(speed, FLAGS_vehicle_max_speed);
264 }
265
266 // update theta and acc
267 if (speed > std::numeric_limits<double>::epsilon()) {
268 if (points->size() > 0) {
269 TrajectoryPoint& prev_trajectory_point = points->back();
270 PathPoint* prev_path_point = prev_trajectory_point.mutable_path_point();
271 theta = std::atan2(y - prev_path_point->y(), x - prev_path_point->x());
272 prev_path_point->set_theta(theta);
273 acc = (speed - prev_trajectory_point.v()) / period;
274 prev_trajectory_point.set_a(acc);
275 }
276 } else {
277 if (points->size() > 0) {
278 theta = points->back().path_point().theta();
279 }
280 }
281
282 // update state
283 if (!FLAGS_free_move_predict_with_accelerate) {
284 acc_x = 0.0;
285 acc_y = 0.0;
286 }
287
288 (*state)(2, 0) = v_x;
289 (*state)(3, 0) = v_y;
290 (*state)(4, 0) = acc_x;
291 (*state)(5, 0) = acc_y;
292
293 // obtain position
294 x = (*state)(0, 0);
295 y = (*state)(1, 0);
296
297 // Generate trajectory point
298 TrajectoryPoint trajectory_point;
299 PathPoint path_point;
300 path_point.set_x(x);
301 path_point.set_y(y);
302 path_point.set_z(0.0);
303 path_point.set_theta(theta);
304 trajectory_point.mutable_path_point()->CopyFrom(path_point);
305 trajectory_point.set_v(speed);
306 trajectory_point.set_a(acc);
307 trajectory_point.set_relative_time(start_time +
308 static_cast<double>(i) * period);
309 points->emplace_back(std::move(trajectory_point));
310
311 // Update position, velocity and acceleration
312 (*state) = transition * (*state);
313 x = (*state)(0, 0);
314 y = (*state)(1, 0);
315 v_x = (*state)(2, 0);
316 v_y = (*state)(3, 0);
317 acc_x = (*state)(4, 0);
318 acc_y = (*state)(5, 0);
319 }
320}

◆ TranslatePoint()

void apollo::prediction::predictor_util::TranslatePoint ( const double  translate_x,
const double  translate_y,
common::TrajectoryPoint point 
)

Translate a point.

参数
translate_xThe translation along x-axis.
translate_yThe translation along y-axis.
pointThe point to be translated.

在文件 prediction_util.cc228 行定义.

229 {
230 if (point == nullptr || !point->has_path_point()) {
231 AERROR << "Point is nullptr or has NO path_point.";
232 return;
233 }
234 const double original_x = point->path_point().x();
235 const double original_y = point->path_point().y();
236 point->mutable_path_point()->set_x(original_x + translate_x);
237 point->mutable_path_point()->set_y(original_y + translate_y);
238}
#define AERROR
Definition log.h:44