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

Shell Script and C Program in ROS

asked 2012-07-23 00:21:06 -0500

updated 2014-01-28 17:13:06 -0500

ngrennan gravatar image


I have been using ROS now for quiet a good time and have been able to achieve several applications. However, recently i came up with a new requirement of having the capability to make ROS run shell scripts and C programs. Although I have some idea on this using some crude Linux methods, I would like to know if there is any formal method of being able to do this?

I have a custom code for a specific application written in C and the operations of the code is invoked using shell commands. I would like to incorporate this into ROS environment to complete my task.

Any relevant information could help me on this.

I am using Ubuntu 12.04 with ROS-fuerte and another system with Ubuntu 11.10 and ROS-electric.


edit retag flag offensive close merge delete


If you mean using something like system(), I don't see why you consider that crude.

PerkinsJames gravatar image PerkinsJames  ( 2012-07-23 06:05:35 -0500 )edit

I said so just because I thought it would be more a linux way than a ROS way. But if there was no other option I would go with the system() function.

SivamPillai gravatar image SivamPillai  ( 2012-07-23 09:46:59 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2012-07-23 01:27:43 -0500

dornhege gravatar image

Depending on what you intent to do I see two possibilities:

  1. Call your C program/shell script from ROS, either by system() within a node or you can also rosrun/roslaunch non-ROS executables.

  2. Integrate your code with ROS by building it as a ROS package, writing a ROS interface or making it available as a library.

Some hints might be here:

edit flag offensive delete link more


could you please expand more on (2). My code is itself a collection of c-files and headers whcih requires command line arguments as the input filename, does processing and generates a few output files... These output files would be required by me in further stages of my ROS nodes.

SivamPillai gravatar image SivamPillai  ( 2012-07-23 05:43:06 -0500 )edit

2 means, you basically build your code with ROS. It doesn't even require to integrate ROS with the code. Usually I'd start with roscreate-pkg of an empty roscpp package, put my sources in and enter them in CMakeLists.txt. Normally this should then compile already as a package.

dornhege gravatar image dornhege  ( 2012-07-24 00:09:33 -0500 )edit

You could now also setup launch files that provide the correct command line arguments, possibly relative to packages, etc.

dornhege gravatar image dornhege  ( 2012-07-24 00:10:43 -0500 )edit

If you need to regularly call this, a system() call is also OK. I'd still recommend building it as a package though as then you can use rosrun in the system call and are independent of hardcoded paths.

dornhege gravatar image dornhege  ( 2012-07-24 00:12:24 -0500 )edit

If you really want the ROS way, scrap the input/output files and send around messages instead.

dornhege gravatar image dornhege  ( 2012-07-24 00:13:17 -0500 )edit

That sounds pretty interesting and hopeful. I would try to do such things and would update if i get stuck up somewhere :) Sending around messages instead of files would mean making a lot of modification in my source files and I would want to avoid that for now. Thanks.

SivamPillai gravatar image SivamPillai  ( 2012-07-24 03:00:31 -0500 )edit

Usually one only writes a ros interface wrapper file that uses the library API. If that is possible depends on your code.

dornhege gravatar image dornhege  ( 2012-07-24 06:44:37 -0500 )edit

DOMHEGE, How to do 1st method plz give me one example. Means how to call C on ROS

KDROS gravatar image KDROS  ( 2014-12-31 00:39:15 -0500 )edit

Question Tools


Asked: 2012-07-23 00:21:06 -0500

Seen: 1,398 times

Last updated: Jul 23 '12