sas
Modularised monitoring, logging, and control of robots.
Loading...
Searching...
No Matches
marinholab::sas::core::RobotDriver Class Referenceabstract

Abstract interface for robot hardware drivers. More...

#include <sas_robot_driver.hpp>

Inheritance diagram for marinholab::sas::core::RobotDriver:
marinholab::sas::core::RobotDriverExample marinholab.sas.core.example_robot_driver_subclass.ExampleRobotDriver sas::RobotDriverCoppeliaSim sas::RobotDriverKuka sas::RobotDriverROSComposer sas::RobotDriverUR sas_robot_driver_gazebo.sas_robot_driver_gazebo.RobotDriverGazebo sas_robot_driver_subclass_example_py.ExampleRobotDriver

Public Types

enum class  Functionality {
  None =0 , PositionControl , VelocityControl , ForceControl ,
  Homing , ClearPositions , Watchdog
}
 Enumeration of optional driver functionalities.

Public Member Functions

virtual ~RobotDriver ()
 Virtual destructor for RobotDriver.
virtual Eigen::VectorXd get_joint_positions ()=0
 Get current joint positions.
virtual void set_target_joint_positions (const Eigen::VectorXd &set_target_joint_positions_rad)=0
 Set target joint positions.
virtual Eigen::VectorXd get_joint_velocities ()
 Get current joint velocities.
virtual void set_target_joint_velocities (const Eigen::VectorXd &set_target_joint_velocities)
 Set target joint velocities.
virtual Eigen::VectorXd get_joint_torques ()
 Get current joint torques.
virtual void set_target_joint_torques (const Eigen::VectorXd &set_target_joint_torques)
 Set target joint torques.
virtual std::tuple< Eigen::VectorXd, Eigen::VectorXd > get_joint_limits ()
 Get joint limits (min, max).
virtual void set_joint_limits (const std::tuple< Eigen::VectorXd, Eigen::VectorXd > &joint_limits)
 Set joint limits (min, max).
void watchdog_start (const std::chrono::nanoseconds &period)
 Start the watchdog thread with the given period.
void watchdog_trigger (const std::chrono::time_point< std::chrono::system_clock, std::chrono::nanoseconds > &time_point_from_the_client, const std::chrono::time_point< std::chrono::system_clock, std::chrono::nanoseconds > &time_point_from_the_server, const bool &status)
 Trigger the watchdog with timestamps from client/server and the current status.
void watchdog_set_maximum_acceptable_delay (const double &max_acceptable_delay)
 Set the maximum acceptable delay for the watchdog (seconds).
void check_for_watchdog_exceptions ()
 Check for exceptions thrown by the watchdog thread and rethrow if present.
virtual void connect ()=0
 Connect to the underlying robot/hardware.
virtual void disconnect ()=0
 Disconnect from the underlying robot/hardware.
virtual void initialize ()=0
 Initialize the driver resources.
virtual void deinitialize ()=0
 Deinitialize the driver resources.
void set_control_loop_callback (std::function< void()> callback)
 Set the control loop callback function.
void execute_control_loop_callback ()
 Execute the control loop callback if it has been set.
bool control_loop_callback_is_set ()
 Check if a control loop callback has been set.

Protected Member Functions

void _watchdog_thread_function ()
 RobotDriver::_watchdog_thread_function throws an exception if the elapsed time since the last trigger exceeds the specified period.
 RobotDriver (const std::shared_ptr< ShutdownSignaler > &shutdown_signaler_)
 RobotDriver (std::atomic_bool *break_loops)
 RobotDriver (const RobotDriver &)=delete

Protected Attributes

std::atomic_bool * break_loops_
std::shared_ptr< ShutdownSignaler > shutdown_signaler_
std::tuple< Eigen::VectorXd, Eigen::VectorXd > joint_limits_
Eigen::VectorXd joint_velocities_
Eigen::VectorXd joint_torques_
std::unique_ptr< marinholab::sas::core::Clock > clock_
std::unique_ptr< std::thread > watchdog_thread_
std::chrono::time_point< std::chrono::system_clock, std::chrono::nanoseconds > time_point_from_the_client_
std::chrono::time_point< std::chrono::system_clock, std::chrono::nanoseconds > time_point_from_the_server_
bool watchdog_status_
std::mutex mutex_watchdog_
double max_acceptable_delay_ = 0.1
double watchdog_period_
std::exception_ptr watchdog_exception_ {nullptr}
std::mutex watchdog_exception_mutex_
std::function< void()> control_loop_callback_

Detailed Description

Abstract interface for robot hardware drivers.

RobotDriver declares the virtual API that concrete drivers must implement to interact with robot hardware.

Member Function Documentation

◆ check_for_watchdog_exceptions()

void marinholab::sas::core::RobotDriver::check_for_watchdog_exceptions ( )

Check for exceptions thrown by the watchdog thread and rethrow if present.

RobotDriver::check_for_watchdog_exceptions this method rethrows any exception thrown in the watchdog thread control loop.

Exceptions
std::runtime_errorif the watchdog thread detected a timing or status error
std::exceptionrethrows any exception captured from the watchdog thread

◆ connect()

virtual void marinholab::sas::core::RobotDriver::connect ( )
pure virtual

◆ control_loop_callback_is_set()

bool marinholab::sas::core::RobotDriver::control_loop_callback_is_set ( )

Check if a control loop callback has been set.

Returns
true if a callback has been set, false otherwise

◆ deinitialize()

virtual void marinholab::sas::core::RobotDriver::deinitialize ( )
pure virtual

◆ disconnect()

virtual void marinholab::sas::core::RobotDriver::disconnect ( )
pure virtual

◆ execute_control_loop_callback()

void marinholab::sas::core::RobotDriver::execute_control_loop_callback ( )

Execute the control loop callback if it has been set.

This method should be called by RobotDriverROS or any other class that runs the control loop. It will execute the callback that was set by the concrete RobotDriver implementation.

◆ get_joint_limits()

std::tuple< Eigen::VectorXd, Eigen::VectorXd > marinholab::sas::core::RobotDriver::get_joint_limits ( )
virtual

Get joint limits (min, max).

Returns
Tuple of (min_limits, max_limits)

Reimplemented in sas::RobotDriverCoppeliaSim, and sas::RobotDriverROSComposer.

◆ get_joint_positions()

virtual Eigen::VectorXd marinholab::sas::core::RobotDriver::get_joint_positions ( )
pure virtual

Get current joint positions.

Returns
Vector of joint positions (radians)

Implemented in marinholab::sas::core::RobotDriverExample, sas::RobotDriverCoppeliaSim, sas::RobotDriverKuka, sas::RobotDriverROSComposer, and sas::RobotDriverUR.

◆ get_joint_torques()

Eigen::VectorXd marinholab::sas::core::RobotDriver::get_joint_torques ( )
virtual

Get current joint torques.

Returns
Vector of joint torques
Exceptions
std::runtime_errorif the default implementation is called (not implemented by derived driver)

Reimplemented in sas::RobotDriverKuka.

◆ get_joint_velocities()

Eigen::VectorXd marinholab::sas::core::RobotDriver::get_joint_velocities ( )
virtual

Get current joint velocities.

Returns
Vector of joint velocities
Exceptions
std::runtime_errorif the default implementation is called (not implemented by derived driver)

Reimplemented in sas::RobotDriverUR.

◆ initialize()

virtual void marinholab::sas::core::RobotDriver::initialize ( )
pure virtual

◆ set_control_loop_callback()

void marinholab::sas::core::RobotDriver::set_control_loop_callback ( std::function< void()> callback)

Set the control loop callback function.

RobotDriver::set_control_loop_callback.

Parameters
callbackThe callback function to be executed in the control loop
callback

◆ set_joint_limits()

void marinholab::sas::core::RobotDriver::set_joint_limits ( const std::tuple< Eigen::VectorXd, Eigen::VectorXd > & joint_limits)
virtual

Set joint limits (min, max).

Parameters
joint_limitsTuple of (min_limits, max_limits)

Reimplemented in sas::RobotDriverROSComposer.

◆ set_target_joint_positions()

virtual void marinholab::sas::core::RobotDriver::set_target_joint_positions ( const Eigen::VectorXd & set_target_joint_positions_rad)
pure virtual

Set target joint positions.

Parameters
set_target_joint_positions_radTarget joint positions (radians)

Implemented in marinholab::sas::core::RobotDriverExample, sas::RobotDriverCoppeliaSim, sas::RobotDriverKuka, sas::RobotDriverROSComposer, and sas::RobotDriverUR.

◆ set_target_joint_torques()

void marinholab::sas::core::RobotDriver::set_target_joint_torques ( const Eigen::VectorXd & set_target_joint_torques)
virtual

Set target joint torques.

Parameters
set_target_joint_torquesTarget joint torques
Exceptions
std::runtime_errorif the default implementation is called (not implemented by derived driver)

◆ set_target_joint_velocities()

void marinholab::sas::core::RobotDriver::set_target_joint_velocities ( const Eigen::VectorXd & set_target_joint_velocities)
virtual

Set target joint velocities.

Parameters
set_target_joint_velocitiesTarget joint velocities
Exceptions
std::runtime_errorif the default implementation is called (not implemented by derived driver)

◆ watchdog_set_maximum_acceptable_delay()

void marinholab::sas::core::RobotDriver::watchdog_set_maximum_acceptable_delay ( const double & max_acceptable_delay)

Set the maximum acceptable delay for the watchdog (seconds).

RobotDriver::watchdog_set_maximum_acceptable_delay sets the maximum acceptable clock skew to check the synchronization or potential delays between the time point of watchdog signal sent by the client and the time point when the watchdog signal was received.

Parameters
max_acceptable_delayMaximum delay in seconds
max_acceptable_delay

◆ watchdog_start()

void marinholab::sas::core::RobotDriver::watchdog_start ( const std::chrono::nanoseconds & period)

Start the watchdog thread with the given period.

RobotDriver::watchdog_start starts the watchdog thread.

Parameters
periodWatchdog period as nanoseconds
periodThe period of time.

◆ watchdog_trigger()

void marinholab::sas::core::RobotDriver::watchdog_trigger ( const std::chrono::time_point< std::chrono::system_clock, std::chrono::nanoseconds > & time_point_from_the_client,
const std::chrono::time_point< std::chrono::system_clock, std::chrono::nanoseconds > & time_point_from_the_server,
const bool & status )

Trigger the watchdog with timestamps from client/server and the current status.

RobotDriver::watchdog_trigger updates the trigger signal.

Parameters
time_point_from_the_clientTime point provided by the client
time_point_from_the_serverTime point provided by the server
statusCurrent watchdog status flag
time_point_from_the_clientThis time point corresponds to the moment the signal was sent, as recorded by the client computer's clock.
time_point_from_the_serverThe time point when the watchdog signal was received. This time point uses the computer's clock on which the server (robot) is running.
statusThe desired status. If false, the driver is going to stop.

The documentation for this class was generated from the following files: