sas
Modularised monitoring, logging, and control of robots.
Loading...
Searching...
No Matches
sas_robot_driver_server.hpp
1#pragma once
2/*
3# Copyright (c) 2016-2025 Murilo Marques Marinho
4#
5# This file is part of sas_robot_driver.
6#
7# sas_robot_driver is free software: you can redistribute it and/or modify
8# it under the terms of the GNU Lesser General Public License as published by
9# the Free Software Foundation, either version 3 of the License, or
10# (at your option) any later version.
11#
12# sas_robot_driver is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU Lesser General Public License for more details.
16#
17# You should have received a copy of the GNU Lesser General Public License
18# along with sas_robot_driver. If not, see <https://www.gnu.org/licenses/>.
19#
20# ################################################################
21#
22# Author: Murilo M. Marinho, email: murilomarinho@ieee.org
23#
24# ################################################################
25# Contributors:
26#
27# 1. Juan Jose Quiroz Omana (juanjose.quirozomana@manchester.ac.uk)
28# Added the Watchdog functionality.
29#
30*/
31
32#include <tuple>
33
34#include <rclcpp/rclcpp.hpp>
35#include <geometry_msgs/msg/pose_stamped.hpp>
36#include <std_msgs/msg/float64_multi_array.hpp>
37#include <std_msgs/msg/int32_multi_array.hpp>
38#include <sensor_msgs/msg/joint_state.hpp>
39
40#include <sas_core/sas_robot_driver.hpp>
41#include <sas_core/sas_object.hpp>
42#include <sas_msgs/msg/watchdog_trigger.hpp>
43#include <sas_msgs/msg/bool.hpp>
44
45namespace sas
46{
47
56class RobotDriverServer : private sas::Object
57{
58private:
59 std::shared_ptr<rclcpp::Node> node_;
60
61 std::string node_prefix_;
62 RobotDriver::Functionality currently_active_functionality_;
63
64 rclcpp::Publisher<sensor_msgs::msg::JointState>::SharedPtr publisher_joint_states_;
65 rclcpp::Publisher<std_msgs::msg::Float64MultiArray>::SharedPtr publisher_joint_limits_min_;
66 rclcpp::Publisher<std_msgs::msg::Float64MultiArray>::SharedPtr publisher_joint_limits_max_;
67 rclcpp::Publisher<std_msgs::msg::Int32MultiArray>::SharedPtr publisher_home_state_;
68
69 rclcpp::Subscription<sas_msgs::msg::Bool>::SharedPtr subscriber_shutdown_signal_;
70 bool shutdown_signal_;
71 rclcpp::Subscription<std_msgs::msg::Float64MultiArray>::SharedPtr subscriber_target_joint_positions_;
72 Eigen::VectorXd target_joint_positions_;
73 rclcpp::Subscription<std_msgs::msg::Float64MultiArray>::SharedPtr subscriber_target_joint_velocities_;
74 Eigen::VectorXd target_joint_velocities_;
75 rclcpp::Subscription<std_msgs::msg::Float64MultiArray>::SharedPtr subscriber_target_joint_forces_;
76 Eigen::VectorXd target_joint_forces_;
77 rclcpp::Subscription<std_msgs::msg::Int32MultiArray>::SharedPtr subscriber_homing_signal_;
78 Eigen::VectorXi homing_signal_;
79 rclcpp::Subscription<std_msgs::msg::Int32MultiArray>::SharedPtr subscriber_clear_positions_signal_;
80 Eigen::VectorXi clear_positions_signal_;
81 rclcpp::Subscription<sas_msgs::msg::WatchdogTrigger>::SharedPtr subscriber_watchdog_trigger_;
82 bool watchdog_trigger_status_;
83 bool watchdog_enabled_;
84 double watchdog_period_in_seconds_;
85 double watchdog_maximum_acceptable_delay_in_seconds_;
86 std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> time_point_from_the_client_;
87 std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> time_point_from_the_server_;
88
89 void _callback_shutdown_signal_(const sas_msgs::msg::Bool& msg);
90 void _callback_target_joint_positions(const std_msgs::msg::Float64MultiArray& msg);
91 void _callback_target_joint_velocities(const std_msgs::msg::Float64MultiArray& msg);
92 void _callback_target_joint_forces(const std_msgs::msg::Float64MultiArray& msg);
93 void _callback_homing_signal(const std_msgs::msg::Int32MultiArray& msg);
94 void _callback_clear_positions_signal(const std_msgs::msg::Int32MultiArray& msg);
95 void _callback_watchdog_trigger_state(const sas_msgs::msg::WatchdogTrigger& msg);
96
97public:
98 RobotDriverServer() = delete;
99 RobotDriverServer(const RobotDriverServer&) = delete;
100
107 RobotDriverServer(const std::shared_ptr<rclcpp::Node>& node, const std::string& node_prefix = "GET_FROM_NODE");
108
116 Eigen::VectorXd get_target_joint_positions() const;
117
125 Eigen::VectorXd get_target_joint_velocities() const;
126
134 Eigen::VectorXd get_target_joint_forces() const;
135
143 Eigen::VectorXi get_homing_signal() const;
144
152 Eigen::VectorXi get_clear_positions_signal();
153
160
168 bool is_enabled(
169 const RobotDriver::Functionality& supported_functionality = RobotDriver::Functionality::PositionControl) const;
170
178 void send_joint_states(const Eigen::VectorXd& joint_positions, const Eigen::VectorXd& joint_velocities,
179 const Eigen::VectorXd& joint_forces);
180
186 void send_joint_limits(const std::tuple<Eigen::VectorXd, Eigen::VectorXd>& joint_limits);
187
193 void send_home_state(const Eigen::VectorXi& home_state);
194
201 std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds>
203
210 std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds>
212
219 bool get_watchdog_trigger_status() const;
220
226 bool is_watchdog_enabled() const;
227
233 double get_watchdog_period() const;
234
241
247 bool get_shutdown_signal() const;
248};
249
250} // namespace sas
Base class for SAS objects.
Definition sas_object.hpp:40
Functionality
Enumeration of optional driver functionalities.
Definition sas_robot_driver.hpp:93
void send_joint_states(const Eigen::VectorXd &joint_positions, const Eigen::VectorXd &joint_velocities, const Eigen::VectorXd &joint_forces)
Publish joint states (positions, velocities and forces) to clients.
Definition sas_robot_driver_server.cpp:241
bool is_enabled(const RobotDriver::Functionality &supported_functionality=RobotDriver::Functionality::PositionControl) const
Check whether the server supports and is enabled for a functionality.
Definition sas_robot_driver_server.cpp:273
bool get_watchdog_trigger_status() const
Get the current watchdog trigger status as last received from the client.
Definition sas_robot_driver_server.cpp:331
Eigen::VectorXi get_clear_positions_signal()
Get the last received clear positions signal vector.
Definition sas_robot_driver_server.cpp:217
double get_watchdog_period() const
Get the configured watchdog period in seconds.
Definition sas_robot_driver_server.cpp:354
Eigen::VectorXd get_target_joint_positions() const
Get the most recent target joint positions received from clients.
Definition sas_robot_driver_server.cpp:172
Eigen::VectorXd get_target_joint_velocities() const
Get the most recent target joint velocities received from clients.
Definition sas_robot_driver_server.cpp:181
bool is_watchdog_enabled() const
Query whether the watchdog is enabled on the server.
Definition sas_robot_driver_server.cpp:345
RobotDriver::Functionality get_currently_active_functionality() const
Get the currently active functionality of the robot driver.
Definition sas_robot_driver_server.cpp:230
std::chrono::time_point< std::chrono::system_clock, std::chrono::nanoseconds > get_watchdog_time_point_from_the_client() const
Get the time point received from the client for watchdog synchronization.
Definition sas_robot_driver_server.cpp:301
Eigen::VectorXi get_homing_signal() const
Get the last received homing signal vector.
Definition sas_robot_driver_server.cpp:204
void send_home_state(const Eigen::VectorXi &home_state)
Publish the home state vector to clients.
Definition sas_robot_driver_server.cpp:266
double get_watchdog_maximum_acceptable_delay() const
Get the configured maximum acceptable delay for the watchdog in seconds.
Definition sas_robot_driver_server.cpp:365
bool get_shutdown_signal() const
Get the current shutdown signal state as last received from clients.
Definition sas_robot_driver_server.cpp:375
Eigen::VectorXd get_target_joint_forces() const
Get the most recent target joint forces received from clients.
Definition sas_robot_driver_server.cpp:191
std::chrono::time_point< std::chrono::system_clock, std::chrono::nanoseconds > get_watchdog_time_point_from_the_server() const
Get the time point captured on the server for watchdog synchronization.
Definition sas_robot_driver_server.cpp:317
void send_joint_limits(const std::tuple< Eigen::VectorXd, Eigen::VectorXd > &joint_limits)
Publish joint limits (min and max) to clients.
Definition sas_robot_driver_server.cpp:255