Nav2 Navigation Stack - lyrical  lyrical
ROS 2 Navigation Stack
Public Member Functions | List of all members
nav2_collision_monitor::CostmapSource Class Reference

Reads nav2_msgs::msg::Costmap and produces obstacle points for Collision Monitor. More...

#include <nav2_collision_monitor/include/nav2_collision_monitor/costmap.hpp>

Inheritance diagram for nav2_collision_monitor::CostmapSource:
Inheritance graph
[legend]
Collaboration diagram for nav2_collision_monitor::CostmapSource:
Collaboration graph
[legend]

Public Member Functions

 CostmapSource (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)
 Construct a CostmapSource. More...
 
 ~CostmapSource ()
 Destructor.
 
bool configure ()
 Declare and get parameters; create the subscription. More...
 
bool getSourceData (const rclcpp::Time &curr_time, std::vector< Point > &data) override
 Produce current obstacle points from the latest costmap. More...
 
void getParameters (std::string &source_topic)
 Read parameters specific to the costmap source. More...
 
bool hasData () const
 Check if costmap data has been received. More...
 
- Public Member Functions inherited from nav2_collision_monitor::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. More...
 
virtual ~Source ()
 Source destructor.
 
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 exclusion zone. More...
 
void activate ()
 Activates the exclusion zone visualization publishers (if any)
 
void deactivate ()
 Deactivates the exclusion zone visualization publishers (if any)
 
void publishExclusionZones () const
 Publishes the source's exclusion zones for visualization.
 
bool getEnabled () const
 Obtains source enabled state. More...
 
std::string getSourceName () const
 Obtains the name of the data source. More...
 
rclcpp::Duration getSourceTimeout () const
 Obtains the source_timeout parameter of the data source. More...
 

Additional Inherited Members

- Protected Member Functions inherited from nav2_collision_monitor::Source
bool configure ()
 Source configuration routine. More...
 
void getCommonParameters (std::string &source_topic)
 Supporting routine obtaining ROS-parameters common for all data sources. More...
 
bool sourceValid (const rclcpp::Time &source_time, const rclcpp::Time &curr_time) const
 Checks whether the source data might be considered as valid. More...
 
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.
 
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.
 
rcl_interfaces::msg::SetParametersResult validateParameterUpdatesCallback (const std::vector< rclcpp::Parameter > &parameters)
 Validate incoming parameter updates before applying them. This callback is triggered when one or more parameters are about to be updated. It checks the validity of parameter values and rejects updates that would lead to invalid or inconsistent configurations. More...
 
void updateParametersCallback (const std::vector< rclcpp::Parameter > &parameters)
 Apply parameter updates after validation This callback is executed when parameters have been successfully updated. It updates the internal configuration of the node with the new parameter values. More...
 
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 and current time (if base_shift_correction_ is true) or the transform without time shift considered which is less accurate but much more faster option not dependent on state estimation frames. More...
 
- Protected Attributes inherited from nav2_collision_monitor::Source
nav2::LifecycleNode::WeakPtr node_
 Collision Monitor node.
 
rclcpp::Logger logger_ {rclcpp::get_logger("collision_monitor")}
 Collision monitor node logger stored for further usage.
 
std::mutex mutex_
 Dynamic parameters handler.
 
rclcpp::node_interfaces::PostSetParametersCallbackHandle::SharedPtr post_set_params_handler_
 
rclcpp::node_interfaces::OnSetParametersCallbackHandle::SharedPtr on_set_params_handler_
 
std::string source_name_
 Name of data source.
 
nav2::TransformBuffer::SharedPtr tf_buffer_
 TF buffer.
 
std::string base_frame_id_
 Robot base frame ID.
 
std::string global_frame_id_
 Global frame ID for correct transform calculation.
 
tf2::Duration transform_tolerance_
 Transform tolerance.
 
rclcpp::Duration source_timeout_
 Maximum time interval in which data is considered valid.
 
bool base_shift_correction_
 Whether to correct source data towards to base frame movement, considering the difference between current time and latest source time.
 
