Ask Your Question
1

How to run ROS commands from C++ application?

asked 2011-05-22 05: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 2012-08-06 11:52:20 -0500

Asomerville gravatar image Asomerville
2061 46 72 110
http://www.resquared.com/

(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 12:09:08 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted
3

answered 2011-05-23 01: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-23 01:41:56 -0500

Felix Endres gravatar image Felix Endres flag of Germany
3407 13 32 63
http://www.informatik.uni...

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 23: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 23:57:33 -0500

KoenBuys gravatar image KoenBuys
2024 16 28 52
http://people.mech.kuleuv...

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 your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

subscribe to rss feed

Stats

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

Seen: 467 times

Last updated: Aug 06 '12