@@ -33,7 +33,8 @@ TrafficLightSelectorNode::TrafficLightSelectorNode(const rclcpp::NodeOptions & n
33
33
detected_rois_sub_(this , " input/detected_rois" , rclcpp::QoS{1 }.get_rmw_qos_profile()),
34
34
rough_rois_sub_(this , " input/rough_rois" , rclcpp::QoS{1 }.get_rmw_qos_profile()),
35
35
expected_rois_sub_(this , " input/expect_rois" , rclcpp::QoS{1 }.get_rmw_qos_profile()),
36
- sync_(SyncPolicy(10 ), detected_rois_sub_, rough_rois_sub_, expected_rois_sub_)
36
+ sync_(SyncPolicy(10 ), detected_rois_sub_, rough_rois_sub_, expected_rois_sub_),
37
+ camera_info_subscribed_(false )
37
38
{
38
39
{
39
40
stop_watch_ptr_ =
@@ -61,13 +62,14 @@ TrafficLightSelectorNode::TrafficLightSelectorNode(const rclcpp::NodeOptions & n
61
62
void TrafficLightSelectorNode::cameraInfoCallback (
62
63
const sensor_msgs::msg::CameraInfo::ConstSharedPtr input_msg)
63
64
{
65
+ std::lock_guard<std::mutex> lock (mutex_);
64
66
if (camera_info_subscribed_) {
65
67
return ;
66
68
}
67
- RCLCPP_INFO (get_logger (), " camera_info received" );
68
69
image_width_ = input_msg->width ;
69
70
image_height_ = input_msg->height ;
70
71
camera_info_subscribed_ = true ;
72
+ RCLCPP_INFO (get_logger (), " camera_info received" );
71
73
}
72
74
73
75
void TrafficLightSelectorNode::objectsCallback (
@@ -76,9 +78,11 @@ void TrafficLightSelectorNode::objectsCallback(
76
78
const TrafficLightRoiArray::ConstSharedPtr & expected_rois_msg)
77
79
{
78
80
stop_watch_ptr_->toc (" processing_time" , true );
81
+ mutex_.lock ();
79
82
if (!camera_info_subscribed_) {
80
83
return ;
81
84
}
85
+ mutex_.unlock ();
82
86
std::map<int , sensor_msgs::msg::RegionOfInterest> rough_rois_map;
83
87
for (const auto & roi : rough_rois_msg->rois ) {
84
88
rough_rois_map[roi.traffic_light_id ] = roi.roi ;
0 commit comments