15 #ifndef NAV2_COLLISION_MONITOR__SOURCE_HPP_
16 #define NAV2_COLLISION_MONITOR__SOURCE_HPP_
22 #include "rclcpp/rclcpp.hpp"
24 #include "tf2/time.hpp"
25 #include "nav2_ros_common/tf2_factories.hpp"
27 #include "nav2_msgs/srv/add_exclusion_zone.hpp"
28 #include "nav2_msgs/srv/remove_exclusion_zone.hpp"
30 #include "nav2_collision_monitor/types.hpp"
31 #include "nav2_collision_monitor/exclusion_zone.hpp"
32 #include "nav2_ros_common/lifecycle_node.hpp"
33 #include "std_msgs/msg/header.hpp"
35 using rcl_interfaces::msg::ParameterType;
37 namespace nav2_collision_monitor
59 const nav2::LifecycleNode::WeakPtr & node,
60 const std::string & source_name,
61 const nav2::TransformBuffer::SharedPtr tf_buffer,
62 const std::string & base_frame_id,
63 const std::string & global_frame_id,
64 const tf2::Duration & transform_tolerance,
65 const rclcpp::Duration & source_timeout,
66 const bool base_shift_correction);
81 const rclcpp::Time & curr_time,
82 std::vector<Point> & data);
127 const rclcpp::Time & curr_time,
128 std::vector<Point> & data) = 0;
149 const rclcpp::Time & source_time,
150 const rclcpp::Time & curr_time)
const;
156 const std::shared_ptr<rmw_request_id_t> request_header,
157 const std::shared_ptr<nav2_msgs::srv::AddExclusionZone::Request> request,
158 std::shared_ptr<nav2_msgs::srv::AddExclusionZone::Response> response);
164 const std::shared_ptr<rmw_request_id_t> request_header,
165 const std::shared_ptr<nav2_msgs::srv::RemoveExclusionZone::Request> request,
166 std::shared_ptr<nav2_msgs::srv::RemoveExclusionZone::Response> response);
177 const std::vector<rclcpp::Parameter> & parameters);
198 const rclcpp::Time & curr_time,
199 const std_msgs::msg::Header & data_header,
200 tf2::Transform & tf_transform)
const;
207 rclcpp::Logger
logger_{rclcpp::get_logger(
"collision_monitor")};
210 rclcpp::node_interfaces::PostSetParametersCallbackHandle::SharedPtr post_set_params_handler_;
211 rclcpp::node_interfaces::OnSetParametersCallbackHandle::SharedPtr on_set_params_handler_;
nav2::LifecycleNode::WeakPtr node_
Collision Monitor node.
rclcpp::Logger logger_
Collision monitor node logger stored for further usage.
std::vector< std::shared_ptr< ExclusionZone > > exclusion_zones_
Exclusion zones masking out points from this source.
void removeExclusionZoneCallback(const std::shared_ptr< rmw_request_id_t > request_header, const std::shared_ptr< nav2_msgs::srv::RemoveExclusionZone::Request > request, std::shared_ptr< nav2_msgs::srv::RemoveExclusionZone::Response > response)
Service callback to remove an exclusion zone at runtime.
void activate()
Activates the exclusion zone visualization publishers (if any)
std::string base_frame_id_
Robot base frame ID.
virtual ~Source()
Source destructor.
bool getTransform(const rclcpp::Time &curr_time, const std_msgs::msg::Header &data_header, tf2::Transform &tf_transform) const
Obtain the transform to get data from source frame and time where it was received to the base frame a...
void addExclusionZoneCallback(const std::shared_ptr< rmw_request_id_t > request_header, const std::shared_ptr< nav2_msgs::srv::AddExclusionZone::Request > request, std::shared_ptr< nav2_msgs::srv::AddExclusionZone::Response > response)
Service callback to add an exclusion zone at runtime.
bool enabled_
Whether source is enabled.
virtual bool getSourceData(const rclcpp::Time &curr_time, std::vector< Point > &data)=0
Adds latest data from source to the data array. Pure virtual method implemented by each concrete sour...
bool getEnabled() const
Obtains source enabled state.
std::string getSourceName() const
Obtains the name of the data source.
Source(const nav2::LifecycleNode::WeakPtr &node, const std::string &source_name, const nav2::TransformBuffer::SharedPtr tf_buffer, const std::string &base_frame_id, const std::string &global_frame_id, const tf2::Duration &transform_tolerance, const rclcpp::Duration &source_timeout, const bool base_shift_correction)
Source constructor.
nav2::ServiceServer< nav2_msgs::srv::AddExclusionZone >::SharedPtr add_ez_service_
Service to add an exclusion zone at runtime.
tf2::Duration transform_tolerance_
Transform tolerance.
void getCommonParameters(std::string &source_topic)
Supporting routine obtaining ROS-parameters common for all data sources.
bool getData(const rclcpp::Time &curr_time, std::vector< Point > &data)
Adds latest data from source to the data array, then removes any points falling inside an enabled exc...
bool configure()
Source configuration routine.
void updateParametersCallback(const std::vector< rclcpp::Parameter > ¶meters)
Apply parameter updates after validation This callback is executed when parameters have been successf...
void publishExclusionZones() const
Publishes the source's exclusion zones for visualization.
std::string global_frame_id_
Global frame ID for correct transform calculation.
void deactivate()
Deactivates the exclusion zone visualization publishers (if any)
std::string source_name_
Name of data source.
nav2::ServiceServer< nav2_msgs::srv::RemoveExclusionZone >::SharedPtr remove_ez_service_
Service to remove an exclusion zone at runtime.
bool sourceValid(const rclcpp::Time &source_time, const rclcpp::Time &curr_time) const
Checks whether the source data might be considered as valid.
bool base_shift_correction_
Whether to correct source data towards to base frame movement, considering the difference between cur...
std::mutex mutex_
Dynamic parameters handler.
rcl_interfaces::msg::SetParametersResult validateParameterUpdatesCallback(const std::vector< rclcpp::Parameter > ¶meters)
Validate incoming parameter updates before applying them. This callback is triggered when one or more...
rclcpp::Duration source_timeout_
Maximum time interval in which data is considered valid.
nav2::TransformBuffer::SharedPtr tf_buffer_
TF buffer.
rclcpp::Duration getSourceTimeout() const
Obtains the source_timeout parameter of the data source.