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.
|
Class which provies automated subscription and threading support for the world model. More...
#include <WMListener.hpp>
Public Member Functions | |
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. More... | |
~WMListener () | |
Destructor. More... | |
WorldModelConstPtr | getWorldModel () |
Returns a pointer to an intialized world model instance. More... | |
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 multi-threaded mode the world model will remain locked until the user function completes. More... | |
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 multi-threaded mode the world model will remain locked until the user function completes. More... | |
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 operation. This function should be used when multiple queries are needed and this object is operating in multi-threaded mode. More... | |
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 multi-threaded mode the world model will remain locked until the user function completes. More... | |
void | enableUpdatesWithoutRouteWL () |
Use to allow updates to occur even if they invalidate the current route. This is only meant to be used by components which generate the route. More... | |
bool | checkIfReRoutingNeededWL () |
Returns true if a map update has been processed which requires rerouting. This method is meant to be used by routing components. More... | |
Private Member Functions | |
void | mapUpdateCallback (autoware_lanelet2_msgs::msg::MapBin::SharedPtr geofence_msg) |
Private Attributes | |
carma_ros2_utils::SubPtr< carma_perception_msgs::msg::RoadwayObstacleList > | roadway_objects_sub_ |
carma_ros2_utils::SubPtr< autoware_lanelet2_msgs::msg::MapBin > | map_update_sub_ |
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_ |
std::unique_ptr< WMListenerWorker > | worker_ |
carma_ros2_utils::SubPtr< autoware_lanelet2_msgs::msg::MapBin > | map_sub_ |
carma_ros2_utils::SubPtr< carma_planning_msgs::msg::Route > | route_sub_ |
carma_ros2_utils::SubPtr< carma_v2x_msgs::msg::SPAT > | traffic_spat_sub_ |
carma_ros2_utils::SubPtr< rosgraph_msgs::msg::Clock > | sim_clock_sub_ |
carma_ros2_utils::SubPtr< rosgraph_msgs::msg::Clock > | ros1_clock_sub_ |
const bool | multi_threaded_ |
std::mutex | mw_mutex_ |
Class which provies automated subscription and threading support for the world model.
Users should generally create and cache a single instance of this class within a node. They can then retrieve a pointer to an initialized WorldModel object for doing queries. By default this class follows the threading model of the host node, but it can operate in the background if specified in the constructor. When used in a multi-threading case users can ensure threadsafe operation though usage of the getLock function
Definition at line 46 of file WMListener.hpp.
carma_wm::WMListener::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.
By default this object follows node threading behavior (ie. waiting for ros::spin()) If the object is operating in multi-threaded mode a ros::AsyncSpinner is used to implement a background thread.
multi_thread | If true this object will subscribe using background threads. Defaults to false |
Definition at line 25 of file WMListener.cpp.
References map_sub_, map_update_sub_, mapUpdateCallback(), multi_threaded_, node_base_, node_logging_, node_params_, node_topics_, roadway_objects_sub_, ros1_clock_sub_, route_sub_, setConfigSpeedLimit(), sim_clock_sub_, traffic_spat_sub_, and worker_.
carma_wm::WMListener::~WMListener | ( | ) |
bool carma_wm::WMListener::checkIfReRoutingNeededWL | ( | ) |
Returns true if a map update has been processed which requires rerouting. This method is meant to be used by routing components.
Definition at line 178 of file WMListener.cpp.
References mw_mutex_, and worker_.
Referenced by route::Route::handle_on_configure().
void carma_wm::WMListener::enableUpdatesWithoutRouteWL | ( | ) |
Use to allow updates to occur even if they invalidate the current route. This is only meant to be used by components which generate the route.
Definition at line 172 of file WMListener.cpp.
References mw_mutex_, and worker_.
Referenced by route::Route::handle_on_configure().
std::unique_lock< std::mutex > carma_wm::WMListener::getLock | ( | bool | pre_locked = true | ) |
Returns a unique_lock which can be used to lock world model updates until the user finishes a desired operation. This function should be used when multiple queries are needed and this object is operating in multi-threaded mode.
pre_locked | If true the returned lock will already be locked. If false the lock will be deferred with std::defer_lock Default is true |
Definition at line 211 of file WMListener.cpp.
References mw_mutex_.
WorldModelConstPtr carma_wm::WMListener::getWorldModel | ( | ) |
Returns a pointer to an intialized world model instance.
Definition at line 184 of file WMListener.cpp.
References mw_mutex_, and worker_.
Referenced by plan_delegator::PlanDelegator::handle_on_configure(), and route::Route::handle_on_configure().
|
private |
Definition at line 190 of file WMListener.cpp.
References mw_mutex_, node_logging_, and worker_.
Referenced by WMListener().
void carma_wm::WMListener::setConfigSpeedLimit | ( | double | config_lim | ) | const |
Allows user to set a callback to be triggered when a route update is received NOTE: If operating in multi-threaded mode the world model will remain locked until the user function completes.
config_lim | A function that populate the configurable speed limit value after the world model is updated with a new route |
Definition at line 222 of file WMListener.cpp.
References worker_.
Referenced by WMListener().
void carma_wm::WMListener::setMapCallback | ( | std::function< void()> | callback | ) |
Allows user to set a callback to be triggered when a map update is received NOTE: If operating in multi-threaded mode the world model will remain locked until the user function completes.
callback | A callback function that will be triggered after the world model receives a new map update |
Definition at line 199 of file WMListener.cpp.
References callback(), mw_mutex_, and worker_.
void carma_wm::WMListener::setRouteCallback | ( | std::function< void()> | callback | ) |
Allows user to set a callback to be triggered when a route update is received NOTE: If operating in multi-threaded mode the world model will remain locked until the user function completes.
callback | A callback function that will be triggered after the world model is updated with a new route |
Definition at line 205 of file WMListener.cpp.
References callback(), mw_mutex_, and worker_.
|
private |
Definition at line 142 of file WMListener.hpp.
Referenced by WMListener().
|
private |
Definition at line 133 of file WMListener.hpp.
Referenced by WMListener().
|
private |
Definition at line 147 of file WMListener.hpp.
Referenced by WMListener().
|
private |
Definition at line 148 of file WMListener.hpp.
Referenced by checkIfReRoutingNeededWL(), enableUpdatesWithoutRouteWL(), getLock(), getWorldModel(), mapUpdateCallback(), setMapCallback(), and setRouteCallback().
|
private |
Definition at line 135 of file WMListener.hpp.
Referenced by WMListener().
|
private |
Definition at line 136 of file WMListener.hpp.
Referenced by WMListener(), and mapUpdateCallback().
|
private |
Definition at line 138 of file WMListener.hpp.
Referenced by WMListener().
|
private |
Definition at line 137 of file WMListener.hpp.
Referenced by WMListener().
|
private |
Definition at line 132 of file WMListener.hpp.
Referenced by WMListener().
|
private |
Definition at line 146 of file WMListener.hpp.
Referenced by WMListener().
|
private |
Definition at line 143 of file WMListener.hpp.
Referenced by WMListener().
|
private |
Definition at line 145 of file WMListener.hpp.
Referenced by WMListener().
|
private |
Definition at line 144 of file WMListener.hpp.
Referenced by WMListener().
|
private |
Definition at line 140 of file WMListener.hpp.
Referenced by WMListener(), checkIfReRoutingNeededWL(), enableUpdatesWithoutRouteWL(), getWorldModel(), mapUpdateCallback(), setConfigSpeedLimit(), setMapCallback(), and setRouteCallback().