How can I open a new terminal and execute a rosrun command through a cpp program ?
i need a code example
ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
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)
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.
Asked: 2017-01-19 12:49:14 -0500
Seen: 1,225 times
Last updated: Jan 23 '17