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

[Ros2] Creating a UDP socket in a node

asked 2019-08-06 10:43:02 -0500

zipp39 gravatar image

Hi! I am converting my package from ROS1 melodic to ROS2 Dashing and we have a node that functions essentially as a UDP socket to send and receive messages to an external device using boost::asio.

To my understanding, ROS 2 no longer has boost as a dependency and recommends using the std library in C++ to replace most of the boost classes and functions, however C++ std library does not have asio, or socket creation tools for the matter.

So my question is, how can I make nodes send and receive data in ROS 2 without boost? I noticed on Windows 10, asio was a dependency and I was wondering if I can just use asio, and if so, how do I include it and declare it as a dependency in my node?

Or is there another ROS 2 dependency/method that is capable and the standard "ros 2 way" of accomplishing this?

Thanks!

edit retag flag offensive close merge delete

Comments

Not exactly an answer, but ROS2 has asio as dependency, since its built together with Fast-RTPS.

alsora gravatar image alsora  ( 2019-08-06 11:25:50 -0500 )edit

I can't seem to find it in the lib folder. That is what I am looking for but when I try to use find_package(asio REQUIRED) Cmake can't find it. Do you know how I can properly link asio to use asio.hpp as an include?

zipp39 gravatar image zipp39  ( 2019-08-06 12:03:37 -0500 )edit

2 Answers

Sort by » oldest newest most voted
0

answered 2019-08-07 03:11:59 -0500

pavel92 gravatar image

I agree with gvdhoorn, I would suggest using boost::asio if you are familiar with it (install it manually if you dont have it already). Also, there seem to be some problems with just asio. For example, on Ros Index you can find this regarding Windows 10:

CMake Packages Unable to Find asio, tinyxml2, tinyxml, eigen, or log4cxx
We’ve seen, but been unable to identify the root cause, that sometimes the chocolatey packages for asio, tinyxml2, etc. do not add important registry entries and that will cause CMake to be unable to find them when building ROS 2.
It seems that uninstalling the chocolatey packages (with -n if the uninstall fails the first time) and then reinstalling them will fix the issue.

Here is an example CMakeLists.txt of me using boost:asio with ROS2.

find_package(Boost REQUIRED COMPONENTS system)

target_link_libraries(your_node ${PROJECT_NAME} ${Boost_LIBRARIES})

ament_export_dependencies(Boost)
ament_export_libraries(${PROJECT_NAME} ${Boost_LIBRARIES})

For the UDP socket implementation within ROS/ROS2 I have used this so far.

edit flag offensive delete link more
0

answered 2019-08-06 11:26:17 -0500

gvdhoorn gravatar image

ROS 2 no longer has boost as a dependency and recommends using the std library in C++ to replace most of the boost classes and functions

the recommendation would be to use std:: as much as possible, but there are of course situations in which that is impossible (such as the one you find yourself in).

Boost is in no way deprecated, nor are you "forbidden" from using it (or is it made any harder to use Boost in ROS 2 than it is/was in ROS 1).

So my question is, how can I make nodes send and receive data in ROS 2 without boost? I noticed on Windows 10, asio was a dependency and I was wondering if I can just use asio, [..]

There are quite a few socket libraries for C++ other than boost::asio, but if you're familiar with it then I would suggest to just keep using it.

how do I include it and declare it as a dependency in my node?

In exactly the same way as you would do it in ROS 1: by stating it in your package.xml -- dependency declarations haven't changed, and as Boost was never a Catkin package, you'd even still use find_package(Boost REQUIRED COMPONENTS ..).

The same rosdep key is used (ie: boost, or asio for the standalone version).

edit flag offensive delete link more

Comments

It seems like most packages being built for ROS 2 are straying away from Boost.. On Windows and Linux I am having a lot of trouble finding boost using CMakelists.txt since now you have to install boost libraries independent of ROS. So my question is, since asio is being installed with ROS 2, how can I use that with my ROS node?

zipp39 gravatar image zipp39  ( 2019-08-06 11:59:57 -0500 )edit

On Windows and Linux I am having a lot of trouble finding boost using CMakelists.txt since now you have to install boost libraries independent of ROS.

you've always had to do this, there is no difference between ROS 1 and ROS 2 in this case.

Boost was just installed for you by your package manager (on Linux).

find_package(Boost ..) is still the same CMake function.

gvdhoorn gravatar image gvdhoorn  ( 2019-08-15 04:36:12 -0500 )edit

Question Tools

Stats

Asked: 2019-08-06 10:43:02 -0500

Seen: 2,042 times

Last updated: Aug 07 '19