38 const std::shared_ptr<DependencyInjector>& injector,
39 const std::string& config_dir,
41 CHECK_NOTNULL(context);
42 bool ret =
Stage::Init(config, injector, config_dir, context);
47 scenario_config_.CopyFrom(GetContextAs<SquareContext>()->scenario_config);
52 AINFO <<
"In ExtricateStage";
57 static constexpr double gear_shift_max_t = 5.0;
58 static constexpr double gear_shift_unit_t = 0.1;
59 for (
double t = 0.0; t < gear_shift_max_t; t += gear_shift_unit_t) {
64 point.mutable_path_point()->set_s(0.0);
65 point.mutable_path_point()->set_kappa(0);
66 point.set_relative_time(t);
69 traj_pair->first.emplace_back(point);
72 AINFO <<
"GENERATE REVERSE TRAJECTORY";
73 need_to_stop_ =
false;
76 AINFO <<
"gear is reverse";
78 const auto& reference_line = reference_line_info.reference_line();
79 double adc_start_s = reference_line_info.AdcSlBoundary().start_s();
82 if (stop_point_ ==
nullptr) {
84 auto ref_point = reference_line.GetReferencePoint(adc_start_s - 10.0);
85 stop_point_ = std::make_shared<common::PathPoint>(ref_point.ToPathPoint(0.0));
87 AINFO <<
"need to stop";
89 reference_line.XYToSL(*stop_point_, &sl_point);
90 std::vector<std::string> wait_for_obstacles;
95 StopReasonCode::STOP_REASON_STOP_SIGN,
101 const auto& candidate_paths = reference_line_info.GetCandidatePathData();
102 bool has_regular_path =
false;
103 for (
const auto& path_data : candidate_paths) {
104 if (path_data.path_label().find(
"regular") != std::string::npos && path_data.blocking_obstacle_id().empty()) {
105 AINFO <<
"find regular path: " << path_data.path_label();
106 has_regular_path =
true;
110 if (has_regular_path) {
111 success_path_times_++;
113 success_path_times_ = 0;
114 need_to_stop_ =
false;
116 if (success_path_times_ > 10 && !need_to_stop_) {
117 AINFO <<
"find square path change stage";
118 need_to_stop_ =
true;
119 *stop_point_ = reference_line_info.mutable_path_data()->discretized_path().Evaluate(5.0);
120 AINFO <<
"stop_point_:" << stop_point_->x() <<
"," << stop_point_->y();
122 if (success_path_times_ > 10 && std::fabs(vehicle_state.
linear_velocity()) < 0.1) {
123 AINFO <<
"already stopped change stage" << vehicle_state.
linear_velocity() <<
" " << vehicle_state.
x() <<
", "
124 << vehicle_state.
y();
125 return FinishStage();
132 success_path_times_ = 0;
133 need_to_stop_ =
false;
140 for (
const auto& obstacle : obstacles_by_frame->Items()) {
141 if (adc_polygon.
HasOverlap(obstacle->PerceptionPolygon())) {
150 std::vector<common::PathPoint> path_points;
151 static constexpr double kReversePathLength = 10.0;
152 static constexpr double kReversePathUnit = 0.5;
153 for (
double s = 0; s <= kReversePathLength; s += kReversePathUnit) {
159 point.set_kappa(0.0);
160 point.set_dkappa(0.0);
161 point.set_ddkappa(0.0);
162 path.emplace_back(point);
A general class to denote the return status of an API call.
Rectangular (undirected) bounding box in 2-D.
The class of polygon in 2-D.
bool HasOverlap(const LineSegment2d &line_segment) const
Check if a line segment has overlap with this polygon.
Implements a class of 2-dimensional vectors.
StageResult Process(const common::TrajectoryPoint &planning_init_point, Frame *frame) override
Each stage does its business logic inside Process function.
bool GenerateStraightReversePath(PathData *path_data, const common::TrajectoryPoint &init_point)
bool HasCollision(Frame *frame, const common::math::Box2d &adc_box)
bool Init(const StagePipeline &config, const std::shared_ptr< DependencyInjector > &injector, const std::string &config_dir, void *context)
Frame holds all data for one planning cycle.
const common::VehicleState & vehicle_state() const
OpenSpaceInfo * mutable_open_space_info()
ThreadSafeIndexedObstacles * GetObstacleList()
std::list< ReferenceLineInfo > * mutable_reference_line_info()
void set_is_on_open_space_trajectory(const bool flag)
std::pair< PublishableTrajectory, canbus::Chassis::GearPosition > * mutable_publishable_trajectory_data()
bool SetDiscretizedPath(DiscretizedPath path)
void set_is_reverse_path(bool is_reverse_path)
void set_path_label(const std::string &label)
const StageResult & SetStageStatus(const StageStatusType &stage_status)
Set the stage status.
virtual bool Init(const StagePipeline &config, const std::shared_ptr< DependencyInjector > &injector, const std::string &config_dir, void *context)
std::shared_ptr< DependencyInjector > injector_
StageResult ExecuteTaskOnReferenceLine(const common::TrajectoryPoint &planning_start_point, Frame *frame)
const std::string & Name() const
Planning module main class.
int BuildStopDecision(const std::string &stop_wall_id, const double stop_line_s, const double stop_distance, const StopReasonCode &stop_reason_code, const std::vector< std::string > &wait_for_obstacles, const std::string &decision_tag, Frame *const frame, ReferenceLineInfo *const reference_line_info, double stop_wall_width)
optional PathPoint path_point
optional double linear_velocity
optional apollo::canbus::Chassis::GearPosition gear