ROS2 Architecture (rclcpp, rcl, rmw)

asked 2019-10-11 02:53:33 -0500

jlepers gravatar image

Hi, I am a beginner with ROS2 and C++ and I can use some help understanding how the architecture of ROS 2 works. I want to implement a QoS-event into a simple chatter program and with my basic knowledge I can make following graph:

CODE (publisher.cpp) ==> RCLCPP(qos_event.cpp) this includes (qos_event.hpp) ==> RCL (event.c) this includes (event.h) ==> RMW (event.c) this includes (event.h) ==> DDS

But I have some questions about this:

1) If I understand it right, header files are used as some kind of library. So if you include them in your program you can use all the functions you want. This means I don't need to use this code in my program but I only need to implement those functions? Are the following files: qos_event.cpp / rcl event.c / rmw event.c examples of code that I can use into my own program ?

2) The Quality of Service (QoS) settings are declared in the Ros middelware (rmw). If I want to use one of those events, can I just directly use the rmw/event.h header file or do I need to respect the architecture and is it only possible to implement rclcpp code in your program ?

Thanks a lot !

edit retag flag offensive close merge delete

Comments

Theoretically you can work on top of whichever layer you want. For the average ROS user I think working on the rclcpp layer is sufficient. The functions you use at rclcpp level will actually call the rcl and rmw layer functions for you. Registering a subscriber at rclcpp level is a lot easier than at rcl level.

MCornelis gravatar imageMCornelis ( 2019-10-11 03:29:36 -0500 )edit

You can set QoS settings when creating a publisher or subscriber something like this:

static const rclcpp::QoS qos = rclcpp::QoS(10)
                               .reliability(RMW_QOS_POLICY_RELIABILITY_BEST_EFFORT)
                               .durability(RMW_QOS_POLICY_DURABILITY_TRANSIENT_LOCAL);
...
auto node = std::make_shared<rclcpp::Node>("node");
auto pub = node->create_publisher<String>("topic_0", qos);
auto sub= node->create_subscription<String>("topic_0", qos, [](String::SharedPtr) {});

for this you just need to include rclcpp

#include <rclcpp/rclcpp.hpp>
MCornelis gravatar imageMCornelis ( 2019-10-11 03:33:13 -0500 )edit

This worked for me:

auto node = rclcpp::Node::make_shared("publisher");

static const rmw_qos_profile_t qos_profile_1 =
{
     RMW_QOS_POLICY_HISTORY_KEEP_LAST, 0,
     RMW_QOS_POLICY_RELIABILITY_RELIABLE,
     RMW_QOS_POLICY_DURABILITY_VOLATILE,
    3
};

auto publisher1 = node->create_publisher<std_msgs::msg::String>("topic1", qos_profile_1);
jlepers gravatar imagejlepers ( 2019-10-11 03:44:32 -0500 )edit

I guess I directly use the rmw/event.h header file here. But now I want to implement the deadline_missed event and I think it is important to know how to properly form this event.

jlepers gravatar imagejlepers ( 2019-10-11 03:49:59 -0500 )edit

If you say that it is easier to implement code from the rclcpp library: (qos_event.hpp code)

struct SubscriptionEventCallbacks
{
  QOSDeadlineRequestedCallbackType deadline_callback;
  QOSLivelinessChangedCallbackType liveliness_callback;
};


QOSEventHandler(
    const EventCallbackT & callback,
    InitFuncT init_func,
    ParentHandleT parent_handle,
    EventTypeEnum event_type)
  : event_callback_(callback)
  {
    event_handle_ = rcl_get_zero_initialized_event();
    rcl_ret_t ret = init_func(&event_handle_, parent_handle, event_type);
    if (ret != RCL_RET_OK) {
      rclcpp::exceptions::throw_from_rcl_error(ret, "could not create event");
    }
  }

This could be code that automaticaly uses the rcl and rmw layers. Right ?

jlepers gravatar imagejlepers ( 2019-10-11 04:17:55 -0500 )edit

https://design.ros2.org/articles/ros_... It could be useful for you to have a look at this. Normally a new user should be able to work with ROS2 without having to leave "user-land". ROS2 is designed in such a way that the underlying system can be treated as a blackbox. Where the user only has to interact with rclcpp or rclpy. HOWEVER, not all of DDS' functionality has been exposed to the top-layer (more and more is being exposed in newer releases). So for very specific cases, a more advanced user could decide to dive deeper and directly address the lower level layers.

MCornelis gravatar imageMCornelis ( 2019-10-11 04:29:10 -0500 )edit

What is your goal? If you just want to use ROS2 and play with QoS settings, I would advise you to look at some tutorials and just set different QoS settings at rclcpp level. If you are truly interested in the inner workings of ROS2 and how all the layers work together then you will need quite a lot of time and I honestly think that for 99% of people it will not have much added value.

MCornelis gravatar imageMCornelis ( 2019-10-11 04:43:20 -0500 )edit

Have you ever implemented a qos-event ?

   RMW_EVENT_LIVELINESS_CHANGED,
   RMW_EVENT_REQUESTED_DEADLINE_MISSED,
   RMW_EVENT_LIVELINESS_LOST,
   RMW_EVENT_OFFERED_DEADLINE_MISSED,

I only want to play with those QoS settings (I already succeeded to do so), but i would like to implement those events. And I am afraid that I need to learn the inner workings of ROS2 before being able to use them, because I haven't found any example of this already. Thanks for your time !

jlepers gravatar imagejlepers ( 2019-10-11 05:10:14 -0500 )edit