25#include "modules/prediction/proto/prediction_conf.pb.h"
30using common::PathPoint;
31using common::TrajectoryPoint;
43 CHECK_NOTNULL(obstacle);
50 if (!feature.has_lane() || !feature.
lane().has_lane_graph()) {
51 AERROR <<
"Obstacle [" << obstacle->
id() <<
" has no lane graph.";
55 std::string lane_id =
"";
56 if (feature.
lane().has_lane_feature()) {
57 lane_id = feature.
lane().lane_feature().lane_id();
59 int num_lane_sequence = feature.
lane().lane_graph().lane_sequence_size();
60 std::vector<bool> enable_lane_sequence(num_lane_sequence,
true);
62 obstacles_container->
GetObstacle(FLAGS_ego_vehicle_id);
64 adc_trajectory_container, &enable_lane_sequence);
66 for (
int i = 0; i < num_lane_sequence; ++i) {
69 AERROR <<
"Empty lane segments.";
73 if (!enable_lane_sequence[i]) {
76 <<
"] is disqualified.";
80 ADEBUG <<
"Obstacle [" << obstacle->
id()
81 <<
"] will draw a lane sequence trajectory [" <<
ToString(sequence)
82 <<
"] with probability [" << sequence.
probability() <<
"].";
84 std::vector<TrajectoryPoint> points;
85 bool is_about_to_stop =
false;
86 double acceleration = 0.0;
87 if (sequence.has_stop_sign()) {
88 double stop_distance =
90 is_about_to_stop =
SupposedToStop(feature, stop_distance, &acceleration);
93 if (is_about_to_stop) {
95 *obstacle, sequence, FLAGS_prediction_trajectory_time_length,
96 FLAGS_prediction_trajectory_time_resolution, acceleration, &points);
99 *obstacle, sequence, FLAGS_prediction_trajectory_time_length,
100 FLAGS_prediction_trajectory_time_resolution, &points);
103 if (points.empty()) {
107 if (FLAGS_enable_trajectory_validation_check &&
113 trajectory.set_probability(sequence.
probability());
122 const double total_time,
const double period,
123 std::vector<TrajectoryPoint>* points) {
125 if (!feature.has_position() || !feature.has_velocity() ||
127 AERROR <<
"Obstacle [" << obstacle.
id()
128 <<
" is missing position or velocity";
133 double speed = feature.
speed();
135 int lane_segment_index = 0;
136 std::string lane_id =
142 AERROR <<
"Failed in getting lane s and lane l";
145 double approach_rate = FLAGS_go_approach_rate;
147 approach_rate = FLAGS_cutin_approach_rate;
149 size_t total_num =
static_cast<size_t>(total_time / period);
150 for (
size_t i = 0; i < total_num; ++i) {
151 double relative_time =
static_cast<double>(i) * period;
152 Eigen::Vector2d point;
156 AERROR <<
"Unable to get smooth point from lane [" << lane_id
157 <<
"] with s [" << lane_s <<
"] and l [" << lane_l <<
"]";
162 path_point.set_x(point.x());
163 path_point.set_y(point.y());
164 path_point.set_z(0.0);
165 path_point.set_theta(theta);
166 path_point.set_lane_id(lane_id);
167 trajectory_point.mutable_path_point()->CopyFrom(path_point);
168 trajectory_point.set_v(speed);
169 trajectory_point.set_a(0.0);
170 trajectory_point.set_relative_time(relative_time);
171 points->emplace_back(std::move(trajectory_point));
173 lane_s += speed * period;
176 lane_segment_index + 1 < lane_sequence.lane_segment_size()) {
177 lane_segment_index += 1;
182 lane_l *= approach_rate;
LaneSequencePredictor()
Constructor
bool Predict(const ADCTrajectoryContainer *adc_trajectory_container, Obstacle *obstacle, ObstaclesContainer *obstacles_container) override
Make prediction
void DrawLaneSequenceTrajectoryPoints(const Obstacle &obstacle, const LaneSequence &lane_sequence, const double total_time, const double period, std::vector< apollo::common::TrajectoryPoint > *points)
Draw lane sequence trajectory points
Feature * mutable_latest_feature()
Get a pointer to the latest feature.
int id() const
Get the obstacle's ID.
size_t history_size() const
Get the number of historical features.
void SetPredictorType(const ObstacleConf::PredictorType &predictor_type)
const Feature & latest_feature() const
Get the latest feature.
Obstacle * GetObstacle(const int id)
Get obstacle pointer
static bool SmoothPointFromLane(const std::string &id, const double s, const double l, Eigen::Vector2d *point, double *heading)
Get the smooth point on a lane by a longitudinal coordinate.
static std::shared_ptr< const hdmap::LaneInfo > LaneById(const std::string &id)
Get a shared pointer to a lane by lane ID.
static bool GetProjection(const Eigen::Vector2d &position, const std::shared_ptr< const hdmap::LaneInfo > lane_info, double *s, double *l)
Get the frenet coordinates (s, l) on a lane by a position.
static Trajectory GenerateTrajectory(const std::vector< apollo::common::TrajectoryPoint > &points)
Generate trajectory from trajectory points
ObstacleConf::PredictorType predictor_type_
bool SupposedToStop(const Feature &feature, const double stop_distance, double *acceleration)
Determine if an obstacle is supposed to stop within a distance
void FilterLaneSequences(const Feature &feature, const std::string &lane_id, const Obstacle *ego_vehicle_ptr, const ADCTrajectoryContainer *adc_trajectory_container, std::vector< bool > *enable_lane_sequence)
Filter lane sequences
void DrawConstantAccelerationTrajectory(const Obstacle &obstacle, const LaneSequence &lane_sequence, const double total_time, const double period, const double acceleration, std::vector< apollo::common::TrajectoryPoint > *points)
Draw constant acceleration trajectory points
std::string ToString(const LaneSequence &sequence)
Convert a lane sequence to string
void Clear()
Clear private members
static bool ValidCentripetalAcceleration(const std::vector< common::TrajectoryPoint > &discretized_trajectory)
Check the validity of trajectory's centripetal acceleration
Define lane sequence predictor
optional apollo::common::Point3D position
optional bool vehicle_on_lane
optional StopSign stop_sign
repeated LaneSegment lane_segment
optional double probability
@ LANE_SEQUENCE_PREDICTOR
optional double lane_sequence_s