Apollo  6.0
Open source self driving car software
open_space_info.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 
20 #pragma once
21 
22 #include <string>
23 #include <utility>
24 #include <vector>
25 
26 #include "Eigen/Dense"
27 #include "cyber/common/log.h"
28 #include "modules/canbus/proto/chassis.pb.h"
29 #include "modules/common/configs/proto/vehicle_config.pb.h"
32 #include "modules/common/vehicle_state/proto/vehicle_state.pb.h"
36 #include "modules/map/proto/map_id.pb.h"
42 #include "modules/planning/proto/planning_internal.pb.h"
43 
44 namespace apollo {
45 namespace planning {
46 
47 typedef std::pair<DiscretizedTrajectory, canbus::Chassis::GearPosition>
49 
51  bool gear_switching_flag = false;
54  double gear_shift_period_time = 0.0;
55  double gear_shift_start_time = 0.0;
56  apollo::canbus::Chassis::GearPosition gear_shift_position =
57  canbus::Chassis::GEAR_DRIVE;
58 };
59 
61  public:
62  OpenSpaceInfo() = default;
63  ~OpenSpaceInfo() = default;
64 
65  const std::string target_parking_spot_id() const {
66  return target_parking_spot_id_;
67  }
68 
70  return &target_parking_spot_id_;
71  }
72 
74  return target_parking_spot_;
75  }
76 
78  return &target_parking_spot_;
79  }
80 
82  return target_parking_lane_;
83  }
84 
86  target_parking_lane_ = lane_info_const_ptr;
87  }
88 
89  double open_space_pre_stop_fence_s() const {
90  return open_space_pre_stop_fence_s_;
91  }
92 
93  void set_open_space_pre_stop_fence_s(const double s) {
94  open_space_pre_stop_fence_s_ = s;
95  }
96 
97  bool pre_stop_rightaway_flag() const { return pre_stop_rightaway_flag_; }
98 
99  void set_pre_stop_rightaway_flag(const bool flag) {
100  pre_stop_rightaway_flag_ = flag;
101  }
102 
104  return pre_stop_rightaway_point_;
105  }
106 
108  return &pre_stop_rightaway_point_;
109  }
110 
112  return is_on_open_space_trajectory_;
113  }
114 
115  void set_is_on_open_space_trajectory(const bool flag) {
116  is_on_open_space_trajectory_ = flag;
117  }
118 
119  size_t obstacles_num() const { return obstacles_num_; }
120 
121  void set_obstacles_num(const size_t obstacles_num) {
122  obstacles_num_ = obstacles_num;
123  }
124 
125  const Eigen::MatrixXi &obstacles_edges_num() const {
126  return obstacles_edges_num_;
127  }
128 
129  Eigen::MatrixXi *mutable_obstacles_edges_num() {
130  return &obstacles_edges_num_;
131  }
132 
133  const std::vector<std::vector<common::math::Vec2d>> &obstacles_vertices_vec()
134  const {
135  return obstacles_vertices_vec_;
136  }
137 
138  std::vector<std::vector<common::math::Vec2d>>
140  return &obstacles_vertices_vec_;
141  }
142 
143  const Eigen::MatrixXd &obstacles_A() const { return obstacles_A_; }
144 
145  Eigen::MatrixXd *mutable_obstacles_A() { return &obstacles_A_; }
146 
147  const Eigen::MatrixXd &obstacles_b() const { return obstacles_b_; }
148 
149  Eigen::MatrixXd *mutable_obstacles_b() { return &obstacles_b_; }
150 
151  double origin_heading() const { return origin_heading_; }
152 
153  void set_origin_heading(const double original_heading) {
154  origin_heading_ = original_heading;
155  }
156 
157  const common::math::Vec2d &origin_point() const { return origin_point_; }
158 
159  common::math::Vec2d *mutable_origin_point() { return &origin_point_; }
160 
161  const std::vector<double> &ROI_xy_boundary() const {
162  return ROI_xy_boundary_;
163  }
164 
165  std::vector<double> *mutable_ROI_xy_boundary() { return &ROI_xy_boundary_; }
166 
167  const std::vector<double> &open_space_end_pose() const {
168  return open_space_end_pose_;
169  }
170 
171  std::vector<double> *mutable_open_space_end_pose() {
172  return &open_space_end_pose_;
173  }
174 
176  return optimizer_trajectory_data_;
177  }
178 
180  return &optimizer_trajectory_data_;
181  }
182 
183  const std::vector<common::TrajectoryPoint> &stitching_trajectory_data()
184  const {
185  return stitching_trajectory_data_;
186  }
187 
188  std::vector<common::TrajectoryPoint> *mutable_stitching_trajectory_data() {
189  return &stitching_trajectory_data_;
190  }
191 
193  return stitched_trajectory_result_;
194  }
195 
197  return &stitched_trajectory_result_;
198  }
199 
201  return open_space_provider_success_;
202  }
203 
204  void set_open_space_provider_success(const bool flag) {
205  open_space_provider_success_ = flag;
206  }
207 
208  bool destination_reached() const { return destination_reached_; }
209 
210  void set_destination_reached(const bool flag) { destination_reached_ = flag; }
211 
213  return interpolated_trajectory_result_;
214  }
215 
217  return &interpolated_trajectory_result_;
218  }
219 
220  const std::vector<TrajGearPair> &partitioned_trajectories() const {
221  // TODO(Runxin): export to chart
222  return partitioned_trajectories_;
223  }
224 
225  std::vector<TrajGearPair> *mutable_partitioned_trajectories() {
226  return &partitioned_trajectories_;
227  }
228 
230  return gear_switch_states_;
231  }
232 
234  return &gear_switch_states_;
235  }
236 
238  // TODO(Runxin): export to chart
239  return chosen_partitioned_trajectory_;
240  }
241 
243  return &chosen_partitioned_trajectory_;
244  }
245 
246  bool fallback_flag() const { return fallback_flag_; }
247 
248  void set_fallback_flag(const bool flag) { fallback_flag_ = flag; }
249 
250  TrajGearPair *mutable_fallback_trajectory() { return &fallback_trajectory_; }
251 
253  return fallback_trajectory_;
254  }
255 
256  void set_fallback_trajectory(const TrajGearPair &traj_gear_pair) {
257  fallback_trajectory_ = traj_gear_pair;
258  }
259 
260  std::pair<PublishableTrajectory, canbus::Chassis::GearPosition>
262  return &publishable_trajectory_data_;
263  }
264 
265  const std::pair<PublishableTrajectory, canbus::Chassis::GearPosition>
267  return publishable_trajectory_data_;
268  }
269 
270  // TODO(QiL, Jinyun) refactor and merge this with debug
271  common::TrajectoryPoint *mutable_future_collision_point() {
272  return &future_collision_point_;
273  }
274 
275  const common::TrajectoryPoint &future_collision_point() const {
276  return future_collision_point_;
277  }
278 
279  // TODO(QiL, Jinyun): refactor open_space_info vs debug
280 
281  apollo::planning_internal::Debug *mutable_debug() { return debug_; }
282 
283  void set_debug(apollo::planning_internal::Debug *debug) { debug_ = debug; }
284 
285  const apollo::planning_internal::Debug &debug() const { return *debug_; }
286 
287  const apollo::planning_internal::Debug debug_instance() const {
288  return debug_instance_;
289  }
290 
291  apollo::planning_internal::Debug *mutable_debug_instance() {
292  return &debug_instance_;
293  }
294 
296  // Remove existing obstacle vectors to prevent repeating obstacle
297  // vectors.
298  if (!debug_->planning_data().open_space().obstacles().empty()) {
299  debug_instance_.mutable_planning_data()
300  ->mutable_open_space()
301  ->clear_obstacles();
302  }
303  debug_instance_.MergeFrom(*debug_);
304  }
305 
306  void RecordDebug(apollo::planning_internal::Debug *ptr_debug);
307 
308  void set_time_latency(double time_latency) { time_latency_ = time_latency; }
309 
310  private:
311  std::string target_parking_spot_id_;
312 
313  hdmap::ParkingSpaceInfoConstPtr target_parking_spot_ = nullptr;
314 
315  hdmap::LaneInfoConstPtr target_parking_lane_ = nullptr;
316 
317  double open_space_pre_stop_fence_s_ = 0.0;
318 
319  bool pre_stop_rightaway_flag_ = false;
320 
321  hdmap::MapPathPoint pre_stop_rightaway_point_;
322 
323  bool is_on_open_space_trajectory_ = false;
324  // @brief obstacles total num including perception obstacles and parking space
325  // boundary
326  size_t obstacles_num_ = 0;
327 
328  // @brief the dimension needed for A and b matrix dimension in H
329  // representation
330  Eigen::MatrixXi obstacles_edges_num_;
331 
332  // @brief in the order of [x_min, x_max, y_min, y_max];
333  std::vector<double> ROI_xy_boundary_;
334 
335  // @brief open_space end configuration in order of x, y, heading and speed.
336  // Speed is set to be always zero now for parking
337  std::vector<double> open_space_end_pose_;
338 
339  // @brief vector storing the vertices of obstacles in counter-clock-wise order
340  std::vector<std::vector<common::math::Vec2d>> obstacles_vertices_vec_;
341 
342  // @brief Linear inequality representation of the obstacles Ax>b
343  Eigen::MatrixXd obstacles_A_;
344  Eigen::MatrixXd obstacles_b_;
345 
346  // @brief origin heading for planning space rotation
347  double origin_heading_ = 0.0;
348 
349  // @brief origin point for scaling down the numeric value of the optimization
350  // problem in order of x , y
351  common::math::Vec2d origin_point_;
352 
353  DiscretizedTrajectory optimizer_trajectory_data_;
354 
355  std::vector<common::TrajectoryPoint> stitching_trajectory_data_;
356 
357  DiscretizedTrajectory stitched_trajectory_result_;
358 
359  bool open_space_provider_success_ = false;
360 
361  bool destination_reached_ = false;
362 
363  DiscretizedTrajectory interpolated_trajectory_result_;
364 
365  std::vector<TrajGearPair> partitioned_trajectories_;
366 
367  GearSwitchStates gear_switch_states_;
368 
369  TrajGearPair chosen_partitioned_trajectory_;
370 
371  bool fallback_flag_ = true;
372 
373  TrajGearPair fallback_trajectory_;
374 
375  common::TrajectoryPoint future_collision_point_;
376 
377  std::pair<PublishableTrajectory, canbus::Chassis::GearPosition>
378  publishable_trajectory_data_;
379 
380  // the pointer from ADCtrajectory
381  apollo::planning_internal::Debug *debug_;
382 
383  // the instance inside debug,
384  // if ADCtrajectory is NULL, blank; else same to ADCtrajectory
385  apollo::planning_internal::Debug debug_instance_;
386 
387  double time_latency_ = 0.0;
388 };
389 
390 } // namespace planning
391 } // namespace apollo
std::string * mutable_target_parking_spot_id()
Definition: open_space_info.h:69
void set_fallback_trajectory(const TrajGearPair &traj_gear_pair)
Definition: open_space_info.h:256
void set_debug(apollo::planning_internal::Debug *debug)
Definition: open_space_info.h:283
const std::vector< common::TrajectoryPoint > & stitching_trajectory_data() const
Definition: open_space_info.h:183
const apollo::planning_internal::Debug debug_instance() const
Definition: open_space_info.h:287
bool pre_stop_rightaway_flag() const
Definition: open_space_info.h:97
apollo::canbus::Chassis::GearPosition gear_shift_position
Definition: open_space_info.h:56
Eigen::MatrixXd * mutable_obstacles_A()
Definition: open_space_info.h:145
bool open_space_provider_success() const
Definition: open_space_info.h:200
const Eigen::MatrixXd & obstacles_A() const
Definition: open_space_info.h:143
common::math::Vec2d * mutable_origin_point()
Definition: open_space_info.h:159
GearSwitchStates * mutable_gear_switch_states()
Definition: open_space_info.h:233
std::shared_ptr< const ParkingSpaceInfo > ParkingSpaceInfoConstPtr
Definition: hdmap_common.h:134
const Eigen::MatrixXd & obstacles_b() const
Definition: open_space_info.h:147
Defines the Vec2d class.
void set_open_space_provider_success(const bool flag)
Definition: open_space_info.h:204
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
const std::vector< TrajGearPair > & partitioned_trajectories() const
Definition: open_space_info.h:220
std::vector< TrajGearPair > * mutable_partitioned_trajectories()
Definition: open_space_info.h:225
std::pair< PublishableTrajectory, canbus::Chassis::GearPosition > * mutable_publishable_trajectory_data()
Definition: open_space_info.h:261
const std::string target_parking_spot_id() const
Definition: open_space_info.h:65
const Eigen::MatrixXi & obstacles_edges_num() const
Definition: open_space_info.h:125
Definition: discretized_trajectory.h:32
const std::vector< double > & open_space_end_pose() const
Definition: open_space_info.h:167
const DiscretizedTrajectory & interpolated_trajectory_result() const
Definition: open_space_info.h:212
bool is_on_open_space_trajectory() const
Definition: open_space_info.h:111
const common::TrajectoryPoint & future_collision_point() const
Definition: open_space_info.h:275
Planning module main class. It processes GPS and IMU as input, to generate planning info...
apollo::planning_internal::Debug * mutable_debug_instance()
Definition: open_space_info.h:291
std::pair< DiscretizedTrajectory, canbus::Chassis::GearPosition > TrajGearPair
Definition: open_space_info.h:48
DiscretizedTrajectory * mutable_stitched_trajectory_result()
Definition: open_space_info.h:196
void set_obstacles_num(const size_t obstacles_num)
Definition: open_space_info.h:121
std::vector< common::TrajectoryPoint > * mutable_stitching_trajectory_data()
Definition: open_space_info.h:188
Definition: path.h:103
std::vector< std::vector< common::math::Vec2d > > * mutable_obstacles_vertices_vec()
Definition: open_space_info.h:139
Definition: open_space_info.h:50
void sync_debug_instance()
Definition: open_space_info.h:295
const TrajGearPair & chosen_partitioned_trajectory() const
Definition: open_space_info.h:237
double gear_shift_start_time
Definition: open_space_info.h:55
void set_target_parking_lane(hdmap::LaneInfoConstPtr lane_info_const_ptr)
Definition: open_space_info.h:85
const std::vector< std::vector< common::math::Vec2d > > & obstacles_vertices_vec() const
Definition: open_space_info.h:133
Eigen::MatrixXi * mutable_obstacles_edges_num()
Definition: open_space_info.h:129
common::TrajectoryPoint * mutable_future_collision_point()
Definition: open_space_info.h:271
const std::vector< double > & ROI_xy_boundary() const
Definition: open_space_info.h:161
bool gear_shift_period_finished
Definition: open_space_info.h:52
size_t obstacles_num() const
Definition: open_space_info.h:119
bool fallback_flag() const
Definition: open_space_info.h:246
const hdmap::LaneInfoConstPtr target_parking_lane() const
Definition: open_space_info.h:81
const hdmap::MapPathPoint & pre_stop_rightaway_point() const
Definition: open_space_info.h:103
apollo::planning_internal::Debug * mutable_debug()
Definition: open_space_info.h:281
Implements a class of 2-dimensional vectors.
Definition: vec2d.h:42
DiscretizedTrajectory * mutable_optimizer_trajectory_data()
Definition: open_space_info.h:179
Definition: open_space_info.h:60
const DiscretizedTrajectory & stitched_trajectory_result() const
Definition: open_space_info.h:192
void set_open_space_pre_stop_fence_s(const double s)
Definition: open_space_info.h:93
TrajGearPair * mutable_fallback_trajectory()
Definition: open_space_info.h:250
const DiscretizedTrajectory & optimizer_trajectory_data() const
Definition: open_space_info.h:175
double gear_shift_period_time
Definition: open_space_info.h:54
const common::math::Vec2d & origin_point() const
Definition: open_space_info.h:157
std::shared_ptr< const LaneInfo > LaneInfoConstPtr
Definition: hdmap_common.h:125
const hdmap::ParkingSpaceInfoConstPtr target_parking_spot() const
Definition: open_space_info.h:73
Eigen::MatrixXd * mutable_obstacles_b()
Definition: open_space_info.h:149
void set_destination_reached(const bool flag)
Definition: open_space_info.h:210
void set_origin_heading(const double original_heading)
Definition: open_space_info.h:153
const TrajGearPair & fallback_trajectory() const
Definition: open_space_info.h:252
void set_is_on_open_space_trajectory(const bool flag)
Definition: open_space_info.h:115
TrajGearPair * mutable_chosen_partitioned_trajectory()
Definition: open_space_info.h:242
void set_fallback_flag(const bool flag)
Definition: open_space_info.h:248
hdmap::MapPathPoint * mutable_pre_stop_rightaway_point()
Definition: open_space_info.h:107
const GearSwitchStates & gear_switch_states() const
Definition: open_space_info.h:229
hdmap::ParkingSpaceInfoConstPtr * mutable_target_parking_spot()
Definition: open_space_info.h:77
bool gear_switching_flag
Definition: open_space_info.h:51
void set_pre_stop_rightaway_flag(const bool flag)
Definition: open_space_info.h:99
void set_time_latency(double time_latency)
Definition: open_space_info.h:308
double open_space_pre_stop_fence_s() const
Definition: open_space_info.h:89
double origin_heading() const
Definition: open_space_info.h:151
bool destination_reached() const
Definition: open_space_info.h:208
std::vector< double > * mutable_ROI_xy_boundary()
Definition: open_space_info.h:165
const std::pair< PublishableTrajectory, canbus::Chassis::GearPosition > & publishable_trajectory_data() const
Definition: open_space_info.h:266
const apollo::planning_internal::Debug & debug() const
Definition: open_space_info.h:285
std::vector< double > * mutable_open_space_end_pose()
Definition: open_space_info.h:171
bool gear_shift_period_started
Definition: open_space_info.h:53
DiscretizedTrajectory * mutable_interpolated_trajectory_result()
Definition: open_space_info.h:216