Ask Your Question
0

ROS2 QoS callback function

asked 2020-02-25 06:26:57 -0500

Sapodilla gravatar image

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

edit retag flag offensive close merge delete

Comments

Can you concisely state what your issue is? Your code sample below looks very reasonable.

stevemacenski gravatar image stevemacenski  ( 2020-02-25 10:54:04 -0500 )edit
1

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.

Sapodilla gravatar image Sapodilla  ( 2020-02-26 09:30:25 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2020-02-26 09:35:33 -0500

Sapodilla gravatar image

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

Good luck!

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2020-02-25 06:26:57 -0500

Seen: 37 times

Last updated: Feb 26