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 |
i need a code example
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,192 times
Last updated: Jan 23 '17
How could I use "ROS" commands in a bash file ?
Ar Drone 2.0 angular movements [closed]
ROS commands from c++ applications
What are some examples of the code I'd write that be for capturing sounds or acceleration?
Start multiple nodes at boot and give access to ports
Problem in AR. Drone Movement (angular.z)
I have a python program. How can I integrate ROS data in it?