35 const std::vector<TrajectoryPoint>& points) {
37 *trajectory.mutable_trajectory_point() = {points.begin(), points.end()};
42 const int start_index,
47 const auto prob = total_probability /
static_cast<double>(num - start_index);
48 for (
int i = start_index; i < num; ++i) {
50 ->mutable_predicted_trajectory(i)
51 ->set_probability(prob);
60 for (
auto& predicted_trajectory :
62 TrimTrajectory(adc_trajectory_container, obstacle, &predicted_trajectory);
70 ADEBUG <<
"Not in protection mode.";
73 if (obstacle ==
nullptr || obstacle->
history_size() == 0) {
74 AERROR <<
"Invalid obstacle.";
77 int num_of_point = trajectory->trajectory_point_size();
78 if (num_of_point == 0) {
82 double vehicle_length = feature.
length();
84 double forward_length =
85 std::fmax(vehicle_length / 2.0 - FLAGS_distance_beyond_junction, 0.0);
88 forward_length * std::cos(vehicle_heading);
90 forward_length * std::sin(vehicle_heading);
92 front_point.set_x(front_x);
93 front_point.set_y(front_y);
94 bool front_in_junction =
98 bool start_in_junction =
101 if (front_in_junction || start_in_junction) {
106 while (index < num_of_point) {
115 if (index == num_of_point) {
119 for (
int i = index; i < num_of_point; ++i) {
120 trajectory->mutable_trajectory_point()->RemoveLast();
126 const double stop_distance,
127 double* acceleration) {
128 if (stop_distance < std::max(feature.
length() * 0.5, 1.0)) {
131 if (stop_distance > FLAGS_distance_to_slow_down_at_stop_sign) {
134 double speed = feature.
speed();
135 *acceleration = -speed * speed / (2.0 * stop_distance);
136 return *acceleration <= -FLAGS_double_precision &&
137 *acceleration >= FLAGS_vehicle_min_linear_acc;
bool IsPointInJunction(const common::PathPoint &point) const
Check if a point is in the first junction of the adc trajectory
bool IsProtected() const
Get the right-of-way status of ADC
Feature * mutable_latest_feature()
Get a pointer to the latest feature.
size_t history_size() const
Get the number of historical features.
const Feature & latest_feature() const
Get the latest feature.
const ObstacleConf::PredictorType & predictor_type()
get the predictor type
bool TrimTrajectory(const ADCTrajectoryContainer &adc_trajectory_container, Obstacle *obstacle, Trajectory *trajectory)
Trim a single prediction trajectory, keep the portion that is not in junction.
void TrimTrajectories(const ADCTrajectoryContainer &adc_trajectory_container, Obstacle *obstacle)
Trim prediction trajectories by adc trajectory
void SetEqualProbability(const double probability, const int start_index, Obstacle *obstacle_ptr)
Set equal probability to prediction trajectories
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
virtual void Clear()
Clear all trajectories
int NumOfTrajectories(const Obstacle &obstacle)
Get trajectory size
Define the predictor base class
optional PathPoint path_point
optional double velocity_heading
repeated apollo::common::TrajectoryPoint trajectory_point