Skip to content

Tutorial 4: Using the Process Manager

Robert edited this page Apr 5, 2023 · 8 revisions

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. The second part of the tutorial shows how you can integrate PM to your custom ROS package. But 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();
}

Run the Example

Open up a terminal and run:

roslaunch my_temoto_config temoto.launch

Open up another terminal and run:

rosrun my_temoto_config process_manager_client __ns:=tutorials

Note: Don't forget to source your catkin workspace

Code Explained

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(10).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::string variable.

ER Manager allows to invoke ROS executables, ROS launch files and other programs. The loadRosResource and loadSysResource methods return a temoto_process_manager::LoadProcess object 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 third std::string variable. The same method can be used to load ROS launch files.

Note that this time the unloadResource was not invoked, as the destructor of pmi object automatically unloads all loaded resources.

Integration details

TODO

Clone this wiki locally