Nav2 Navigation Stack - rolling  main
ROS 2 Navigation Stack
Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
nav2_loopback_sim::LoopbackSimulator Class Reference

A loopback simulator that replaces a physics simulator to create a frictionless, inertialess, and collisionless simulation environment. It accepts cmd_vel messages and publishes odometry & TF messages based on the cumulative velocities received to mimic global localization and simulation. It also accepts initialpose messages to set the initial pose of the robot. More...

#include <nav2_loopback_sim/include/nav2_loopback_sim/loopback_simulator.hpp>

Inheritance diagram for nav2_loopback_sim::LoopbackSimulator:
Inheritance graph
[legend]
Collaboration diagram for nav2_loopback_sim::LoopbackSimulator:
Collaboration graph
[legend]

Public Member Functions

 LoopbackSimulator (const rclcpp::NodeOptions &options=rclcpp::NodeOptions())
 Construct a LoopbackSimulator node. More...
 
- Public Member Functions inherited from nav2::LifecycleNode
 LifecycleNode (const std::string &node_name, const std::string &ns, const rclcpp::NodeOptions &options=rclcpp::NodeOptions())
 A lifecycle node constructor. More...
 
 LifecycleNode (const std::string &node_name, const rclcpp::NodeOptions &options=rclcpp::NodeOptions())
 A lifecycle node constructor with no namespace. More...
 
template<typename ParameterT >
ParameterT declare_or_get_parameter (const std::string &parameter_name, const ParameterDescriptor &parameter_descriptor=ParameterDescriptor())
 Declares or gets a parameter with specified type (not value). If the parameter is already declared, returns its value; otherwise declares it with the specified type. More...
 
template<typename ParamType >
ParamType declare_or_get_parameter (const std::string &parameter_name, const ParamType &default_value, const ParameterDescriptor &parameter_descriptor=ParameterDescriptor())
 Declares or gets a parameter. If the parameter is already declared, returns its value; otherwise declares it and returns the default value. More...
 
template<typename MessageT , typename CallbackT >
nav2::Subscription< MessageT >::SharedPtr create_subscription (const std::string &topic_name, CallbackT &&callback, const rclcpp::QoS &qos=nav2::qos::StandardTopicQoS(), const rclcpp::CallbackGroup::SharedPtr &callback_group=nullptr)
 Create a subscription to a topic using Nav2 QoS profiles and SubscriptionOptions. More...
 
template<typename MessageT >
nav2::Publisher< MessageT >::SharedPtr create_publisher (const std::string &topic_name, const rclcpp::QoS &qos=nav2::qos::StandardTopicQoS(), const rclcpp::CallbackGroup::SharedPtr &callback_group=nullptr)
 Create a publisher to a topic using Nav2 QoS profiles and PublisherOptions. More...
 
template<typename ServiceT >
nav2::ServiceClient< ServiceT >::SharedPtr create_client (const std::string &service_name, bool use_internal_executor=false)
 Create a ServiceClient to interface with a service. More...
 
template<typename ServiceT >
nav2::ServiceServer< ServiceT >::SharedPtr create_service (const std::string &service_name, typename nav2::ServiceServer< ServiceT >::CallbackType cb, rclcpp::CallbackGroup::SharedPtr callback_group=nullptr)
 Create a ServiceServer to host with a service. More...
 
template<typename DurationRepT , typename DurationT , typename CallbackT >
rclcpp::GenericTimer< CallbackT >::SharedPtr create_timer (std::chrono::duration< DurationRepT, DurationT > period, CallbackT callback, rclcpp::CallbackGroup::SharedPtr group=nullptr)
 Create a sim-time-aware timer for Nav2 lifecycle nodes. More...
 
template<typename ActionT >
nav2::SimpleActionServer< ActionT >::SharedPtr create_action_server (const std::string &action_name, typename nav2::SimpleActionServer< ActionT >::ExecuteCallback execute_callback, typename nav2::SimpleActionServer< ActionT >::GoalReceivedCallback goal_received_callback=nullptr, typename nav2::SimpleActionServer< ActionT >::CompletionCallback compl_cb=nullptr, std::chrono::milliseconds server_timeout=std::chrono::milliseconds(500), bool spin_thread=false, const bool realtime=false)
 Create a SimpleActionServer to host with an action. More...
 
template<typename ActionT >
nav2::ActionClient< ActionT >::SharedPtr create_action_client (const std::string &action_name, rclcpp::CallbackGroup::SharedPtr callback_group=nullptr)
 Create a ActionClient to call an action using. More...
 
nav2::LifecycleNode::SharedPtr shared_from_this ()
 Get a shared pointer of this.
 
nav2::LifecycleNode::WeakPtr weak_from_this ()
 Get a shared pointer of this.
 
