Skip to content

Tutorial 4: Using the Process Manager

Mitch Pryor edited this page May 1, 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, below a version of the C++ demo application (explanations will follow) process_manager_client.cpp in the tutorials_temoto_config/src folder.

#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 tutorials_temoto_config temoto.launch

Open up another terminal and run:

# The '__ns' argument places all the services and topics this node has under a namespace. Without it the 'process_manager_client' is not able to reach TeMoto
rosrun tutorials_temoto_config process_manager_client __ns:=tutorials_temoto_config

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 and 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

As a standard with ROS packages, you have to modify the CMakeLists.txt and package.xml files

CMakeLists

Add temoto_process_manager to the find_package macro and declare it as a dependency of your custom package. The simplest way to make your custom targets (executables, libraries) link with temoto_process_manager is to use the catkin_LIBRARIES variable:

find_package(catkin REQUIRED COMPONENTS
  <other-packages>
  temoto_process_manager
)

catkin_package(
  ...
  CATKIN_DEPENDS <other-deps> temoto_process_manager 
)

add_executable(my_custom_exec
  src/my_custom_exec.cpp
)
add_dependencies(my_custom_exec
  ${catkin_EXPORTED_TARGETS} 
  ${${PROJECT_NAME}_EXPORTED_TARGETS}
)
target_link_libraries(my_custom_exec
  ${catkin_LIBRARIES}
)

package.xml

Add temoto_process_manager as a dependency:

<depend>temoto_process_manager</depend>

Clone this wiki locally