Template Class ROSServiceWrapper

Class Documentation

template<typename SrvT, typename CallbackT>
class ROSServiceWrapper

A wrapper class for ROS services that simplifies the creation and management of a service server.

Template Parameters:
  • SrvT – The type of the service message, derived from a .srv file by the ROS build system.

  • CallbackT – The type of the callback function to be invoked on service request. Currently supported callback function signatures include void() and void(bool).

Public Types

using SrvSharedPtr = typename rclcpp::Service<SrvT>::SharedPtr
using SrvRequestConstPtr = typename SrvT::Request::ConstSharedPtr
using SrvResponsePtr = typename SrvT::Response::SharedPtr

Public Functions

inline ROSServiceWrapper(const CallbackT &callback)

Constructs a ROSServiceWrapper object with the specified callback function.

Parameters:

callback – The callback function to be called whenever the service receives a request. Currently supported callback function signatures include void() and void(bool).

void RegisterService(const rclcpp::Node::SharedPtr node, const std::string &service_name, rclcpp::CallbackGroup::SharedPtr group = nullptr, const rclcpp::QoS &qos = rclcpp::ServicesQoS())

Register and advertises the service with the specified name under the given ROS node.

Parameters:
  • node – The shared pointer to the ROS node under which the service will be advertised.

  • service_name – The name of the service. This is the name under which the service will be advertised over ROS.

  • group – The shared pointer to the node’s callback group. Defaults to nullptr, which indicates that the node’s default callback group will be used.

  • qos – The QoS settings for the service. Defaults to ServicesQoS.