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

ROS subscriber integration

asked 2012-02-27 08:00:53 -0500

bzt gravatar image

updated 2014-01-28 17:11:30 -0500

ngrennan gravatar image


I have a 32-bit C program that sends data over UDP to a windows GUI. I need to integrate a simple ros subscriber node into the program to subscribe to a node publishing a joy message. I've had no luck following the tutorials or methods I've been able to find. What is the normal method for doing such a task?

I've checked a couple of Q/A already, such as: with no luck.


After making a new project, adding the file to the CMakeLists.txt, and adding ros.h to the c program, I get the following error:

In file included from /opt/ros/electric/stacks/ros_comm/utilities/rostime/include/ros/time.h:53:0, from /opt/ros/electric/stacks/ros_comm/clients/cpp/roscpp/include/ros/ros.h:38, from .../ros_workspace/project_1/src/project_1.c:26:


fatal error: string: No such file or directory

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2012-02-27 08:16:57 -0500

dornhege gravatar image

When porting code to ROS you can try to port the software fully or to just write a ROS interface that translates ROS request and calls some interface functions in the software.

When I port code to ROS, what I usually do is:

  1. Create a ROS package using roscreate-pkg.
  2. Copy the source code to the package and make it compile (without any ROS interfacing). This should result in the same program as before.
  3. Add ros stuff, i.e. ros::init, spinning, subscribers/publishers, maybe switch in some ROS features, i.e. using ros::Time, ROS_INFO, etc.
edit flag offensive delete link more


Gotcha, the program works up to step 3, where I need to include ros/ros.h right? How do I include ros.h? Will i make the program with "gcc progam.c -m32" or with a "rosmake program" command ?

bzt gravatar image bzt  ( 2012-02-27 08:26:26 -0500 )edit

In step 3, you'll need to use rosmake.

joq gravatar image joq  ( 2012-02-27 08:38:54 -0500 )edit

I've edited my original post to reflect the error I'm now getting after attempting this method.

bzt gravatar image bzt  ( 2012-02-27 08:49:17 -0500 )edit

This is only a suspicion, but you are using a C program in a .c file. This will automatically run gcc (not g++) and thus there is no string (c++) only. Do you need the program to be C or can it be compiled as c++ (using C only code) - then just rename the file to end in .cpp and see.

dornhege gravatar image dornhege  ( 2012-02-27 12:01:06 -0500 )edit

Fixing the headers with "extern "C" {(headers here)}" and converting some data types to c++ solved the issue! (Changing the extension to .cpp) Thanks!

bzt gravatar image bzt  ( 2012-02-28 08:20:58 -0500 )edit

Question Tools


Asked: 2012-02-27 08:00:53 -0500

Seen: 1,793 times

Last updated: Feb 27 '12