Class robot_interfaces::MonitoredRobotDriver

template<typename Driver>
class MonitoredRobotDriver : public robot_interfaces::RobotDriver<Driver::Action, Driver::Observation>, public robot_interfaces::RobotDriver<Driver::Action, Driver::Observation>

Wrapper for RobotDriver that monitors timing.

Takes a RobotDriver instance as input and forwards all method calls to it. A background loop monitors timing of actions to ensure the following constraints:

  1. The execution of an action does not take longer than max_action_duration_s_ seconds.

  2. The time interval between termination of the previous action and receival of the next one (through apply_action()) does not exceed max_inter_action_duration_s_.

If these timing constraints are not satisfied, the robot will be shutdown, and no more actions from the outside will be accepted.

This wrapper also makes sure that the shutdown() method of the given RobotDriver is called when wrapper is destroyed, so the robot should always be left in a safe state.

Template Parameters:
  • Action

  • Observation

Public Types

typedef std::shared_ptr<Driver> RobotDriverPtr
typedef std::shared_ptr<Driver> RobotDriverPtr

Public Functions

inline MonitoredRobotDriver(RobotDriverPtr robot_driver, const double max_action_duration_s, const double max_inter_action_duration_s)

Starts a thread for monitoring timing of action execution.

Parameters:
  • robot_driver – The actual robot driver instance.

  • max_action_duration_s – Maximum time allowed for an action to be executed.

  • max_inter_action_duration_s – Maximum time allowed between end of the previous action and receival of the next one.

inline ~MonitoredRobotDriver()

Shuts down the robot and stops the monitoring thread.

inline Driver::Action apply_action(const typename Driver::Action &desired_action) final override

Apply desired action on the robot.

If the robot is shut down, no more actions will be applied (the method will just ignore them silently.

Parameters:

desired_action – The desired action.

Returns:

The action that is actually applied on the robot (may differ from desired action due to safety limitations).

inline virtual void initialize() override

Initialize the robot.

Any initialization procedures that need to be done before sending actions to the robot should be done in this method (e.g. homing to find the absolute position).

inline virtual Driver::Action get_idle_action() override

Return action that is safe to apply while the robot is idle.

Typically this can be an action applying zero torque to all joints but it might be more involved depending on the robot (it could, for example, also be an action to hold the joints in place).

The default implementation simply uses the default constructor of Action, assuming that this is safe to use.

inline virtual Driver::Observation get_latest_observation() override

Return the latest observation immediately.

Returns:

Observation

inline virtual std::optional<std::string> get_error() override

Get error message if there is any error.

Uses std::optional for the return type, so an actual string only needs to be created if there is an error. This is relevant as std::string is in general not real-time safe and should thus be avoided. In case of an error this does not matter, as the control loop will be stopped anyway.

Returns:

Returns an error message or std::nullopt if there is no error.

inline virtual void shutdown() final override

Shut down the robot safely.

After shutdown, actions sent by the user are ignored.

inline MonitoredRobotDriver(RobotDriverPtr robot_driver, const double max_action_duration_s, const double max_inter_action_duration_s)

Starts a thread for monitoring timing of action execution.

Parameters:
  • robot_driver – The actual robot driver instance.

  • max_action_duration_s – Maximum time allowed for an action to be executed.

  • max_inter_action_duration_s – Maximum time allowed between end of the previous action and receival of the next one.

inline ~MonitoredRobotDriver()

Shuts down the robot and stops the monitoring thread.

inline Driver::Action apply_action(const typename Driver::Action &desired_action) final override

Apply desired action on the robot.

If the robot is shut down, no more actions will be applied (the method will just ignore them silently.

Parameters:

desired_action – The desired action.

Returns:

The action that is actually applied on the robot (may differ from desired action due to safety limitations).

inline virtual void initialize() override

Initialize the robot.

Any initialization procedures that need to be done before sending actions to the robot should be done in this method (e.g. homing to find the absolute position).

inline virtual Driver::Action get_idle_action() override

Return action that is safe to apply while the robot is idle.

Typically this can be an action applying zero torque to all joints but it might be more involved depending on the robot (it could, for example, also be an action to hold the joints in place).

The default implementation simply uses the default constructor of Action, assuming that this is safe to use.

inline virtual Driver::Observation get_latest_observation() override

Return the latest observation immediately.

Returns:

Observation

inline virtual std::optional<std::string> get_error() override

Get error message if there is any error.

Uses std::optional for the return type, so an actual string only needs to be created if there is an error. This is relevant as std::string is in general not real-time safe and should thus be avoided. In case of an error this does not matter, as the control loop will be stopped anyway.

Returns:

Returns an error message or std::nullopt if there is no error.

inline virtual void shutdown() final override

Shut down the robot safely.

After shutdown, actions sent by the user are ignored.