ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

You have to set a deadline QoS for both publisher and subscription. Based on your description what you want is to configure the joystick publisher with a deadline QoS. You don't create a new subscription or publisher but you simply configure them to use QoS and to bind it a callback to handle missing deadlines. In your case it could be as follows:

  // create publisher
  rclcpp::QoS qos_profile(10);
  rclcpp::PublisherOptions publisher_options;
  qos_profile.deadline(deadline_duration);
  publisher_options.event_callbacks.deadline_callback =
    [](rclcpp::QOSDeadlineOfferedInfo & event) -> void
    {
      // handle missing deadlines
    };
  publisher_ = this->create_publisher<sensor_msgs::msg::Joy>("joy", qos_profile,  publisher_options);

  // create subscription
  rclcpp::SubscriptionOptions subscription_options;
  subscription_options.event_callbacks.deadline_callback =
  [](rclcpp::QOSDeadlineRequestedInfo & event) -> void
  {
     // handle missing deadlines
  };
   subscription_ = this->create_subscription<sensor_msgs::msg::Joy>("joy", qos_profile, std::bind(&JoyToVel::topic_callback, this, _1), subscription_options);

It's important this QoS is configured on both sides, otherwise, you would get an incompatible QoS error. See:

When the DDS Service ‘matches’ a DataWriter and a DataReader it checks whether the settings are compatible (i.e., offered deadline period<= requested deadline period) if they are not, the two entities are informed (via the listener or condition mechanism) of the incompatibility of the QoS settings and communication will not occur.

Fore more information take a look to this document and this example.