-
Notifications
You must be signed in to change notification settings - Fork 0
Tutorial 4: Using the Process Manager
Process Manager is a ROS node, which can dynamically invoke programs, including ROS executables, ROS launch files and regular executables. Running programs are then monitored for process failures (via segmentation faults, unexpected shutdowns, etc), which are reported to the consumers of the failed resource.
This is a simple demonstration of Process Manager (PM) from client's perspective. In this example the PM is used to load a ROS related program (rqt_graph) and also regular Ubuntu program (Gnome calcultator), but you can modify the example to load other components that may relate better to your use-case. First, here's the whole C++ demo application (explanations will follow):
#include "ros/ros.h"
#include "temoto_process_manager/process_manager_interface.hpp"
void resourceFailureCallback(temoto_process_manager::LoadProcess load_process_msg)
{
ROS_WARN_STREAM("The following resource stopped unexpectedly\n" << load_process_msg.request);
}
int main(int argc, char** argv)
{
ros::init(argc, argv, "test_er_client_node");
temoto_process_manager::ProcessManagerInterface pmi(true);
pmi.registerUpdateCallback(resourceFailureCallback);
ROS_INFO("Loading gnome-calculator");
temoto_process_manager::LoadProcess load_process_msg = pmi.loadSysResource("gnome-calculator");
ros::Duration(5).sleep();
ROS_INFO("Unloading gnome-calculator");
pmi.unloadResource(load_process_msg);
ROS_INFO("Loading rqt_graph");
pmi.loadRosResource("rqt_graph", "rqt_graph");
ros::Duration(5).sleep();
}Open up a terminal and run:
roslaunch tutorials_temoto_config temoto.launchOpen up another terminal and run:
rosrun tutorials_temoto_config process_manager_client __ns:=tutorialsNote: Don't forget to source your catkin workspace
temoto_process_manager::ProcessManagerInterface pmi(true);Create PM Interface object that provides a simplified API for communicating with the Process Manager. The boolean "true", that's passed to the constructor of PM interface tells it whether it should be initialised immediately, or that's done later by the user.
pmi.registerUpdateCallback(resourceFailureCallback);You can register a custom routine (not required) where resource failures are reported.
temoto_process_manager::LoadProcess load_process_msg = pmi.loadSysResource("gnome-calculator"); ros::Duration(5).sleep(); pmi.unloadResource(load_process_msg);Load the Gnome calculator as an example of a regular system program. Additional arguments can also be passed as a second
std::stringvariable.ER Manager allows to invoke ROS executables, ROS launch files and other programs. The
loadRosResourceandloadSysResourcemethods return atemoto_process_manager::LoadProcessobject which contains the details regarding the query. This can be later used to unload the resource.
pmi.loadRosResource("rqt_graph", "rqt_graph");Load a ROS program an example of a ROS executable (regularly invoked via
rosrun). The first parameter indicates the ROS package name and the second indicates the executable. Additional arguments can also be passed as a thirdstd::stringvariable. The same method can be used to load ROS launch files.Note that this time the
unloadResourcewas not invoked, as the destructor ofpmiobject automatically unloads all loaded resources.