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

How can I open a new terminal and execute a rosrun command through a cpp program ?

asked 2017-01-19 12:49:14 -0500

bill gravatar image

updated 2017-01-20 00:53:22 -0500

NEngelhard gravatar image

i need a code example

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2017-01-19 15:33:27 -0500

petern3 gravatar image

Not recommended

To run any shell commands from a cpp program, you can use the std::system function. ie

#include <cstdlib>  // I think 'system' is in here?

int main(void) {
    std::system("rosrun [package] [node]");  // replace [package] and [node] with the relevant text

    return EXIT_SUCCESS;
}

This won't work unless the master node is running (i.e you have called roscore or roslaunch first)

Recommended

Normally when you want to start a node, you run all the nodes you'll need in the program using a launch file. Instead of generating new nodes during runtime, you could also create services. The Cpp API gives you basically all the interfaces you'll need.

I would highly recommend doing the tutorials. They take ages, but go a long way to understanding ROS.

Also, before posting a question next time, look for the answer first, and if these don't answer your question, follow the support guidelines. A more descriptive title might be "How to execute rosrun command from cpp", then the informal text can go in the text body.

edit flag offensive delete link more

Comments

thanks you so much ,and i promise that next time i will consider what you wrote and then i will ask something

bill gravatar image bill  ( 2017-01-23 05:33:32 -0500 )edit

No problem, hopefully the tutorials are able to kickstart your project!

petern3 gravatar image petern3  ( 2017-01-23 17:24:06 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2017-01-19 12:49:14 -0500

Seen: 1,192 times

Last updated: Jan 23 '17