Apollo  6.0
Open source self driving car software
open_space_trajectory_partition.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright 2019 The Apollo Authors. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *****************************************************************************/
16 
21 #pragma once
22 
23 #include <memory>
24 #include <string>
25 #include <utility>
26 #include <vector>
27 
28 #include "modules/canbus/proto/chassis.pb.h"
34 
35 namespace apollo {
36 namespace planning {
38  public:
40  const TaskConfig& config,
41  const std::shared_ptr<DependencyInjector>& injector);
42 
44 
45  void Restart();
46 
47  private:
48  common::Status Process() override;
49 
50  void InterpolateTrajectory(
51  const DiscretizedTrajectory& stitched_trajectory_result,
52  DiscretizedTrajectory* interpolated_trajectory);
53 
54  void UpdateVehicleInfo();
55 
56  bool EncodeTrajectory(const DiscretizedTrajectory& trajectory,
57  std::string* const encoding);
58 
59  bool CheckTrajTraversed(const std::string& trajectory_encoding_to_check);
60 
61  void UpdateTrajHistory(const std::string& chosen_trajectory_encoding);
62 
63  void PartitionTrajectory(const DiscretizedTrajectory& trajectory,
64  std::vector<TrajGearPair>* partitioned_trajectories);
65 
66  void LoadTrajectoryPoint(const common::TrajectoryPoint& trajectory_point,
67  const bool is_trajectory_last_point,
68  const canbus::Chassis::GearPosition& gear,
69  common::math::Vec2d* last_pos_vec,
70  double* distance_s,
71  DiscretizedTrajectory* current_trajectory);
72 
73  bool CheckReachTrajectoryEnd(const DiscretizedTrajectory& trajectory,
74  const canbus::Chassis::GearPosition& gear,
75  const size_t trajectories_size,
76  const size_t trajectories_index,
77  size_t* current_trajectory_index,
78  size_t* current_trajectory_point_index);
79 
80  bool UseFailSafeSearch(
81  const std::vector<TrajGearPair>& partitioned_trajectories,
82  const std::vector<std::string>& trajectories_encodings,
83  size_t* current_trajectory_index, size_t* current_trajectory_point_index);
84 
85  bool InsertGearShiftTrajectory(
86  const bool flag_change_to_next, const size_t current_trajectory_index,
87  const std::vector<TrajGearPair>& partitioned_trajectories,
88  TrajGearPair* gear_switch_idle_time_trajectory);
89 
90  void GenerateGearShiftTrajectory(
91  const canbus::Chassis::GearPosition& gear_position,
92  TrajGearPair* gear_switch_idle_time_trajectory);
93 
94  void AdjustRelativeTimeAndS(
95  const std::vector<TrajGearPair>& partitioned_trajectories,
96  const size_t current_trajectory_index,
97  const size_t closest_trajectory_point_index,
98  DiscretizedTrajectory* stitched_trajectory_result,
99  TrajGearPair* current_partitioned_trajectory);
100 
101  private:
102  OpenSpaceTrajectoryPartitionConfig open_space_trajectory_partition_config_;
103  double heading_search_range_ = 0.0;
104  double heading_track_range_ = 0.0;
105  double distance_search_range_ = 0.0;
106  double heading_offset_to_midpoint_ = 0.0;
107  double lateral_offset_to_midpoint_ = 0.0;
108  double longitudinal_offset_to_midpoint_ = 0.0;
109  double vehicle_box_iou_threshold_to_midpoint_ = 0.0;
110  double linear_velocity_threshold_on_ego_ = 0.0;
111 
112  common::VehicleParam vehicle_param_;
113  double ego_length_ = 0.0;
114  double ego_width_ = 0.0;
115  double shift_distance_ = 0.0;
116  double wheel_base_ = 0.0;
117 
118  double ego_theta_ = 0.0;
119  double ego_x_ = 0.0;
120  double ego_y_ = 0.0;
121  double ego_v_ = 0.0;
122  common::math::Box2d ego_box_;
123  double vehicle_moving_direction_ = 0.0;
124 
125  struct pair_comp_ {
126  bool operator()(
127  const std::pair<std::pair<size_t, size_t>, double>& left,
128  const std::pair<std::pair<size_t, size_t>, double>& right) const {
129  return left.second <= right.second;
130  }
131  };
132  struct comp_ {
133  bool operator()(const std::pair<size_t, double>& left,
134  const std::pair<size_t, double>& right) {
135  return left.second <= right.second;
136  }
137  };
138 };
139 } // namespace planning
140 } // namespace apollo
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
Definition: discretized_trajectory.h:32
Planning module main class. It processes GPS and IMU as input, to generate planning info...
Definition: trajectory_optimizer.h:33
std::pair< DiscretizedTrajectory, canbus::Chassis::GearPosition > TrajGearPair
Definition: open_space_info.h:48
Rectangular (undirected) bounding box in 2-D.
Definition: box2d.h:52
Definition: open_space_trajectory_partition.h:37
Implements a class of 2-dimensional vectors.
Definition: vec2d.h:42
Linear interpolation functions.
A general class to denote the return status of an API call. It can either be an OK status for success...
Definition: status.h:43
OpenSpaceTrajectoryPartition(const TaskConfig &config, const std::shared_ptr< DependencyInjector > &injector)