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
45
46namespace sas
47{
48
57class RobotDriverServer: private sas::Object
58{
59private:
60 std::shared_ptr<rclcpp::Node> node_;
61
62 std::string node_prefix_;
63 RobotDriver::Functionality currently_active_functionality_;
64
65 rclcpp::Publisher<sensor_msgs::msg::JointState>::SharedPtr publisher_joint_states_;
66 rclcpp::Publisher<std_msgs::msg::Float64MultiArray>::SharedPtr publisher_joint_limits_min_;
67 rclcpp::Publisher<std_msgs::msg::Float64MultiArray>::SharedPtr publisher_joint_limits_max_;
68 rclcpp::Publisher<std_msgs::msg::Int32MultiArray>::SharedPtr publisher_home_state_;
69
70
71 rclcpp::Subscription<sas_msgs::msg::Bool>::SharedPtr subscriber_shutdown_signal_;
72 bool shutdown_signal_;
73 rclcpp::Subscription<std_msgs::msg::Float64MultiArray>::SharedPtr subscriber_target_joint_positions_;
74 Eigen::VectorXd target_joint_positions_;
75 rclcpp::Subscription<std_msgs::msg::Float64MultiArray>::SharedPtr subscriber_target_joint_velocities_;
76 Eigen::VectorXd target_joint_velocities_;
77 rclcpp::Subscription<std_msgs::msg::Float64MultiArray>::SharedPtr subscriber_target_joint_forces_;
78 Eigen::VectorXd target_joint_forces_;
79 rclcpp::Subscription<std_msgs::msg::Int32MultiArray>::SharedPtr subscriber_homing_signal_;
80 Eigen::VectorXi homing_signal_;
81 rclcpp::Subscription<std_msgs::msg::Int32MultiArray>::SharedPtr subscriber_clear_positions_signal_;
82 Eigen::VectorXi clear_positions_signal_;
83 rclcpp::Subscription<sas_msgs::msg::WatchdogTrigger>::SharedPtr subscriber_watchdog_trigger_;
84 bool watchdog_trigger_status_;
85 bool watchdog_enabled_;
86 double watchdog_period_in_seconds_;
87 double watchdog_maximum_acceptable_delay_in_seconds_;
88 std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> time_point_from_the_client_;
89 std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> time_point_from_the_server_;
90
91 void _callback_shutdown_signal_(const sas_msgs::msg::Bool& msg);
92 void _callback_target_joint_positions(const std_msgs::msg::Float64MultiArray &msg);
93 void _callback_target_joint_velocities(const std_msgs::msg::Float64MultiArray &msg);
94 void _callback_target_joint_forces(const std_msgs::msg::Float64MultiArray &msg);
95 void _callback_homing_signal(const std_msgs::msg::Int32MultiArray& msg);
96 void _callback_clear_positions_signal(const std_msgs::msg::Int32MultiArray &msg);
97 void _callback_watchdog_trigger_state(const sas_msgs::msg::WatchdogTrigger& msg);
98public:
99 RobotDriverServer() = delete;
100 RobotDriverServer(const RobotDriverServer&) = delete;
101
108 RobotDriverServer(const std::shared_ptr<rclcpp::Node> &node, const std::string& node_prefix="GET_FROM_NODE");
109
117 Eigen::VectorXd get_target_joint_positions() const;
118
126 Eigen::VectorXd get_target_joint_velocities() const;
127
135 Eigen::VectorXd get_target_joint_forces() const;
136
144 Eigen::VectorXi get_homing_signal() const;
145
153 Eigen::VectorXi get_clear_positions_signal();
154
160 RobotDriver::Functionality get_currently_active_functionality() const;
161
169 bool is_enabled(const RobotDriver::Functionality& supported_functionality=RobotDriver::Functionality::PositionControl) const;
170
178 void send_joint_states(const Eigen::VectorXd& joint_positions,
179 const Eigen::VectorXd& joint_velocities,
180 const Eigen::VectorXd& joint_forces);
181
187 void send_joint_limits(const std::tuple<Eigen::VectorXd, Eigen::VectorXd>& joint_limits);
188
194 void send_home_state(const Eigen::VectorXi& home_state);
195
202 std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> get_watchdog_time_point_from_the_client() const;
203
210 std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> get_watchdog_time_point_from_the_server() const;
211
218 bool get_watchdog_trigger_status() const;
219
225 bool is_watchdog_enabled() const;
226
232 double get_watchdog_period() const;
233
240
246 bool get_shutdown_signal() const;
247};
248
249}
Base class for SAS objects.
Definition sas_object.hpp:40
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:230
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:262
bool get_watchdog_trigger_status() const
Get the current watchdog trigger status as last received from the client.
Definition sas_robot_driver_server.cpp:314
Eigen::VectorXi get_clear_positions_signal()
Get the last received clear positions signal vector.
Definition sas_robot_driver_server.cpp:207
double get_watchdog_period() const
Get the configured watchdog period in seconds.
Definition sas_robot_driver_server.cpp:335
Eigen::VectorXd get_target_joint_positions() const
Get the most recent target joint positions received from clients.
Definition sas_robot_driver_server.cpp:167
Eigen::VectorXd get_target_joint_velocities() const
Get the most recent target joint velocities received from clients.
Definition sas_robot_driver_server.cpp:175
bool is_watchdog_enabled() const
Query whether the watchdog is enabled on the server.
Definition sas_robot_driver_server.cpp:326
RobotDriver::Functionality get_currently_active_functionality() const
Get the currently active functionality of the robot driver.
Definition sas_robot_driver_server.cpp:219
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:289
Eigen::VectorXi get_homing_signal() const
Get the last received homing signal vector.
Definition sas_robot_driver_server.cpp:195
void send_home_state(const Eigen::VectorXi &home_state)
Publish the home state vector to clients.
Definition sas_robot_driver_server.cpp:254
double get_watchdog_maximum_acceptable_delay() const
Get the configured maximum acceptable delay for the watchdog in seconds.
Definition sas_robot_driver_server.cpp:346
bool get_shutdown_signal() const
Get the current shutdown signal state as last received from clients.
Definition sas_robot_driver_server.cpp:356
Eigen::VectorXd get_target_joint_forces() const
Get the most recent target joint forces received from clients.
Definition sas_robot_driver_server.cpp:183
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:302
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:243