26 rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_base,
27 rclcpp::node_interfaces::NodeLoggingInterface::SharedPtr node_logging,
28 rclcpp::node_interfaces::NodeTopicsInterface::SharedPtr node_topics,
29 rclcpp::node_interfaces::NodeParametersInterface::SharedPtr node_params_,
31 :node_base_(node_base),node_logging_(node_logging),node_topics_(node_topics),worker_(std::unique_ptr<
WMListenerWorker>(new
WMListenerWorker)), multi_threaded_(multi_thread)
34 RCLCPP_DEBUG_STREAM(
node_logging_->get_logger(),
"WMListener: Creating world model listener");
37 rclcpp::Parameter config_speed_limit_param(
"config_speed_limit");
38 if(!
node_params_->get_parameter(
"config_speed_limit", config_speed_limit_param)){
39 rclcpp::ParameterValue config_speed_limit_param_value;
40 config_speed_limit_param_value =
node_params_->declare_parameter(
"config_speed_limit", rclcpp::ParameterValue (0.0));
43 rclcpp::Parameter participant_param(
"vehicle_participant_type");
44 if(!
node_params_->get_parameter(
"vehicle_participant_type", participant_param)){
45 rclcpp::ParameterValue participant_param_value;
46 participant_param_value =
node_params_->declare_parameter(
"vehicle_participant_type", rclcpp::ParameterValue(
""));
50 rclcpp::Parameter use_sim_time_param(
"use_sim_time");
51 if(!
node_params_->get_parameter(
"use_sim_time", use_sim_time_param)){
52 rclcpp::ParameterValue use_sim_time_param_value;
53 use_sim_time_param_value =
node_params_->declare_parameter(
"use_sim_time", rclcpp::ParameterValue (
false));
56 rclcpp::Parameter is_spat_wall_time_param(
"is_spat_wall_time");
57 if(!
node_params_->get_parameter(
"is_spat_wall_time", is_spat_wall_time_param)){
58 rclcpp::ParameterValue is_spat_wall_time_param_value;
59 is_spat_wall_time_param_value =
node_params_->declare_parameter(
"is_spat_wall_time", rclcpp::ParameterValue (
true));
63 config_speed_limit_param =
node_params_->get_parameter(
"config_speed_limit");
64 participant_param =
node_params_->get_parameter(
"vehicle_participant_type");
65 use_sim_time_param =
node_params_->get_parameter(
"use_sim_time");
66 is_spat_wall_time_param =
node_params_->get_parameter(
"is_spat_wall_time");
68 RCLCPP_INFO_STREAM(node_logging->get_logger(),
"Loaded config speed limit: " << config_speed_limit_param.as_double());
69 RCLCPP_INFO_STREAM(node_logging->get_logger(),
"Loaded vehicle participant type: " << participant_param.as_string());
70 RCLCPP_INFO_STREAM(node_logging->get_logger(),
"Is using simulation time? : " << use_sim_time_param.as_bool());
71 RCLCPP_INFO_STREAM(node_logging->get_logger(),
"Is SPaT using wall time? : " << is_spat_wall_time_param.as_bool());
75 worker_->setVehicleParticipationType(participant_param.as_string());
76 worker_->isUsingSimTime(use_sim_time_param.as_bool());
77 worker_->isSpatWallTime(is_spat_wall_time_param.as_bool());
79 rclcpp::SubscriptionOptions map_update_options;
80 rclcpp::SubscriptionOptions map_options;
81 rclcpp::SubscriptionOptions route_options;
82 rclcpp::SubscriptionOptions roadway_objects_options;
83 rclcpp::SubscriptionOptions traffic_spat_options;
84 rclcpp::SubscriptionOptions ros1_clock_options;
85 rclcpp::SubscriptionOptions sim_clock_options;
89 RCLCPP_DEBUG_STREAM(
node_logging_->get_logger(),
"WMListener: Using a multi-threaded subscription");
91 map_update_options.callback_group =
node_base_->create_callback_group(rclcpp::CallbackGroupType::MutuallyExclusive);
93 map_options.callback_group =
node_base_->create_callback_group(rclcpp::CallbackGroupType::MutuallyExclusive);
95 route_options.callback_group =
node_base_->create_callback_group(rclcpp::CallbackGroupType::MutuallyExclusive);
97 roadway_objects_options.callback_group =
node_base_->create_callback_group(rclcpp::CallbackGroupType::MutuallyExclusive);
99 traffic_spat_options.callback_group =
node_base_->create_callback_group(rclcpp::CallbackGroupType::MutuallyExclusive);
101 ros1_clock_options.callback_group =
node_base_->create_callback_group(rclcpp::CallbackGroupType::MutuallyExclusive);
103 sim_clock_options.callback_group =
node_base_->create_callback_group(rclcpp::CallbackGroupType::MutuallyExclusive);
108 [
this](
const carma_planning_msgs::msg::Route::SharedPtr msg)
110 this->
worker_->routeCallback(msg);
115 [
this](
const rosgraph_msgs::msg::Clock::SharedPtr msg)
117 this->
worker_->ros1ClockCallback(msg);
119 , ros1_clock_options);
122 [
this](
const rosgraph_msgs::msg::Clock::SharedPtr msg)
124 this->
worker_->simClockCallback(msg);
126 , sim_clock_options);
129 [
this](
const carma_perception_msgs::msg::RoadwayObstacleList::SharedPtr msg)
131 this->
worker_->roadwayObjectListCallback(msg);
133 , roadway_objects_options);
136 [
this](
const carma_v2x_msgs::msg::SPAT::SharedPtr msg)
138 this->
worker_->incomingSpatCallback(msg);
140 , traffic_spat_options);
143 map_update_options.use_intra_process_comm = rclcpp::IntraProcessSetting::Disable;
144 auto map_update_sub_qos = rclcpp::QoS(rclcpp::KeepLast(10));
145 map_update_sub_qos.transient_local();
150 [
this](
const autoware_lanelet2_msgs::msg::MapBin::SharedPtr msg)
154 , map_update_options);
156 map_options.use_intra_process_comm = rclcpp::IntraProcessSetting::Disable;
157 auto map_sub_qos = rclcpp::QoS(rclcpp::KeepLast(2));
158 map_sub_qos.transient_local();
162 map_sub_ = rclcpp::create_subscription<autoware_lanelet2_msgs::msg::MapBin>(
node_topics_,
"semantic_map", map_sub_qos,
163 [
this](
const autoware_lanelet2_msgs::msg::MapBin::SharedPtr msg)
165 this->
worker_->mapCallback(msg);
174 const std::lock_guard<std::mutex> lock(
mw_mutex_);
175 worker_->enableUpdatesWithoutRoute();
180 const std::lock_guard<std::mutex> lock(
mw_mutex_);
181 return worker_->checkIfReRoutingNeeded();
186 const std::lock_guard<std::mutex> lock(
mw_mutex_);
187 return worker_->getWorldModel();
192 const std::lock_guard<std::mutex> lock(
mw_mutex_);
194 RCLCPP_INFO_STREAM(
node_logging_->get_logger(),
"New Map Update Received. SeqNum: " << geofence_msg->seq_id);
196 worker_->mapUpdateCallback(geofence_msg);
201 const std::lock_guard<std::mutex> lock(
mw_mutex_);
207 const std::lock_guard<std::mutex> lock(
mw_mutex_);
215 std::unique_lock<std::mutex> lock(
mw_mutex_);
218 std::unique_lock<std::mutex> lock(
mw_mutex_, std::defer_lock);
224 worker_->setConfigSpeedLimit(config_lim);
Backend logic class for WMListener.
rclcpp::node_interfaces::NodeLoggingInterface::SharedPtr node_logging_
void mapUpdateCallback(autoware_lanelet2_msgs::msg::MapBin::SharedPtr geofence_msg)
void setConfigSpeedLimit(double config_lim) const
Allows user to set a callback to be triggered when a route update is received NOTE: If operating in m...
carma_ros2_utils::SubPtr< autoware_lanelet2_msgs::msg::MapBin > map_update_sub_
void setMapCallback(std::function< void()> callback)
Allows user to set a callback to be triggered when a map update is received NOTE: If operating in mul...
WorldModelConstPtr getWorldModel()
Returns a pointer to an intialized world model instance.
carma_ros2_utils::SubPtr< rosgraph_msgs::msg::Clock > sim_clock_sub_
carma_ros2_utils::SubPtr< rosgraph_msgs::msg::Clock > ros1_clock_sub_
rclcpp::node_interfaces::NodeTopicsInterface::SharedPtr node_topics_
carma_ros2_utils::SubPtr< autoware_lanelet2_msgs::msg::MapBin > map_sub_
std::unique_ptr< WMListenerWorker > worker_
void enableUpdatesWithoutRouteWL()
Use to allow updates to occur even if they invalidate the current route. This is only meant to be use...
rclcpp::node_interfaces::NodeParametersInterface::SharedPtr node_params_
carma_ros2_utils::SubPtr< carma_perception_msgs::msg::RoadwayObstacleList > roadway_objects_sub_
rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_base_
void setRouteCallback(std::function< void()> callback)
Allows user to set a callback to be triggered when a route update is received NOTE: If operating in m...
carma_ros2_utils::SubPtr< carma_planning_msgs::msg::Route > route_sub_
WMListener(rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_base, rclcpp::node_interfaces::NodeLoggingInterface::SharedPtr node_logging, rclcpp::node_interfaces::NodeTopicsInterface::SharedPtr node_topics, rclcpp::node_interfaces::NodeParametersInterface::SharedPtr node_params_, bool multi_thread=false)
Constructor which can be used to specify threading behavior of this class.
const bool multi_threaded_
bool checkIfReRoutingNeededWL()
Returns true if a map update has been processed which requires rerouting. This method is meant to be ...
std::unique_lock< std::mutex > getLock(bool pre_locked=true)
Returns a unique_lock which can be used to lock world model updates until the user finishes a desired...
carma_ros2_utils::SubPtr< carma_v2x_msgs::msg::SPAT > traffic_spat_sub_
bool callback(cav_srvs::PlanTrajectory::Request &req, cav_srvs::PlanTrajectory::Response &res)
std::shared_ptr< const WorldModel > WorldModelConstPtr