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
42#include <sas_msgs/msg/watchdog_trigger.hpp>
43#include <sas_msgs/msg/bool.hpp>
44
45using namespace rclcpp;
46
47namespace sas
48{
49
59{
60private:
61 std::shared_ptr<Node> node_;
62
63 std::string node_prefix_;
64 RobotDriver::Functionality currently_active_functionality_;
65
66 Publisher<sensor_msgs::msg::JointState>::SharedPtr publisher_joint_states_;
67 Publisher<std_msgs::msg::Float64MultiArray>::SharedPtr publisher_joint_limits_min_;
68 Publisher<std_msgs::msg::Float64MultiArray>::SharedPtr publisher_joint_limits_max_;
69 Publisher<std_msgs::msg::Int32MultiArray>::SharedPtr publisher_home_state_;
70
71
72 Subscription<sas_msgs::msg::Bool>::SharedPtr subscriber_shutdown_signal_;
73 bool shutdown_signal_;
74 Subscription<std_msgs::msg::Float64MultiArray>::SharedPtr subscriber_target_joint_positions_;
75 VectorXd target_joint_positions_;
76 Subscription<std_msgs::msg::Float64MultiArray>::SharedPtr subscriber_target_joint_velocities_;
77 VectorXd target_joint_velocities_;
78 Subscription<std_msgs::msg::Float64MultiArray>::SharedPtr subscriber_target_joint_forces_;
79 VectorXd target_joint_forces_;
80 Subscription<std_msgs::msg::Int32MultiArray>::SharedPtr subscriber_homing_signal_;
81 VectorXi homing_signal_;
82 Subscription<std_msgs::msg::Int32MultiArray>::SharedPtr subscriber_clear_positions_signal_;
83 VectorXi clear_positions_signal_;
84 Subscription<sas_msgs::msg::WatchdogTrigger>::SharedPtr subscriber_watchdog_trigger_;
85 bool watchdog_trigger_status_;
86 bool watchdog_enabled_;
87 double watchdog_period_in_seconds_;
88 double watchdog_maximum_acceptable_delay_in_seconds_;
89 std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> time_point_from_the_client_;
90 std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> time_point_from_the_server_;
91
92 void _callback_shutdown_signal_(const sas_msgs::msg::Bool& msg);
93 void _callback_target_joint_positions(const std_msgs::msg::Float64MultiArray &msg);
94 void _callback_target_joint_velocities(const std_msgs::msg::Float64MultiArray &msg);
95 void _callback_target_joint_forces(const std_msgs::msg::Float64MultiArray &msg);
96 void _callback_homing_signal(const std_msgs::msg::Int32MultiArray& msg);
97 void _callback_clear_positions_signal(const std_msgs::msg::Int32MultiArray &msg);
98 void _callback_watchdog_trigger_state(const sas_msgs::msg::WatchdogTrigger& msg);
99public:
100 RobotDriverServer() = delete;
101 RobotDriverServer(const RobotDriverServer&) = delete;
102
103//see the discussion in sas_common to understand why this is commented out
104//#ifdef IS_SAS_PYTHON_BUILD
105// RobotDriverServer(const std::string& node_prefix);
106//#endif
107
114 RobotDriverServer(const std::shared_ptr<Node> &node, const std::string& node_prefix="GET_FROM_NODE");
115
121 VectorXd get_target_joint_positions() const;
122
128 VectorXd get_target_joint_velocities() const;
129
135 VectorXd get_target_joint_forces() const;
136
142 VectorXi get_homing_signal() const;
143
150
157
164 bool is_enabled(const RobotDriver::Functionality& supported_functionality=RobotDriver::Functionality::PositionControl) const;
165
173 void send_joint_states(const VectorXd& joint_positions,
174 const VectorXd& joint_velocities,
175 const VectorXd& joint_forces);
176
182 void send_joint_limits(const std::tuple<VectorXd, VectorXd>& joint_limits);
183
189 void send_home_state(const VectorXi& home_state);
190
196 std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> get_watchdog_time_point_from_the_client() const;
197
203 std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> get_watchdog_time_point_from_the_server() const;
204
210 bool get_watchdog_trigger_status() const;
211
217 bool is_watchdog_enabled() const;
218
224 double get_watchdog_period() const;
225
232
238 bool get_shutdown_signal() const;
239};
240
241}
Definition sas_object.hpp:39
Server interface for robot driver ROS topics.
Definition sas_robot_driver_server.hpp:59
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
void send_joint_states(const VectorXd &joint_positions, const VectorXd &joint_velocities, const VectorXd &joint_forces)
Publish joint states (positions, velocities and forces) to clients.
Definition sas_robot_driver_server.cpp:230
double get_watchdog_period() const
Get the configured watchdog period in seconds.
Definition sas_robot_driver_server.cpp:335
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
void send_joint_limits(const std::tuple< VectorXd, VectorXd > &joint_limits)
Publish joint limits (min and max) to clients.
Definition sas_robot_driver_server.cpp:243
VectorXd get_target_joint_forces() const
Get the most recent target joint forces received from clients.
Definition sas_robot_driver_server.cpp:183
void send_home_state(const 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
VectorXd get_target_joint_positions() const
Get the most recent target joint positions received from clients.
Definition sas_robot_driver_server.cpp:167
VectorXi get_clear_positions_signal()
Get the last received clear positions signal vector.
Definition sas_robot_driver_server.cpp:207
VectorXd get_target_joint_velocities() const
Get the most recent target joint velocities received from clients.
Definition sas_robot_driver_server.cpp:175
bool get_shutdown_signal() const
Get the current shutdown signal state as last received from clients.
Definition sas_robot_driver_server.cpp:356
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
VectorXi get_homing_signal() const
Get the last received homing signal vector.
Definition sas_robot_driver_server.cpp:195
Functionality
Enumeration of optional driver functionalities.
Definition sas_robot_driver.hpp:86
Base object class for identification and license utilities.
Abstract RobotDriver interface and watchdog support.