Class robot_interfaces::RobotDriver

template<typename TAction, typename TObservation>
class RobotDriver

Driver for interfacing the actual robot hardware or simulation.

Interface to the robot used by the subsequent classes. Any robot (be it real or simulation) has to derive from this class and implement the functions apply_action(), get_latest_observation() and shutdown(). This Base class provides some timing logic around those three functions. It makes sure that after the first call of apply_action(), it is always called again after some specified time, otherwise the shutdown() method will be called. This Base class also makes sure that the apply_action() function itself does not take more time than expected.

Template Parameters:
  • Action

  • Observation

Public Types

typedef TAction Action
typedef TObservation Observation
typedef TAction Action
typedef TObservation Observation

Public Functions

inline virtual ~RobotDriver()
virtual void initialize() = 0

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).

virtual Action apply_action(const Action &desired_action) = 0

Apply action immediately and block until it is executed.

This method must apply the desired_action immediately when it is called, and only return once the action has been executed completely. This way we can accommodate both simulators and real robots with this interface.

Parameters:

desired_action – The action we want to apply.

Returns:

The action that was actually applied (since due to safety reasons it might not be possible to apply the desired action).

virtual Observation get_latest_observation() = 0

Return the latest observation immediately.

Returns:

Observation

virtual std::optional<std::string> get_error() = 0

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.

virtual void shutdown() = 0

Shut down the robot safely.

Use this method if your robot needs to perform some action when shutting down, e.g. to move it to a defined rest position.

inline virtual Action get_idle_action()

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 ~RobotDriver()
virtual void initialize() = 0

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).

virtual Action apply_action(const Action &desired_action) = 0

Apply action immediately and block until it is executed.

This method must apply the desired_action immediately when it is called, and only return once the action has been executed completely. This way we can accommodate both simulators and real robots with this interface.

Parameters:

desired_action – The action we want to apply.

Returns:

The action that was actually applied (since due to safety reasons it might not be possible to apply the desired action).

virtual Observation get_latest_observation() = 0

Return the latest observation immediately.

Returns:

Observation

virtual std::optional<std::string> get_error() = 0

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.

virtual void shutdown() = 0

Shut down the robot safely.

Use this method if your robot needs to perform some action when shutting down, e.g. to move it to a defined rest position.

inline virtual Action get_idle_action()

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.