@@ -801,6 +801,9 @@ MapBasedPredictionNode::MapBasedPredictionNode(const rclcpp::NodeOptions & node_
801
801
sub_map_ = this ->create_subscription <HADMapBin>(
802
802
" /vector_map" , rclcpp::QoS{1 }.transient_local (),
803
803
std::bind (&MapBasedPredictionNode::mapCallback, this , std::placeholders::_1));
804
+ sub_traffic_signals_ = this ->create_subscription <TrafficSignalArray>(
805
+ " /traffic_signals" , 1 ,
806
+ std::bind (&MapBasedPredictionNode::trafficSignalsCallback, this , std::placeholders::_1));
804
807
805
808
pub_objects_ = this ->create_publisher <PredictedObjects>(" ~/output/objects" , rclcpp::QoS{1 });
806
809
pub_debug_markers_ =
@@ -872,6 +875,14 @@ void MapBasedPredictionNode::mapCallback(const HADMapBin::ConstSharedPtr msg)
872
875
crosswalks_.insert (crosswalks_.end (), walkways.begin (), walkways.end ());
873
876
}
874
877
878
+ void MapBasedPredictionNode::trafficSignalsCallback (const TrafficSignalArray::ConstSharedPtr msg)
879
+ {
880
+ traffic_signal_id_map.clear ();
881
+ for (const auto & signal : msg->signals ) {
882
+ traffic_signal_id_map[signal .traffic_signal_id ] = signal ;
883
+ }
884
+ }
885
+
875
886
void MapBasedPredictionNode::objectsCallback (const TrackedObjects::ConstSharedPtr in_objects)
876
887
{
877
888
stop_watch_.tic ();
@@ -1218,6 +1229,23 @@ PredictedObject MapBasedPredictionNode::getPredictedObjectAsCrosswalkUser(
1218
1229
}
1219
1230
// try to find the edge points for all crosswalks and generate path to the crosswalk edge
1220
1231
for (const auto & crosswalk : crosswalks_) {
1232
+ const auto crosswalk_signal_id_opt = getTrafficSignalId (crosswalk);
1233
+ if (crosswalk_signal_id_opt.has_value ()) {
1234
+ // If the crosswalk has traffic light, do something.
1235
+ if (traffic_signal_id_map.count (crosswalk_signal_id_opt.value ()) != 0 ) {
1236
+ const auto & signal_elements =
1237
+ traffic_signal_id_map.at (crosswalk_signal_id_opt.value ()).elements ;
1238
+ if (signal_elements.size () > 1 ) {
1239
+ RCLCPP_ERROR (
1240
+ get_logger (), " [Map Based Prediction]: Multiple TrafficSignalElement_ are recieved." );
1241
+ } else if (
1242
+ !signal_elements.empty () && signal_elements.front ().color == TrafficSignalElement::RED) {
1243
+ continue ;
1244
+ }
1245
+ }
1246
+ // TODO(yuki takagi): If a flag is setted, wait for timeout while the pedestrian is stopping.
1247
+ }
1248
+
1221
1249
const auto edge_points = getCrosswalkEdgePoints (crosswalk);
1222
1250
1223
1251
const auto reachable_first = hasPotentialToReach (
@@ -2211,6 +2239,24 @@ bool MapBasedPredictionNode::isDuplicated(
2211
2239
2212
2240
return false ;
2213
2241
}
2242
+
2243
+ std::optional<lanelet::Id> MapBasedPredictionNode::getTrafficSignalId (
2244
+ const lanelet::ConstLanelet & way_lanelet)
2245
+ {
2246
+ const auto traffic_light_reg_elems =
2247
+ way_lanelet.regulatoryElementsAs <const lanelet::TrafficLight>();
2248
+ if (traffic_light_reg_elems.empty ()) {
2249
+ return std::nullopt;
2250
+ } else if (traffic_light_reg_elems.size () > 1 ) {
2251
+ RCLCPP_ERROR (
2252
+ get_logger (),
2253
+ " [Map Based Prediction]: "
2254
+ " Multiple regulatory elements as TrafficLight are defined to one lanelet object." );
2255
+ return std::nullopt; // Is it appropriate?
2256
+ }
2257
+ return traffic_light_reg_elems.front ()->id ();
2258
+ }
2259
+
2214
2260
} // namespace map_based_prediction
2215
2261
2216
2262
#include < rclcpp_components/register_node_macro.hpp>
0 commit comments