Apollo 11.0
自动驾驶开放平台
apollo::planning::TrafficLightUnprotectedLeftTurnScenario类 参考

#include <traffic_light_unprotected_left_turn_scenario.h>

类 apollo::planning::TrafficLightUnprotectedLeftTurnScenario 继承关系图:
apollo::planning::TrafficLightUnprotectedLeftTurnScenario 的协作图:

Public 成员函数

bool Init (std::shared_ptr< DependencyInjector > injector, const std::string &name) override
 
TrafficLightUnprotectedLeftTurnContext * GetContext () override
 Get the scenario context.
 
bool IsTransferable (const Scenario *const other_scenario, const Frame &frame) override
 Each scenario should define its own transfer condition, i.e., when it should allow to transfer from other scenario to itself.
 
bool Exit (Frame *frame) override
 
bool Enter (Frame *frame) override
 
- Public 成员函数 继承自 apollo::planning::Scenario
 Scenario ()
 
virtual ~Scenario ()=default
 
virtual ScenarioResult Process (const common::TrajectoryPoint &planning_init_point, Frame *frame)
 
std::shared_ptr< Stage > CreateStage (const StagePipeline &stage_pipeline)
 Each scenario should define its own stages object's creation scenario will call stage's Stage::Process function following a configured order, The return value of Stage::Process function determines the transition from one stage to another.
 
const ScenarioStatusType & GetStatus () const
 
const std::string GetStage () const
 
const std::string & GetMsg () const
 
const std::string & Name () const
 
void Reset ()
 Reset the scenario, used before entering the scenario.
 

额外继承的成员函数

- Protected 成员函数 继承自 apollo::planning::Scenario
template<typename T >
bool LoadConfig (T *config)
 
- Protected 属性 继承自 apollo::planning::Scenario
ScenarioResult scenario_result_
 
std::shared_ptr< Stage > current_stage_
 
std::unordered_map< std::string, const StagePipeline * > stage_pipeline_map_
 
std::string msg_
 
std::shared_ptr< DependencyInjector > injector_
 
std::string config_path_
 
std::string config_dir_
 
std::string name_
 
ScenarioPipeline scenario_pipeline_config_
 

详细描述

成员函数说明

◆ Enter()

bool apollo::planning::TrafficLightUnprotectedLeftTurnScenario::Enter ( Frame *  frame)
overridevirtual

重载 apollo::planning::Scenario .

在文件 traffic_light_unprotected_left_turn_scenario.cc 第 152 行定义.

152 {
153 const auto& reference_line_info = frame->reference_line_info().front();
154 std::string current_traffic_light_overlap_id;
155 const auto& overlaps = reference_line_info.FirstEncounteredOverlaps();
156 for (auto overlap : overlaps) {
157 if (overlap.first == ReferenceLineInfo::SIGNAL) {
158 current_traffic_light_overlap_id = overlap.second.object_id;
159 break;
160 }
161 }
162
163 if (current_traffic_light_overlap_id.empty()) {
164 injector_->planning_context()
165 ->mutable_planning_status()
166 ->mutable_traffic_light()
167 ->Clear();
168 AERROR << "Can not find traffic light overlap in reference line!";
169 return false;
170 }
171
172 // find all the traffic light at/within the same location/group
173 const std::vector<apollo::hdmap::PathOverlap>& traffic_light_overlaps =
174 reference_line_info.reference_line().map_path().signal_overlaps();
175 auto traffic_light_overlap_itr = std::find_if(
176 traffic_light_overlaps.begin(), traffic_light_overlaps.end(),
177 [&current_traffic_light_overlap_id](const hdmap::PathOverlap& overlap) {
178 return overlap.object_id == current_traffic_light_overlap_id;
179 });
180 if (traffic_light_overlap_itr == traffic_light_overlaps.end()) {
181 injector_->planning_context()
182 ->mutable_planning_status()
183 ->mutable_traffic_light()
184 ->Clear();
185 return true;
186 }
187
188 static constexpr double kTrafficLightGroupingMaxDist = 2.0; // unit: m
189 const double current_traffic_light_overlap_start_s =
190 traffic_light_overlap_itr->start_s;
191 for (const auto& traffic_light_overlap : traffic_light_overlaps) {
192 const double dist =
193 traffic_light_overlap.start_s - current_traffic_light_overlap_start_s;
194 if (fabs(dist) <= kTrafficLightGroupingMaxDist) {
195 injector_->planning_context()
196 ->mutable_planning_status()
197 ->mutable_traffic_light()
198 ->add_current_traffic_light_overlap_id(
199 traffic_light_overlap.object_id);
200 ADEBUG << "Update PlanningContext with first_encountered traffic_light["
201 << traffic_light_overlap.object_id << "] start_s["
202 << traffic_light_overlap.start_s << "]";
203 }
204 }
205 return true;
206}
std::shared_ptr< DependencyInjector > injector_
Definition scenario.h:113
#define ADEBUG
Definition log.h:41
#define AERROR
Definition log.h:44

◆ Exit()

bool apollo::planning::TrafficLightUnprotectedLeftTurnScenario::Exit ( Frame *  frame)
overridevirtual

重载 apollo::planning::Scenario .

在文件 traffic_light_unprotected_left_turn_scenario.cc 第 144 行定义.

144 {
145 injector_->planning_context()
146 ->mutable_planning_status()
147 ->mutable_traffic_light()
148 ->Clear();
149 return true;
150}

◆ GetContext()

