47#include <eigen3/Eigen/Dense>
62 std::atomic_bool* break_loops_;
63 std::shared_ptr<ShutdownSignaler> shutdown_signaler_;
64 std::tuple<VectorXd, VectorXd> joint_limits_;
65 VectorXd joint_velocities_;
66 VectorXd joint_torques_;
68 std::unique_ptr<sas::Clock> clock_;
69 std::unique_ptr<std::thread> watchdog_thread_;
70 std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> time_point_from_the_client_;
71 std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> time_point_from_the_server_;
72 bool watchdog_status_;
74 std::mutex mutex_watchdog_;
75 double max_acceptable_delay_ = 0.1;
76 double watchdog_period_;
78 RobotDriver(
const std::shared_ptr<ShutdownSignaler>& shutdown_signaler_);
79 [[deprecated(
"Use RobotDriver(const std::shared_ptr<ShutdownSignaler>& shutdown_signaler_) instead.")]]
80 RobotDriver(std::atomic_bool* break_loops);
83 RobotDriver(
const RobotDriver&)=
delete;
85 std::exception_ptr watchdog_exception_{
nullptr};
86 std::mutex watchdog_exception_mutex_;
89 std::function<void()> control_loop_callback_;
160 virtual void set_joint_limits(
const std::tuple<VectorXd, VectorXd>& joint_limits);
174 void watchdog_trigger(
const std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds>& time_point_from_the_client,
175 const std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds>& time_point_from_the_server,
~RobotDriver()
Virtual destructor for RobotDriver.
Definition sas_robot_driver.cpp:55
virtual void disconnect()=0
Disconnect from the underlying robot/hardware.
virtual void set_target_joint_positions(const VectorXd &set_target_joint_positions_rad)=0
Set target joint positions.
virtual VectorXd get_joint_torques()
Get current joint torques.
Definition sas_robot_driver.cpp:73
virtual VectorXd get_joint_velocities()
Get current joint velocities.
Definition sas_robot_driver.cpp:63
virtual void connect()=0
Connect to the underlying robot/hardware.
void check_for_watchdog_exceptions()
Check for exceptions thrown by the watchdog thread and rethrow if present.
Definition sas_robot_driver.cpp:198
void execute_control_loop_callback()
Execute the control loop callback if it has been set.
Definition sas_robot_driver.cpp:222
void set_control_loop_callback(std::function< void()> callback)
Set the control loop callback function.
Definition sas_robot_driver.cpp:209
bool control_loop_callback_is_set()
Check if a control loop callback has been set.
Definition sas_robot_driver.cpp:241
virtual void set_target_joint_torques(const VectorXd &set_target_joint_torques)
Set target joint torques.
Definition sas_robot_driver.cpp:78
virtual void deinitialize()=0
Deinitialize the driver resources.
void watchdog_set_maximum_acceptable_delay(const double &max_acceptable_delay)
Set the maximum acceptable delay for the watchdog (seconds).
Definition sas_robot_driver.cpp:190
Functionality
Enumeration of optional driver functionalities.
Definition sas_robot_driver.hpp:95
virtual std::tuple< VectorXd, VectorXd > get_joint_limits()
Get joint limits (min, max).
Definition sas_robot_driver.cpp:83
virtual VectorXd get_joint_positions()=0
Get current joint positions.
virtual void initialize()=0
Initialize the driver resources.
virtual void set_joint_limits(const std::tuple< VectorXd, VectorXd > &joint_limits)
Set joint limits (min, max).
Definition sas_robot_driver.cpp:88
virtual void set_target_joint_velocities(const VectorXd &set_target_joint_velocities)
Set target joint velocities.
Definition sas_robot_driver.cpp:68
void _watchdog_thread_function()
RobotDriver::_watchdog_thread_function throws an exception if the elapsed time since the last trigger...
Definition sas_robot_driver.cpp:98
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.
Definition sas_robot_driver.cpp:171
void watchdog_start(const std::chrono::nanoseconds &period)
Start the watchdog thread with the given period.
Definition sas_robot_driver.cpp:149
Timing utilities for control loops and statistics collection.
Cross-module shutdown signaling class.