nav2::CallbackReturn on_error (const rclcpp_lifecycle::State &)
 Abstracted on_error state transition callback, since unimplemented as of 2020 in the managed ROS2 node state machine. More...
 
void autostart ()
 Automatically configure and active the node.
 
virtual void on_rcl_preshutdown ()
 Perform preshutdown activities before our Context is shutdown. Note that this is related to our Context's shutdown sequence, not the lifecycle node state machine.
 
void createBond ()
 Create bond connection to lifecycle manager.
 
void destroyBond ()
 Destroy bond connection to lifecycle manager.
 

Protected Member Functions

nav2::CallbackReturn on_configure (const rclcpp_lifecycle::State &state) override
 Configure the node: declare parameters, create pubs/subs/timers.
 
nav2::CallbackReturn on_activate (const rclcpp_lifecycle::State &state) override
 Activate the node: start publishing.
 
nav2::CallbackReturn on_deactivate (const rclcpp_lifecycle::State &state) override
 Deactivate the node: stop timers, reset cmd_vel.
 
nav2::CallbackReturn on_cleanup (const rclcpp_lifecycle::State &state) override
 Cleanup the node: release all resources.
 
nav2::CallbackReturn on_shutdown (const rclcpp_lifecycle::State &state) override
 Shutdown the node.
 
void cmdVelCallback (const geometry_msgs::msg::Twist::ConstSharedPtr &msg)
 Callback for incoming cmd_vel (unstamped Twist)
 
void cmdVelStampedCallback (const geometry_msgs::msg::TwistStamped::ConstSharedPtr &msg)
 Callback for incoming cmd_vel (stamped TwistStamped)
 
void initialPoseCallback (const geometry_msgs::msg::PoseWithCovarianceStamped::ConstSharedPtr &msg)
 Callback for incoming initial pose.
 
void setupTimerCallback ()
 Periodic setup callback: publishes identity TFs and fetches map.
 
void timerCallback ()
 Main update callback: integrates cmd_vel and publishes TF.
 
void odomTimerCallback ()
 Periodic odometry publishing callback.
 
void publishLaserScan ()
 Publish a simulated laser scan from the map.
 
rcl_interfaces::msg::SetParametersResult validateParameterUpdatesCallback (const std::vector< rclcpp::Parameter > &parameters)
 Validate dynamic parameter changes (pre-set callback) More...
 
void updateParametersCallback (const std::vector< rclcpp::Parameter > &parameters)
 Apply validated dynamic parameter changes (post-set callback) More...
 
void getBaseToLaserTf ()
 Look up the static transform from base to laser frame.
 
void getMap ()
 Request the map from the map server.
 
void publishTransforms (geometry_msgs::msg::TransformStamped &map_to_odom, geometry_msgs::msg::TransformStamped &odom_to_base_link)
 Publish map->odom and odom->base_link transforms.
 
void publishOdometry (const geometry_msgs::msg::TransformStamped &odom_to_base_link)
 Publish nav_msgs::Odometry from the current odom->base transform.
 
std::tuple< double, double, double > getLaserPose ()
 Compute the laser pose in the map frame.
 
void getLaserScan (int num_samples, sensor_msgs::msg::LaserScan &scan_msg)
 Raycast the map to fill a LaserScan message. More...
 
- Protected Member Functions inherited from nav2::LifecycleNode
void printLifecycleNodeNotification ()
 Print notifications for lifecycle node.
 
void register_rcl_preshutdown_callback ()
 
void runCleanups ()
 

Static Protected Member Functions

static geometry_msgs::msg::Quaternion addYawToQuat (const geometry_msgs::msg::Quaternion &quaternion, double yaw_to_add)
 Add a yaw rotation to a quaternion. More...
 

Protected Attributes

double update_dur_
 
std::string base_frame_id_
 
std::string map_frame_id_
 
std::string odom_frame_id_
 
std::string scan_frame_id_
 
double odom_publish_dur_
 
double scan_publish_dur_
 
bool publish_map_odom_tf_
 
double scan_range_min_
 
double scan_range_max_
 
double scan_angle_min_
 
double scan_angle_max_
 
double scan_angle_increment_
 
bool use_inf_
 
double scan_noise_std_
 
bool publish_scan_
 
bool publish_clock_
 
double speed_factor_
 
std::optional< geometry_msgs::msg::Twist > curr_cmd_vel_
 
rclcpp::Time curr_cmd_vel_time_
 
bool has_initial_pose_ {false}
 
geometry_msgs::msg::Pose initial_pose_
 
bool has_map_ {false}
 
nav_msgs::msg::OccupancyGrid map_
 
bool has_base_to_laser_ {false}
 
tf2::Transform tf_base_to_laser_
 
std::mt19937 rng_ {std::random_device{}()}
 
