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

How to run ROS commands from C++ application?

asked 2011-05-22 00:10:14 -0600

this post is marked as community wiki

This post is a wiki. Anyone with karma >75 is welcome to improve it.

(Original Author) want(s) to run ROS commands, like e.g. $ ROSCORE, from a C++ application. The following example does not work:

#include <stdlib.h>   
int main()    
{    
    system("/opt/ros/diamondback/ros/bin/roscore");  
    return 0;    
}

Execution results in the following message:

Traceback (most recent call last):    
  File "/opt/ros/diamondback/ros/bin/roscore", line 34, in <module>    
    from ros import roslaunch    
ImportError: No module named ros

Original Author was using Ubuntu 10.04.
Original Author notes that roscore successfully launches the master when executed from the command line

edit retag flag offensive close merge delete

Comments

I accidentally pushed this to the top by correcting the formatting. :P

Asomerville gravatar image Asomerville  ( 2012-08-06 07:09:08 -0600 )edit

you must use system("/opt/ros/diamondback/bin/roscore");

domikilo gravatar image domikilo  ( 2013-12-18 21:02:07 -0600 )edit

2 Answers

Sort by ยป oldest newest most voted
4

answered 2011-05-22 20:41:56 -0600

this post is marked as community wiki

This post is a wiki. Anyone with karma >75 is welcome to improve it.

Maybe it is a problem with missing environment variables (python path?). You could try to run bash with the command as parameter, e.g. something like bash -i -c "/opt/ros/diamondback/ros/bin/roscore". -i makes the bash read ~/.bashrc where I assume you source /opt/ros/diamondback/setup.sh.

edit flag offensive delete link more
3

answered 2011-07-03 18:57:33 -0600

this post is marked as community wiki

This post is a wiki. Anyone with karma >75 is welcome to improve it.

Why do you want to launch this from inside a program? If you include your program in a launch file the roscore will also be launched.

edit flag offensive delete link more

Question Tools

Stats

Asked: 2011-05-22 00:10:14 -0600

Seen: 3,663 times

Last updated: Aug 06 '12