TrafficLightUnprotectedLeftTurnContext * apollo::planning::TrafficLightUnprotectedLeftTurnScenario::GetContext ( )
inlineoverridevirtual

Get the scenario context.

实现了 apollo::planning::Scenario.

在文件 traffic_light_unprotected_left_turn_scenario.h 第 42 行定义.

42 {
43 return &context_;
44 }

◆ Init()

bool apollo::planning::TrafficLightUnprotectedLeftTurnScenario::Init ( std::shared_ptr< DependencyInjector >  injector,
const std::string &  name 
)
overridevirtual

重载 apollo::planning::Scenario .

在文件 traffic_light_unprotected_left_turn_scenario.cc 第 40 行定义.

41 {
42 if (init_) {
43 return true;
44 }
45
46 if (!Scenario::Init(injector, name)) {
47 AERROR << "failed to init scenario" << Name();
48 return false;
49 }
50
51 if (!Scenario::LoadConfig<ScenarioTrafficLightUnprotectedLeftTurnConfig>(
52 &context_.scenario_config)) {
53 AERROR << "fail to get specific config of scenario " << Name();
54 return false;
55 }
56 init_ = true;
57 return true;
58}
virtual bool Init(std::shared_ptr< DependencyInjector > injector, const std::string &name)
Definition scenario.cc:43
const std::string & Name() const
Definition scenario.h:98
ScenarioTrafficLightUnprotectedLeftTurnConfig scenario_config
Definition context.h:32

◆ IsTransferable()

bool apollo::planning::TrafficLightUnprotectedLeftTurnScenario::IsTransferable ( const Scenario *const  other_scenario,
const Frame &  frame 
)
overridevirtual

Each scenario should define its own transfer condition, i.e., when it should allow to transfer from other scenario to itself.

重载 apollo::planning::Scenario .

在文件 traffic_light_unprotected_left_turn_scenario.cc 第 60 行定义.

61 {
62 if (!frame.local_view().planning_command->has_lane_follow_command()) {
63 return false;
64 }
65 if (other_scenario == nullptr || frame.reference_line_info().empty()) {
66 return false;
67 }
68 const auto& reference_line_info = frame.reference_line_info().front();
69 const auto& first_encountered_overlaps =
70 reference_line_info.FirstEncounteredOverlaps();
71 if (first_encountered_overlaps.empty()) {
72 return false;
73 }
74 hdmap::PathOverlap* traffic_sign_overlap = nullptr;
75 for (const auto& overlap : first_encountered_overlaps) {
76 if (overlap.first == ReferenceLineInfo::STOP_SIGN ||
77 overlap.first == ReferenceLineInfo::YIELD_SIGN) {
78 return false;
79 } else if (overlap.first == ReferenceLineInfo::SIGNAL) {
80 traffic_sign_overlap = const_cast<hdmap::PathOverlap*>(&overlap.second);
81 break;
82 }
83 }
84 if (traffic_sign_overlap == nullptr) {
85 return false;
86 }
87 const std::vector<hdmap::PathOverlap>& traffic_light_overlaps =
88 reference_line_info.reference_line().map_path().signal_overlaps();
89 const double start_check_distance =
91 const double adc_front_edge_s = reference_line_info.AdcSlBoundary().end_s();
92 // find all the traffic light belong to
93 // the same group as first encountered traffic light
94 std::vector<hdmap::PathOverlap> next_traffic_lights;
95 static constexpr double kTrafficLightGroupingMaxDist = 2.0; // unit: m
96 for (const auto& overlap : traffic_light_overlaps) {
97 const double dist = overlap.start_s - traffic_sign_overlap->start_s;
98 if (fabs(dist) <= kTrafficLightGroupingMaxDist) {
99 next_traffic_lights.push_back(overlap);
100 }
101 }
102 bool traffic_light_scenario = false;
103 // note: need iterate all lights to check no RED/YELLOW/UNKNOWN
104 for (const auto& overlap : next_traffic_lights) {
105 const double adc_distance_to_traffic_light =
106 overlap.start_s - adc_front_edge_s;
107 ADEBUG << "traffic_light[" << overlap.object_id << "] start_s["
108 << overlap.start_s << "] adc_distance_to_traffic_light["
109 << adc_distance_to_traffic_light << "]";
110
111 // enter traffic-light scenarios: based on distance only
112 if (adc_distance_to_traffic_light <= 0.0 ||
113 adc_distance_to_traffic_light > start_check_distance) {
114 continue;
115 }
116
117 const auto& signal_color = frame.GetSignal(overlap.object_id).color();
118 ADEBUG << "traffic_light_id[" << overlap.object_id << "] start_s["
119 << overlap.start_s << "] color[" << signal_color << "]";
120
121 if (signal_color != perception::TrafficLight::GREEN &&
122 signal_color != perception::TrafficLight::BLACK) {
123 traffic_light_scenario = true;
124 break;
125 }
126 }
127 if (!traffic_light_scenario) {
128 return false;
129 }
130
131 const auto& turn_type =
132 reference_line_info.GetPathTurnType(traffic_sign_overlap->start_s);
133 if (turn_type != hdmap::Lane::LEFT_TURN) {
134 return false;
135 }
136 context_.current_traffic_light_overlap_ids.clear();
137 for (const auto& overlap : next_traffic_lights) {
138 context_.current_traffic_light_overlap_ids.push_back(overlap.object_id);
139 }
140
141 return true;
142}
std::vector< std::string > current_traffic_light_overlap_ids
Definition context.h:33

该类的文档由以下文件生成: