sas
Modularised monitoring, logging, and control of robots.
Loading...
Searching...
No Matches
RobotDriverGazebo Class Reference

Gazebo implementation of RobotDriver. More...

#include <sas_robot_driver_gazebo.hpp>

Inheritance diagram for RobotDriverGazebo:
marinholab::sas::core::RobotDriver

Public Member Functions

 RobotDriverGazebo (const RobotDriverGazebo &)=delete
 Not copyable.
 RobotDriverGazebo ()=delete
 Needs a configuration.
 RobotDriverGazebo (const std::shared_ptr< ShutdownSignaler > &shutdown_signaler, const RobotDriverGazeboConfiguration &configuration)
 Construct a Gazebo robot driver.
 ~RobotDriverGazebo () override=default
 Destructor.
const RobotDriverGazeboConfiguration & get_configuration () const
 The configuration this driver was constructed with.
Eigen::VectorXd get_joint_positions () override
 The latest joint positions from Gazebo.
void set_target_joint_positions (const Eigen::VectorXd &target_joint_positions_rad) override
 Publish target joint positions to Gazebo's joint position controllers.
Eigen::VectorXd get_joint_velocities () override
 The latest joint velocities from Gazebo.
Eigen::VectorXd get_joint_torques () override
 The latest joint torques from Gazebo.
void connect () override
 Advertise the joints' command topics and subscribe to the joint-state topic.
void disconnect () override
 Unsubscribe from the joint-state topic.
void initialize () override
 Wait for every joint's state and limits from Gazebo, then set the joint limits.
void deinitialize () override
 Nothing to undo in Gazebo.
Public Member Functions inherited from marinholab::sas::core::RobotDriver
virtual ~RobotDriver ()
 Virtual destructor for RobotDriver.
virtual void set_target_joint_velocities (const Eigen::VectorXd &set_target_joint_velocities)
 Set target joint velocities.
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.
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.

Additional Inherited Members

Public Types inherited from marinholab::sas::core::RobotDriver
enum class  Functionality {
  None = 0 , PositionControl , VelocityControl , ForceControl ,
  Homing , ClearPositions , Watchdog
}
 Enumeration of optional driver functionalities.
Protected Member Functions inherited from marinholab::sas::core::RobotDriver
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 inherited from marinholab::sas::core::RobotDriver
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

Gazebo implementation of RobotDriver.

Exchanges joint commands and joint states with Gazebo through gz-transport: one gz.msgs.Double command topic per joint (a JointPositionController) and one gz.msgs.Model joint-state topic (a JointStatePublisher). Thread-safe: the joint-state callback and the getters share the cached values under a mutex.

Constructor & Destructor Documentation

◆ RobotDriverGazebo()

sas::RobotDriverGazebo::RobotDriverGazebo ( const std::shared_ptr< ShutdownSignaler > & shutdown_signaler,
const RobotDriverGazeboConfiguration & configuration )

Construct a Gazebo robot driver.

Parameters
shutdown_signalerSignals the driver to stop waiting (e.g. on SIGINT).
configurationJoint names and Gazebo topics.
Exceptions
std::invalid_argumentif configuration has no joints.

Member Function Documentation

◆ connect()

void sas::RobotDriverGazebo::connect ( )
overridevirtual

Advertise the joints' command topics and subscribe to the joint-state topic.

Exceptions
std::runtime_errorif a topic cannot be advertised or subscribed to.

Implements marinholab::sas::core::RobotDriver.

◆ deinitialize()

void sas::RobotDriverGazebo::deinitialize ( )
overridevirtual

Nothing to undo in Gazebo.

Implements marinholab::sas::core::RobotDriver.

◆ disconnect()

void sas::RobotDriverGazebo::disconnect ( )
overridevirtual

Unsubscribe from the joint-state topic.

Implements marinholab::sas::core::RobotDriver.

◆ get_configuration()

The configuration this driver was constructed with.

Returns
The joints and Gazebo topics.

◆ get_joint_positions()

Eigen::VectorXd sas::RobotDriverGazebo::get_joint_positions ( )
overridevirtual

The latest joint positions from Gazebo.

Returns
Joint positions [rad], in configuration order.
Exceptions
std::runtime_errorbefore every joint's state has been received.

Implements marinholab::sas::core::RobotDriver.

◆ get_joint_torques()

Eigen::VectorXd sas::RobotDriverGazebo::get_joint_torques ( )
overridevirtual

The latest joint torques from Gazebo.

Returns
Joint torques [N m], in configuration order.
Exceptions
std::runtime_errorbefore every joint's state has been received.

Reimplemented from marinholab::sas::core::RobotDriver.

◆ get_joint_velocities()

Eigen::VectorXd sas::RobotDriverGazebo::get_joint_velocities ( )
overridevirtual

The latest joint velocities from Gazebo.

Returns
Joint velocities [rad/s], in configuration order.
Exceptions
std::runtime_errorbefore every joint's state has been received.

Reimplemented from marinholab::sas::core::RobotDriver.

◆ initialize()

void sas::RobotDriverGazebo::initialize ( )
overridevirtual

Wait for every joint's state and limits from Gazebo, then set the joint limits.

Exceptions
std::runtime_errorif a shutdown is signaled while waiting.

Implements marinholab::sas::core::RobotDriver.

◆ set_target_joint_positions()

void sas::RobotDriverGazebo::set_target_joint_positions ( const Eigen::VectorXd & target_joint_positions_rad)
overridevirtual

Publish target joint positions to Gazebo's joint position controllers.

Parameters
target_joint_positions_radTarget joint positions [rad], in configuration order.
Exceptions
std::invalid_argumentif the size differs from the number of joints.

Implements marinholab::sas::core::RobotDriver.


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