Class robot_interfaces::example::Driver

class Driver : public robot_interfaces::RobotDriver<Action, Observation>, public robot_interfaces::RobotDriver<Action, Observation>

Example Robot Driver.

Send command to the robot and read observation from the robot. The DOF positions simply becomes the ones set by the latest action, capped between a min and a max value.

Public Functions

inline Driver(int min, int max)
inline virtual void initialize()

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 Action apply_action(const Action &action_to_apply)

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

inline virtual Observation get_latest_observation()

Return the latest observation immediately.

Returns:

Observation

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

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

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 Driver(int min, int max)
inline virtual void initialize()

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 Action apply_action(const Action &action_to_apply)

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

inline virtual Observation get_latest_observation()

Return the latest observation immediately.

Returns:

Observation

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

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

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.