0
$\begingroup$

Rosanswers logo

Hi everyone,

First of all, I just learned about ROS2 so I am not so familiar with it. Also, I apologize for my bad English.

I am now working on how to implement QoS in my subscription. I have a little bit experience on eProsima FastRTPS and I did manage to run publisher and subscriber with QoS policies. Thus, I expected ROS2 works quite the same way. Here I want to have a deadline policy with a callback function. However, I were lost while trying to set up the callback because in FastRTPS, it has publisher/subscriber listener, which handles all the event callback functions. In ROS2, I do not know where and how to put or configure callback function. I had a look in SubscriptionEventCallbacks class but it did not work (maybe I set it wrongly). After searching on internet, I have not had any clue yet.

Below is a part of my code trying to configure QoS (I am also not expert on C++ and I am learning it, so feel free to put any comment):

Listener(): Node("Listener_node") // Constructor
{
rclcpp::QoS qos_profile(10);
std::chrono::milliseconds deadline_time(1000);
qos_profile.deadline(deadline_time);
Subscription = this->create_subscription<std_msgs::msg::String>("topic",qos_profile,std::bind(&Listener::callback,this,std::placeholder::_1));
}

Any recommendation, comment or hint is welcomed!

Thanks


Originally posted by Sapodilla on ROS Answers with karma: 48 on 2020-02-25

Post score: 1


Original comments

Comment by stevemacenski on 2020-02-25:
Can you concisely state what your issue is? Your code sample below looks very reasonable.

Comment by Sapodilla on 2020-02-26:
Hi Steven, sorry for my late response. I already found the solution for my issue a few second before typing this comment :D. To make it a bit more clearly, I want to have a callback function whenever a deadline is missed. After spending some time to going through ROS2 doxygen, it finally works for me :). I will put the answer for those who come across this problem like me.

$\endgroup$

1 Answer 1

1
$\begingroup$

Rosanswers logo

To whoever struggles the same problem as me, for having your callback function for QoS, specify the callback function in rclcpp::SubscriptionOptions.

Good luck!


Originally posted by Sapodilla with karma: 48 on 2020-02-26

This answer was ACCEPTED on the original site

Post score: 2


Original comments

Comment by Gunika on 2020-12-18:
Hello Can you let me know how did you use rclcpp::SubscriptionOptions in the code?

Comment by Gunika on 2020-12-19:
Can you please let me know how did you use the callback in rclcpp::SubscriptionOptions? This is my code for the subscriber: rclcpp::QoS qos_profile(10); std::chrono::milliseconds deadline_time(1000); qos_profile.deadline(deadline_time); rclcpp::SubscriptionOptions subscription_options; subscription_options.event_callbacks.deadline_callback = [](rclcpp::QOSDeadlineRequestedInfo & event) -> void { std::cout << "Connection Lost"; };

  subscription_ = this->create_subscription<std_msgs::msg::String>(
  "topic", 10,subscription_options,qos_profile,std::bind(&MinimalSubscriber::topic_callback, this, _1));
}

Publisher: { rclcpp::QoS qos_profile(10); std::chrono::milliseconds deadline_time(1000); qos_profile.deadline(deadline_time); publisher_ = this->create_publisher<std_msgs::msg::String>("topic", 10,qos_profile); timer_ = this->create_wall_timer( 500ms, std::bind(&MinimalPublisher::t

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.