51 const std::shared_ptr<::apollo::hdmap::HDMap> &hdmap,
double distance,
56 if (!msg->has_gps_x_m() || !msg->has_gps_y_m()) {
57 AERROR <<
"Error::v2x traffic_light ignore, gps point is null";
63 if (0 == msg->single_traffic_light_size()) {
64 AERROR <<
"Error::v2x traffic_light ignore, size of single light is 0.";
71 double dummy_s = 0, dummy_l = 0;
72 if (0 != hdmap->GetNearestLane(point, &laneinfo, &dummy_s, &dummy_l)) {
75 std::vector<::apollo::hdmap::SignalInfoConstPtr> signals;
76 if (0 != hdmap->GetForwardNearestSignalsOnLane(point, distance, &signals)) {
77 AERROR <<
"Error::v2x traffic_light ignore, hdmap get no signals."
78 <<
"traffic light size : " << signals.size() <<
" "
79 << std::setiosflags(std::ios::fixed) << std::setprecision(11)
80 <<
"Point:x=" << point.
x() <<
",y=" << point.
y();
83 if (signals.empty()) {
84 AERROR <<
"Get traffic light size : " << signals.size() <<
" "
85 << std::setiosflags(std::ios::fixed) << std::setprecision(11)
86 <<
"Point:x=" << point.
x() <<
",y=" << point.
y();
89 AINFO <<
"the size of traffic light from HDMap is: " << signals.size();
94 auto next_remaining_time =
96 msg->clear_single_traffic_light();
97 for (
size_t i = 0; i < signals.size(); i++) {
98 auto signal_info = signals[i];
99 auto single = msg->add_single_traffic_light();
100 single->set_id(signal_info->id().id());
101 single->add_traffic_light_type(tl_type);
102 single->set_color(color);
103 single->set_color_remaining_time_s(remaining_time);
104 single->set_next_color(next_color);
105 single->set_next_remaining_time_s(next_remaining_time);
118 const std::shared_ptr<::apollo::hdmap::HDMap> &hdmap,
119 const ObuLight *x2v_traffic_light,
const std::string &junction_id,
120 bool flag_u_turn,
double distance,
double check_time,
121 std::shared_ptr<OSLight> *os_light) {
122 if (
nullptr == os_light) {
125 if (
nullptr == *os_light) {
128 if (!x2v_traffic_light) {
135 AWARN <<
"current junction id " << junction_id
136 <<
", received the junction id "
140 std::shared_ptr<OSLight> os_traffic_light =
nullptr;
144 int num_os_traffic_light = os_traffic_light->road_traffic_light_size();
145 if (0 == num_os_traffic_light) {
146 AERROR <<
"Ignored no traffic light contained after conventor.";
149 std::shared_ptr<OSLight> sim_traffic_light_data =
nullptr;
152 auto tmp_os_traffic_light = std::make_shared<OSLight>();
153 tmp_os_traffic_light->CopyFrom(*os_traffic_light);
155 tmp_os_traffic_light->clear_road_traffic_light();
156 for (
int i = 0; i < num_os_traffic_light; i++) {
157 auto os_current_light = os_traffic_light->mutable_road_traffic_light(i);
159 AERROR <<
"Traffic light proc failed";
162 if (os_current_light->single_traffic_light_size() > 0) {
163 auto tmp_os_current_light =
164 tmp_os_traffic_light->add_road_traffic_light();
165 tmp_os_current_light->CopyFrom(*(os_current_light));
168 tmp_os_traffic_light->set_confidence(
IsRushHour() ? 0.5 : 1.0);
169 AINFO <<
"all traffic light send to os BEFORE is: "
170 << os_traffic_light->DebugString();
171 if (0 == tmp_os_traffic_light->road_traffic_light_size()) {
175 tmp_os_traffic_light->set_intersection_id(cur_junction_id);
177 if (cur_junction_id != intersection_id_) {
178 AINFO <<
"Enter New Juncion: " << cur_junction_id;
180 intersection_id_ = cur_junction_id;
181 int num_traffic_light = tmp_os_traffic_light->road_traffic_light_size();
182 for (
int i = 0; i < num_traffic_light; i++) {
183 auto remaining_time = tmp_os_traffic_light->road_traffic_light(i)
184 .single_traffic_light(0)
185 .color_remaining_time_s();
186 remaining_time_[i] = remaining_time;
190 ADEBUG <<
"Same Juncion: " << cur_junction_id;
192 for (
unsigned int i = 0; i < kBufferSize; i++) {
193 msg_timestamp_[i] = 0.0;
194 remaining_time_[i] = -1;
198 int num_traffic_light = tmp_os_traffic_light->road_traffic_light_size();
199 for (
int i = 0; i < num_traffic_light; i++) {
200 auto remaining_time = tmp_os_traffic_light->road_traffic_light(i)
201 .single_traffic_light(0)
202 .color_remaining_time_s();
203 if ((remaining_time_[i] != remaining_time)) {
204 remaining_time_[i] = remaining_time;
209 int road_valid_size =
210 std::min(oslight_->road_traffic_light_size(),
211 tmp_os_traffic_light->road_traffic_light_size());
212 for (
int i = 0; i < road_valid_size; i++) {
213 const auto &last_msg_road = oslight_->road_traffic_light(i);
214 auto current_msg_road =
215 tmp_os_traffic_light->mutable_road_traffic_light(i);
216 int single_valid_size =
217 std::min(last_msg_road.single_traffic_light_size(),
218 current_msg_road->single_traffic_light_size());
219 for (
int j = 0; j < single_valid_size; j++) {
220 const auto &last_msg_single_traffic_light =
221 last_msg_road.single_traffic_light(j);
222 auto current_msg_single_traffic_light =
223 current_msg_road->mutable_single_traffic_light(j);
224 if (last_msg_single_traffic_light.color() ==
225 current_msg_single_traffic_light->color()) {
226 if (current_msg_single_traffic_light->color_remaining_time_s() >
227 last_msg_single_traffic_light.color_remaining_time_s()) {
228 AINFO <<
"correct the remaining time";
229 current_msg_single_traffic_light->set_color_remaining_time_s(
230 last_msg_single_traffic_light.color_remaining_time_s());
237 oslight_ = std::make_shared<::apollo::v2x::IntersectionTrafficLightData>();
238 oslight_->CopyFrom(*tmp_os_traffic_light);
239 (*os_light)->CopyFrom(*tmp_os_traffic_light);
244 const ::apollo::planning::ADCTrajectory *planning_msg,
246 std::shared_ptr<::apollo::perception::TrafficLightDetection> *res_light) {
247 if (!planning_msg || !res_light || !(*res_light)) {
251 (*res_light)->mutable_header();
252 if (!planning_msg->has_debug() ||
253 !planning_msg->debug().has_planning_data()) {
256 const auto &planning_debug = planning_msg->debug().planning_data();
257 if (!planning_debug.has_signal_light() ||
258 0 == planning_debug.signal_light().signal_size()) {
261 const std::string light_id =
262 planning_debug.signal_light().signal(0).light_id();
263 if (!last_os_light || light_id.empty()) {
268 for (
int idx = 0; idx < last_os_light->road_traffic_light_size(); idx++) {
270 if (0 == road_tl.single_traffic_light_size()) {
273 if (road_tl.single_traffic_light(0).id() == light_id) {
280 AWARN <<
"Failed to find light_id from os_light: " << light_id
284 (*res_light)->clear_traffic_light();
285 auto res_frame_id = std::to_string(last_os_light->has_intersection_id()
288 (*res_light)->mutable_header()->set_frame_id(res_frame_id);
289 AINFO <<
"Selected road attr: " << ::apollo::common::Direction_Name(attr);
290 std::set<std::string> idset;
291 for (
int idx = 0; idx < last_os_light->road_traffic_light_size(); idx++) {
293 if (0 == road_tl.single_traffic_light_size()) {
296 if (road_tl.road_attribute() != attr) {
300 if (single_tl.traffic_light_type_size() < 1) {
303 auto *light1 = (*res_light)->add_traffic_light();
306 light1->set_id(SingleTrafficLight_Type_Name(
307 single_tl.traffic_light_type(0)));
308 idset.emplace(single_tl.id());
310 if (single_tl.has_color()) {
311 switch (single_tl.color()) {
312 case OSLightColor::SingleTrafficLight_Color_RED:
314 ::apollo::perception::TrafficLight_Color::TrafficLight_Color_RED);
316 case OSLightColor::SingleTrafficLight_Color_YELLOW:
317 light1->set_color(::apollo::perception::TrafficLight_Color::
318 TrafficLight_Color_YELLOW);
320 case OSLightColor::SingleTrafficLight_Color_GREEN:
321 case OSLightColor::SingleTrafficLight_Color_FLASH_GREEN:
322 light1->set_color(::apollo::perception::TrafficLight_Color::
323 TrafficLight_Color_GREEN);
325 case OSLightColor::SingleTrafficLight_Color_BLACK:
326 light1->set_color(::apollo::perception::TrafficLight_Color::
327 TrafficLight_Color_BLACK);
330 light1->set_color(::apollo::perception::TrafficLight_Color::
331 TrafficLight_Color_UNKNOWN);
336 if (single_tl.has_color_remaining_time_s()) {
337 light1->set_remaining_time(single_tl.color_remaining_time_s());