Use UDP with ROS2

asked 2022-07-11 21:30:54 -0600

KKYY gravatar image

updated 2022-07-14 01:14:06 -0600

I'm a ROS2 beginner. It seems that ROS1 was able to do UDP ros :: TransportHints (). Unreliable ().
But ROS2 doesn't seem to have this function. What should I do when performing UDP connection with ROS2 C++? Also, I understand that something called DDS is available in ROS2, but does it support UDP?

development environment: ubuntu20.04, ROS2 FOXY

UDP subscriber written in ROS1 that I tried to reference below.

   void print_message(const std_msgs::String data){
       ROS_INFO_STREAM("received: " << data);

   int main(int argc, char **argv){
       ros::init(argc, argv, "udp_test_node");
       ros::AsyncSpinner spinner(4);
       ros::NodeHandle private_nh("~");
       ros::Subscriber chatter_sub = private_nh.subscribe("/chatter", 10, print_message,
       while (ros::ok()){
edit retag flag offensive close merge delete