Skip to content

Commit e9c43b4

Browse files
committed
add mutex
Signed-off-by: MasatoSaeki <masato.saeki@tier4.jp>
1 parent 4823597 commit e9c43b4

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

perception/autoware_traffic_light_selector/src/traffic_light_selector_node.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ TrafficLightSelectorNode::TrafficLightSelectorNode(const rclcpp::NodeOptions & n
3333
detected_rois_sub_(this, "input/detected_rois", rclcpp::QoS{1}.get_rmw_qos_profile()),
3434
rough_rois_sub_(this, "input/rough_rois", rclcpp::QoS{1}.get_rmw_qos_profile()),
3535
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)
3738
{
3839
{
3940
stop_watch_ptr_ =
@@ -61,13 +62,14 @@ TrafficLightSelectorNode::TrafficLightSelectorNode(const rclcpp::NodeOptions & n
6162
void TrafficLightSelectorNode::cameraInfoCallback(
6263
const sensor_msgs::msg::CameraInfo::ConstSharedPtr input_msg)
6364
{
65+
std::lock_guard<std::mutex> lock(mutex_);
6466
if (camera_info_subscribed_) {
6567
return;
6668
}
67-
RCLCPP_INFO(get_logger(), "camera_info received");
6869
image_width_ = input_msg->width;
6970
image_height_ = input_msg->height;
7071
camera_info_subscribed_ = true;
72+
RCLCPP_INFO(get_logger(), "camera_info received");
7173
}
7274

7375
void TrafficLightSelectorNode::objectsCallback(
@@ -76,9 +78,11 @@ void TrafficLightSelectorNode::objectsCallback(
7678
const TrafficLightRoiArray::ConstSharedPtr & expected_rois_msg)
7779
{
7880
stop_watch_ptr_->toc("processing_time", true);
81+
mutex_.lock();
7982
if (!camera_info_subscribed_) {
8083
return;
8184
}
85+
mutex_.unlock();
8286
std::map<int, sensor_msgs::msg::RegionOfInterest> rough_rois_map;
8387
for (const auto & roi : rough_rois_msg->rois) {
8488
rough_rois_map[roi.traffic_light_id] = roi.roi;

perception/autoware_traffic_light_selector/src/traffic_light_selector_node.hpp

+6-3
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include <tf2_ros/transform_listener.h>
3636

3737
#include <memory>
38+
#include <mutex>
3839

3940
namespace autoware::traffic_light
4041
{
@@ -73,9 +74,11 @@ class TrafficLightSelectorNode : public rclcpp::Node
7374
// Subscribe camera_info to get width and height of image
7475
rclcpp::Subscription<sensor_msgs::msg::CameraInfo>::SharedPtr camera_info_sub_;
7576
bool camera_info_subscribed_;
76-
uint32_t image_width_{1280};
77-
uint32_t image_height_{960};
78-
double max_iou_threshold_{0.0};
77+
uint32_t image_width_;
78+
uint32_t image_height_;
79+
double max_iou_threshold_;
80+
81+
std::mutex mutex_;
7982

8083
std::unique_ptr<autoware::universe_utils::StopWatch<std::chrono::milliseconds>> stop_watch_ptr_;
8184
std::unique_ptr<autoware::universe_utils::DebugPublisher> debug_publisher_;

0 commit comments

Comments
 (0)