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

Publish data of an existing C++ project into a ROS topic

asked 2014-05-12 04:17:31 -0500

jamman gravatar image

updated 2014-05-12 04:36:13 -0500

Hi, I'm using a pretty complex c++ program from which I want to publish data as a ROS topic. I'd like not to change the existing program, I mean not much. What's the simplest/best way to do it.

Cheers

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2014-05-13 19:02:04 -0500

Mehdi. gravatar image

You don't need to create a ROS Package in order to publish messages. I also had to find a way to publish some messages from complex programs without a massive change or complex dependencies. So basically you have two options:

  1. Rosbridge: I consider this to be the most elegant and portable solution. You can publish and subscribe to topics from ANY programming languages that supports websockets. So if you think that you might later want to publish messages from other complex programs that are not in C++, this option is the best for you. More information about it in http://rosbridge.org/doku.php?id=rosb...
  2. Linking roscpp : This is also a solution you could consider. There is no need to learn new things like in the case of rosbridge. You just link the roscpp library and can directly use it in your C++ code, creating a node, subscribing,publishing etc... More details on how to do it in this wonderful tutorial : http://jbohren.com/articles/gentle-ca... Under the section "Building with GNU make" it shows how to build a ros node manually and what libraries you need to link.

I hope this could help.

edit flag offensive delete link more
0

answered 2014-05-12 10:37:43 -0500

sterlingm gravatar image

updated 2014-05-12 10:40:29 -0500

Check http://wiki.ros.org/roscpp/Overview/P...

In terms of code, all that you need is to call ros::init, create a NodeHandle, and create a Publisher to start publishing data. You may have to define some custom .msg files if none of the provided work for your code. You will also need to create a Subscriber to listen to the data and do something with it.

Refer to http://wiki.ros.org/ROS/Tutorials/Cre... to see how to create a ROS package.

edit flag offensive delete link more

Comments

Thank you. Is it mandatory to create a ROS package to use ROS functions ? Because I tried to call ros::init and I added "INCLUDE_DIRECTORIES("/opt/ros/hydro/include/")" in my CMakeLists.txt file and I get "undefined reference to ros::init....". So I'm wondering if that comes from the non use of ROS package.

jamman gravatar image jamman  ( 2014-05-12 22:52:50 -0500 )edit

In all of my ROS packages' CMakeLists.txt, I have target_link_libraries(executable_name ${catkin_LIBRARIES} ). You can try adding that since you have a linking error.

sterlingm gravatar image sterlingm  ( 2014-05-13 03:17:59 -0500 )edit

Question Tools

Stats

Asked: 2014-05-12 04:17:31 -0500

Seen: 1,876 times

Last updated: May 13 '14