Skip to content

Commit 56cf8f6

Browse files
consider the crosswalks signals
Signed-off-by: Yuki Takagi <yuki.takagi@tier4.jp>
1 parent f0b8555 commit 56cf8f6

File tree

4 files changed

+59
-0
lines changed

4 files changed

+59
-0
lines changed

perception/map_based_prediction/include/map_based_prediction/map_based_prediction_node.hpp

+10
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <autoware_auto_mapping_msgs/msg/had_map_bin.hpp>
3030
#include <autoware_auto_perception_msgs/msg/predicted_objects.hpp>
3131
#include <autoware_auto_perception_msgs/msg/tracked_objects.hpp>
32+
#include <autoware_perception_msgs/msg/traffic_signal_array.hpp>
3233
#include <geometry_msgs/msg/pose.hpp>
3334
#include <geometry_msgs/msg/pose_stamped.hpp>
3435
#include <geometry_msgs/msg/twist.hpp>
@@ -42,6 +43,7 @@
4243
#include <algorithm>
4344
#include <deque>
4445
#include <memory>
46+
#include <optional>
4547
#include <string>
4648
#include <unordered_map>
4749
#include <utility>
@@ -107,6 +109,9 @@ using autoware_auto_perception_msgs::msg::TrackedObject;
107109
using autoware_auto_perception_msgs::msg::TrackedObjectKinematics;
108110
using autoware_auto_perception_msgs::msg::TrackedObjects;
109111
using autoware_auto_planning_msgs::msg::TrajectoryPoint;
112+
using autoware_perception_msgs::msg::TrafficSignal;
113+
using autoware_perception_msgs::msg::TrafficSignalArray;
114+
using autoware_perception_msgs::msg::TrafficSignalElement;
110115
using tier4_autoware_utils::StopWatch;
111116
using tier4_debug_msgs::msg::StringStamped;
112117
using TrajectoryPoints = std::vector<TrajectoryPoint>;
@@ -122,6 +127,7 @@ class MapBasedPredictionNode : public rclcpp::Node
122127
rclcpp::Publisher<StringStamped>::SharedPtr pub_calculation_time_;
123128
rclcpp::Subscription<TrackedObjects>::SharedPtr sub_objects_;
124129
rclcpp::Subscription<HADMapBin>::SharedPtr sub_map_;
130+
rclcpp::Subscription<TrafficSignalArray>::SharedPtr sub_traffic_signals_;
125131

126132
// Object History
127133
std::unordered_map<std::string, std::deque<ObjectData>> objects_history_;
@@ -131,6 +137,8 @@ class MapBasedPredictionNode : public rclcpp::Node
131137
std::shared_ptr<lanelet::routing::RoutingGraph> routing_graph_ptr_;
132138
std::shared_ptr<lanelet::traffic_rules::TrafficRules> traffic_rules_ptr_;
133139

140+
std::unordered_map<lanelet::Id, TrafficSignal> traffic_signal_id_map;
141+
134142
// parameter update
135143
OnSetParametersCallbackHandle::SharedPtr set_param_res_;
136144
rcl_interfaces::msg::SetParametersResult onParam(
@@ -186,6 +194,7 @@ class MapBasedPredictionNode : public rclcpp::Node
186194

187195
// Member Functions
188196
void mapCallback(const HADMapBin::ConstSharedPtr msg);
197+
void trafficSignalsCallback(const TrafficSignalArray::ConstSharedPtr msg);
189198
void objectsCallback(const TrackedObjects::ConstSharedPtr in_objects);
190199

191200
bool doesPathCrossAnyFence(const PredictedPath & predicted_path);
@@ -249,6 +258,7 @@ class MapBasedPredictionNode : public rclcpp::Node
249258
const LaneletsData & lanelets_data);
250259
bool isDuplicated(
251260
const PredictedPath & predicted_path, const std::vector<PredictedPath> & predicted_paths);
261+
std::optional<lanelet::Id> getTrafficSignalId(const lanelet::ConstLanelet & way_lanelet);
252262

253263
visualization_msgs::msg::Marker getDebugMarker(
254264
const TrackedObject & object, const Maneuver & maneuver, const size_t obj_num);

perception/map_based_prediction/launch/map_based_prediction.launch.xml

+2
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
<arg name="param_path" default="$(find-pkg-share map_based_prediction)/config/map_based_prediction.param.yaml"/>
44

55
<arg name="vector_map_topic" default="/map/vector_map"/>
6+
<arg name="traffic_signals_topic" default="/perception/traffic_light_recognition/traffic_signals"/>
67
<arg name="output_topic" default="objects"/>
78
<arg name="input_topic" default="/perception/object_recognition/tracking/objects"/>
89

910
<node pkg="map_based_prediction" exec="map_based_prediction" name="map_based_prediction" output="screen">
1011
<param from="$(var param_path)"/>
1112
<remap from="/vector_map" to="$(var vector_map_topic)"/>
13+
<remap from="/traffic_signals" to="$(var traffic_signals_topic)"/>
1214
<remap from="~/output/objects" to="$(var output_topic)"/>
1315
<remap from="~/input/objects" to="$(var input_topic)"/>
1416
</node>

perception/map_based_prediction/package.xml

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
<buildtool_depend>autoware_cmake</buildtool_depend>
1717

1818
<depend>autoware_auto_perception_msgs</depend>
19+
<depend>autoware_perception_msgs</depend>
1920
<depend>interpolation</depend>
2021
<depend>lanelet2_extension</depend>
2122
<depend>libgoogle-glog-dev</depend>

perception/map_based_prediction/src/map_based_prediction_node.cpp

+46
Original file line numberDiff line numberDiff line change
@@ -801,6 +801,9 @@ MapBasedPredictionNode::MapBasedPredictionNode(const rclcpp::NodeOptions & node_
801801
sub_map_ = this->create_subscription<HADMapBin>(
802802
"/vector_map", rclcpp::QoS{1}.transient_local(),
803803
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));
804807

805808
pub_objects_ = this->create_publisher<PredictedObjects>("~/output/objects", rclcpp::QoS{1});
806809
pub_debug_markers_ =
@@ -872,6 +875,14 @@ void MapBasedPredictionNode::mapCallback(const HADMapBin::ConstSharedPtr msg)
872875
crosswalks_.insert(crosswalks_.end(), walkways.begin(), walkways.end());
873876
}
874877

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+
875886
void MapBasedPredictionNode::objectsCallback(const TrackedObjects::ConstSharedPtr in_objects)
876887
{
877888
stop_watch_.tic();
@@ -1218,6 +1229,23 @@ PredictedObject MapBasedPredictionNode::getPredictedObjectAsCrosswalkUser(
12181229
}
12191230
// try to find the edge points for all crosswalks and generate path to the crosswalk edge
12201231
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+
12211249
const auto edge_points = getCrosswalkEdgePoints(crosswalk);
12221250

12231251
const auto reachable_first = hasPotentialToReach(
@@ -2211,6 +2239,24 @@ bool MapBasedPredictionNode::isDuplicated(
22112239

22122240
return false;
22132241
}
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+
22142260
} // namespace map_based_prediction
22152261

22162262
#include <rclcpp_components/register_node_macro.hpp>

0 commit comments

Comments
 (0)