geometry_msgs::msg::TransformStamped t_map_to_odom_
 
geometry_msgs::msg::TransformStamped t_odom_to_base_link_
 
nav2::TransformBroadcaster::SharedPtr tf_broadcaster_
 
nav2::TransformBuffer::SharedPtr tf_buffer_
 
nav2::TransformListener::SharedPtr tf_listener_
 
nav2::Subscription< geometry_msgs::msg::PoseWithCovarianceStamped >::SharedPtr initial_pose_sub_
 
std::unique_ptr< nav2_util::TwistSubscribercmd_vel_sub_
 
nav2::Publisher< nav_msgs::msg::Odometry >::SharedPtr odom_pub_
 
nav2::Publisher< sensor_msgs::msg::LaserScan >::SharedPtr scan_pub_
 
nav2::ServiceClient< nav_msgs::srv::GetMap >::SharedPtr map_client_
 
rclcpp::TimerBase::SharedPtr setup_timer_
 
rclcpp::TimerBase::SharedPtr timer_
 
rclcpp::TimerBase::SharedPtr odom_timer_
 
rclcpp::TimerBase::SharedPtr scan_timer_
 
std::unique_ptr< ClockPublisherclock_publisher_
 
rclcpp::node_interfaces::OnSetParametersCallbackHandle::SharedPtr param_validator_
 
rclcpp::node_interfaces::PostSetParametersCallbackHandle::SharedPtr param_updater_
 
- Protected Attributes inherited from nav2::LifecycleNode
std::unique_ptr< rclcpp::PreShutdownCallbackHandle > rcl_preshutdown_cb_handle_ {nullptr}
 
std::shared_ptr< bond::Bond > bond_ {nullptr}
 
double bond_heartbeat_period {0.1}
 
rclcpp::TimerBase::SharedPtr autostart_timer_
 

Additional Inherited Members

- Public Types inherited from nav2::LifecycleNode
using SharedPtr = std::shared_ptr< nav2::LifecycleNode >
 
using WeakPtr = std::weak_ptr< nav2::LifecycleNode >
 
using SharedConstPointer = std::shared_ptr< const nav2::LifecycleNode >
 

Detailed Description

A loopback simulator that replaces a physics simulator to create a frictionless, inertialess, and collisionless simulation environment. It accepts cmd_vel messages and publishes odometry & TF messages based on the cumulative velocities received to mimic global localization and simulation. It also accepts initialpose messages to set the initial pose of the robot.

Definition at line 59 of file loopback_simulator.hpp.

Constructor & Destructor Documentation

◆ LoopbackSimulator()

nav2_loopback_sim::LoopbackSimulator::LoopbackSimulator ( const rclcpp::NodeOptions &  options = rclcpp::NodeOptions())
explicit

Construct a LoopbackSimulator node.

Parameters
optionsNode options

Definition at line 34 of file loopback_simulator.cpp.

Member Function Documentation

◆ addYawToQuat()

geometry_msgs::msg::Quaternion nav2_loopback_sim::LoopbackSimulator::addYawToQuat ( const geometry_msgs::msg::Quaternion &  quaternion,
double  yaw_to_add 
)
staticprotected

Add a yaw rotation to a quaternion.

Parameters
quaternionInput quaternion
yaw_to_addYaw angle to add in radians
Returns
Resulting quaternion

Definition at line 423 of file loopback_simulator.cpp.

Referenced by timerCallback().

Here is the caller graph for this function:

◆ getLaserScan()

void nav2_loopback_sim::LoopbackSimulator::getLaserScan ( int  num_samples,
sensor_msgs::msg::LaserScan &  scan_msg 
)
protected

Raycast the map to fill a LaserScan message.

Parameters
num_samplesNumber of ray samples
scan_msgOutput scan message to populate

Definition at line 452 of file loopback_simulator.cpp.

References getLaserPose().

Referenced by publishLaserScan().

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

◆ updateParametersCallback()

void nav2_loopback_sim::LoopbackSimulator::updateParametersCallback ( const std::vector< rclcpp::Parameter > &  parameters)
protected

Apply validated dynamic parameter changes (post-set callback)

Parameters
parametersThe parameters that were set

Definition at line 535 of file loopback_simulator.cpp.

Referenced by on_configure().

Here is the caller graph for this function:

◆ validateParameterUpdatesCallback()

rcl_interfaces::msg::SetParametersResult nav2_loopback_sim::LoopbackSimulator::validateParameterUpdatesCallback ( const std::vector< rclcpp::Parameter > &  parameters)
protected

Validate dynamic parameter changes (pre-set callback)

Parameters
parametersThe parameters being set
Returns
Result indicating whether the parameter change is accepted

Definition at line 517 of file loopback_simulator.cpp.

Referenced by on_configure().

Here is the caller graph for this function:

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