ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
If you are writing in C++ you can use fork and execlp to run a system command such as rosrun or roslaunch:
// this code would be called from the callback method of your button
pid_t pid = 0;
pid = fork();
if (pid < 0) {
ROS_ERROR("Process failed to fork");
exit(-1);
}
else if (pid == 0) { // Child process
execlp( "roslaunch", "roslaunch", "launchfolder", "launchfile.launch",NULL);
// launchfolder is the directory where your launchfile is
exit(1);
}
else { // parent process
launchPID = pid;
}
// Kill the started process when exiting the application (in onExit() and/or onClose() callbacks:
if (launchPID) kill(launchPID, 15);
Using system() instead is much easier, but you don't have any control over the processes you created...