Carma-platform v4.2.0
CARMA Platform is built on robot operating system (ROS) and utilizes open source software (OSS) that enables Cooperative Driving Automation (CDA) features to allow Automated Driving Systems to interact and cooperate with infrastructure and other vehicles through communication.
WMListener.hpp
Go to the documentation of this file.
1#pragma once
2
3/*
4 * Copyright (C) 2022 LEIDOS.
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
7 * use this file except in compliance with the License. You may obtain a copy of
8 * the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15 * License for the specific language governing permissions and limitations under
16 * the License.
17 */
18
19#include <functional>
20#include <mutex>
21#include <rclcpp/rclcpp.hpp>
23#include <carma_ros2_utils/carma_ros2_utils.hpp>
24#include <autoware_lanelet2_msgs/msg/map_bin.hpp>
25#include <queue>
26#include <carma_perception_msgs/msg/roadway_obstacle_list.hpp>
27#include <carma_planning_msgs/msg/route.hpp>
28#include <carma_v2x_msgs/msg/spat.hpp>
29#include <carma_ros2_utils/carma_lifecycle_node.hpp>
30#include <rosgraph_msgs/msg/clock.hpp>
31
32namespace carma_wm
33{
34class WMListenerWorker; // Forward declaration of worker class
35
47{
48public:
58 rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_base,
59 rclcpp::node_interfaces::NodeLoggingInterface::SharedPtr node_logging,
60 rclcpp::node_interfaces::NodeTopicsInterface::SharedPtr node_topics,
61 rclcpp::node_interfaces::NodeParametersInterface::SharedPtr node_params_,
62 bool multi_thread = false);
63
67
74
82 void setMapCallback(std::function<void()> callback);
83
91 void setRouteCallback(std::function<void()> callback);
92
103 std::unique_lock<std::mutex> getLock(bool pre_locked = true);
104
112 void setConfigSpeedLimit(double config_lim) const;
113
119
127
128
129private:
130 // Callback function that uses lock to edit the map
131 void mapUpdateCallback(autoware_lanelet2_msgs::msg::MapBin::SharedPtr geofence_msg);
132 carma_ros2_utils::SubPtr<carma_perception_msgs::msg::RoadwayObstacleList> roadway_objects_sub_;
133 carma_ros2_utils::SubPtr<autoware_lanelet2_msgs::msg::MapBin> map_update_sub_;
134
135 rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_base_;
136 rclcpp::node_interfaces::NodeLoggingInterface::SharedPtr node_logging_;
137 rclcpp::node_interfaces::NodeTopicsInterface::SharedPtr node_topics_;
138 rclcpp::node_interfaces::NodeParametersInterface::SharedPtr node_params_;
139
140 std::unique_ptr<WMListenerWorker> worker_;
141
142 carma_ros2_utils::SubPtr<autoware_lanelet2_msgs::msg::MapBin> map_sub_;
143 carma_ros2_utils::SubPtr<carma_planning_msgs::msg::Route> route_sub_;
144 carma_ros2_utils::SubPtr<carma_v2x_msgs::msg::SPAT> traffic_spat_sub_;
145 carma_ros2_utils::SubPtr<rosgraph_msgs::msg::Clock> sim_clock_sub_;
146 carma_ros2_utils::SubPtr<rosgraph_msgs::msg::Clock> ros1_clock_sub_;
147 const bool multi_threaded_;
148 std::mutex mw_mutex_;
149
150
151};
152} // namespace carma_wm
Class which provies automated subscription and threading support for the world model.
Definition: WMListener.hpp:47
rclcpp::node_interfaces::NodeLoggingInterface::SharedPtr node_logging_
Definition: WMListener.hpp:136
void mapUpdateCallback(autoware_lanelet2_msgs::msg::MapBin::SharedPtr geofence_msg)
Definition: WMListener.cpp:190
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...
Definition: WMListener.cpp:222
carma_ros2_utils::SubPtr< autoware_lanelet2_msgs::msg::MapBin > map_update_sub_
Definition: WMListener.hpp:133
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...
Definition: WMListener.cpp:199
WorldModelConstPtr getWorldModel()
Returns a pointer to an intialized world model instance.
Definition: WMListener.cpp:184
carma_ros2_utils::SubPtr< rosgraph_msgs::msg::Clock > sim_clock_sub_
Definition: WMListener.hpp:145
carma_ros2_utils::SubPtr< rosgraph_msgs::msg::Clock > ros1_clock_sub_
Definition: WMListener.hpp:146
rclcpp::node_interfaces::NodeTopicsInterface::SharedPtr node_topics_
Definition: WMListener.hpp:137
~WMListener()
Destructor.
Definition: WMListener.cpp:170
carma_ros2_utils::SubPtr< autoware_lanelet2_msgs::msg::MapBin > map_sub_
Definition: WMListener.hpp:142
std::unique_ptr< WMListenerWorker > worker_
Definition: WMListener.hpp:140
void enableUpdatesWithoutRouteWL()
Use to allow updates to occur even if they invalidate the current route. This is only meant to be use...
Definition: WMListener.cpp:172
rclcpp::node_interfaces::NodeParametersInterface::SharedPtr node_params_
Definition: WMListener.hpp:138
carma_ros2_utils::SubPtr< carma_perception_msgs::msg::RoadwayObstacleList > roadway_objects_sub_
Definition: WMListener.hpp:132
rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_base_
Definition: WMListener.hpp:135
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...
Definition: WMListener.cpp:205
carma_ros2_utils::SubPtr< carma_planning_msgs::msg::Route > route_sub_
Definition: WMListener.hpp:143
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.
Definition: WMListener.cpp:25
const bool multi_threaded_
Definition: WMListener.hpp:147
bool checkIfReRoutingNeededWL()
Returns true if a map update has been processed which requires rerouting. This method is meant to be ...
Definition: WMListener.cpp:178
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...
Definition: WMListener.cpp:211
carma_ros2_utils::SubPtr< carma_v2x_msgs::msg::SPAT > traffic_spat_sub_
Definition: WMListener.hpp:144
bool callback(cav_srvs::PlanTrajectory::Request &req, cav_srvs::PlanTrajectory::Response &res)
Definition: helper.cpp:21
std::shared_ptr< const WorldModel > WorldModelConstPtr
Definition: WorldModel.hpp:452