Ask Your Question
1

How to run ROS commands from C++ application?

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

this post is marked as community wiki

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

updated 2014-01-28 17:09:42 -0500

ngrennan gravatar image

(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 delete

Comments

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

Asomerville ( 2012-08-06 07:09:08 -0500 )edit

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

domikilo ( 2013-12-18 21:02:07 -0500 )edit

2 answers

Sort by ยป oldest newest most voted
3

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

this post is marked as community wiki

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

updated 2011-05-22 20:41:56 -0500

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 publish link more
3

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

this post is marked as community wiki

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

updated 2011-07-03 18:57:33 -0500

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 publish link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

[hide preview]

Stats

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

Seen: 728 times

Last updated: Aug 06 '12