bool enabled_
 Whether source is enabled.
 
std::vector< std::shared_ptr< ExclusionZone > > exclusion_zones_
 Exclusion zones masking out points from this source.
 
nav2::ServiceServer< nav2_msgs::srv::AddExclusionZone >::SharedPtr add_ez_service_
 Service to add an exclusion zone at runtime.
 
nav2::ServiceServer< nav2_msgs::srv::RemoveExclusionZone >::SharedPtr remove_ez_service_
 Service to remove an exclusion zone at runtime.
 

Detailed Description

Reads nav2_msgs::msg::Costmap and produces obstacle points for Collision Monitor.

Cells with cost >= cost_threshold_ are exported as points. Optionally, NO_INFORMATION (255) can be treated as obstacles via treat_unknown_as_obstacle_.

Parameters (declared/queried in getParameters):

Definition at line 49 of file costmap.hpp.

Constructor & Destructor Documentation

◆ CostmapSource()

nav2_collision_monitor::CostmapSource::CostmapSource ( 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 
)

Construct a CostmapSource.

Parameters
nodeWeak pointer to the lifecycle node.
source_nameLogical name of this source instance (for params/logs).
tf_bufferShared TF buffer for frame transforms.
base_frame_idRobot base frame (e.g., "base_footprint").
global_frame_idGlobal frame of the costmap (e.g., "odom" or "map").
transform_toleranceAllowed TF age for transforms.
source_timeoutMax age of data before it is considered stale.
base_shift_correctionWhether to compensate robot motion during simulation checks.

Definition at line 30 of file costmap.cpp.

References nav2_collision_monitor::Source::logger_, and nav2_collision_monitor::Source::source_name_.

Member Function Documentation

◆ configure()

bool nav2_collision_monitor::CostmapSource::configure ( )

Declare and get parameters; create the subscription.

Must be called during the node’s configuration phase (after construction, before use). Reads topic, cost_threshold, and treat_unknown_as_obstacle.

Returns
True in case of everything is configured correctly, or false otherwise

Definition at line 53 of file costmap.cpp.

References nav2_collision_monitor::Source::configure(), getParameters(), and nav2_collision_monitor::Source::node_.

Here is the call graph for this function:

◆ getParameters()

void nav2_collision_monitor::CostmapSource::getParameters ( std::string &  source_topic)

Read parameters specific to the costmap source.

Parameters
[out]source_topicResolved topic name to subscribe to.

Declares/gets: topic, cost_threshold, treat_unknown_as_obstacle.

Definition at line 122 of file costmap.cpp.

References nav2_collision_monitor::Source::getCommonParameters(), nav2_collision_monitor::Source::node_, and nav2_collision_monitor::Source::source_name_.

Referenced by configure().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getSourceData()

bool nav2_collision_monitor::CostmapSource::getSourceData ( const rclcpp::Time &  curr_time,
std::vector< Point > &  data 
)
overridevirtual

Produce current obstacle points from the latest costmap.

Parameters
curr_timeCurrent time used for staleness checks and TF queries.
[out]dataOutput vector of points in the base frame.
Returns
true if valid, non-stale data were produced; false otherwise.
  • Returns false if no message has arrived or data are older than source_timeout_.
  • Transforms points from costmap frame to base_frame_id using tf_buffer_.
  • Applies cost_threshold_ and treat_unknown_as_obstacle_.

Implements nav2_collision_monitor::Source.

Definition at line 72 of file costmap.cpp.

References nav2_collision_monitor::Source::base_frame_id_, nav2_collision_monitor::Source::getTransform(), nav2_collision_monitor::Source::logger_, nav2_collision_monitor::Source::node_, nav2_collision_monitor::Source::source_name_, and nav2_collision_monitor::Source::sourceValid().

Here is the call graph for this function:

◆ hasData()

bool nav2_collision_monitor::CostmapSource::hasData ( ) const
inline

Check if costmap data has been received.

Returns
true if data has been received, false otherwise.

Definition at line 112 of file costmap.hpp.


The documentation for this class was generated from the following files: