sas
Modularised monitoring, logging, and control of robots.
Loading...
Searching...
No Matches
sas_robot_driver_client.hpp
1#pragma once
2/*
3# Copyright (c) 2016-2022 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 <atomic>
33#include <tuple>
34
35#include <rclcpp/rclcpp.hpp>
36#include <geometry_msgs/msg/pose_stamped.hpp>
37#include <std_msgs/msg/float64_multi_array.hpp>
38#include <std_msgs/msg/int32_multi_array.hpp>
39#include <sensor_msgs/msg/joint_state.hpp>
40#include <sas_msgs/msg/watchdog_trigger.hpp>
43#include <sas_msgs/msg/bool.hpp>
44
45
46using namespace rclcpp;
47
48namespace sas
49{
50
60{
61public:
66 {
67 JOINT_CONTROL=0,
68 JOINT_MONITORING,
69 WATCHDOG_CONTROL
70 };
71private:
72 std::shared_ptr<Node> node_;
73
74 std::vector<MODE_BLACKLIST_FLAG> blacklisted_modes_;
75 std::atomic_bool enabled_;
76 std::string topic_prefix_;
77
78 Subscription<sensor_msgs::msg::JointState>::SharedPtr subscriber_joint_states_;
79 VectorXd joint_positions_;
80 VectorXd joint_velocities_;
81 VectorXd joint_forces_;
82 Subscription<std_msgs::msg::Float64MultiArray>::SharedPtr subscriber_joint_limits_min_;
83 VectorXd joint_limits_min_;
84 Subscription<std_msgs::msg::Float64MultiArray>::SharedPtr subscriber_joint_limits_max_;
85 VectorXd joint_limits_max_;
86 Subscription<std_msgs::msg::Int32MultiArray>::SharedPtr subscriber_home_state_;
87 VectorXi home_states_;
88
89 Publisher<std_msgs::msg::Float64MultiArray>::SharedPtr publisher_target_joint_positions_;
90 Publisher<std_msgs::msg::Float64MultiArray>::SharedPtr publisher_target_joint_velocities_;
91 Publisher<std_msgs::msg::Float64MultiArray>::SharedPtr publisher_target_joint_forces_;
92 Publisher<std_msgs::msg::Int32MultiArray> ::SharedPtr publisher_homing_signal_;
93 Publisher<std_msgs::msg::Int32MultiArray> ::SharedPtr publisher_clear_positions_signal_;
94 Publisher<sas_msgs::msg::WatchdogTrigger> ::SharedPtr publisher_watchdog_trigger_;
95 Publisher<sas_msgs::msg::Bool> ::SharedPtr publisher_shutdown_signal_;
96
97 void _callback_joint_states(const sensor_msgs::msg::JointState& msg);
98 void _callback_joint_limits_min(const std_msgs::msg::Float64MultiArray& msg);
99 void _callback_joint_limits_max(const std_msgs::msg::Float64MultiArray& msg);
100 void _callback_home_states(const std_msgs::msg::Int32MultiArray& msg);
101public:
102 RobotDriverClient() = delete;
103 RobotDriverClient(const RobotDriverClient&) = delete;
104
112 RobotDriverClient(const std::shared_ptr<Node> &node,
113 const std::string topic_prefix="GET_FROM_NODE",
114 const std::vector<MODE_BLACKLIST_FLAG>& blacklisted_modes = std::vector<MODE_BLACKLIST_FLAG>{});
115
121 void send_target_joint_positions(const VectorXd& target_joint_positions);
122
128 void send_target_joint_velocities(const VectorXd& target_joint_velocities);
129
135 void send_target_joint_forces(const VectorXd& target_joint_forces);
136
142 void send_homing_signal(const VectorXi& homing_signal);
143
149 void send_clear_positions_signal(const VectorXi& clear_positions_signal);
150
158 void send_watchdog_trigger(const bool& watchdog_trigger_status,
159 const double& period_in_seconds = 1.0,
160 const double& maximum_acceptable_delay = 0.5);
161
166
172 VectorXd get_joint_positions() const;
173
179 VectorXd get_joint_velocities() const;
180
186 VectorXd get_joint_forces() const;
187
193 std::tuple<VectorXd, VectorXd> get_joint_limits() const;
194
200 VectorXi get_home_states() const;
201
208 bool is_enabled(const RobotDriver::Functionality& supported_functionality=RobotDriver::Functionality::PositionControl) const;
209
215 std::string get_topic_prefix() const;
216};
217
218}
219
Definition sas_object.hpp:39
Client interface for robot driver ROS topics.
Definition sas_robot_driver_client.hpp:60
VectorXi get_home_states() const
Get the last received home states vector.
Definition sas_robot_driver_client.cpp:263
std::string get_topic_prefix() const
Get the configured topic prefix.
Definition sas_robot_driver_client.cpp:296
VectorXd get_joint_positions() const
Get the last received joint positions.
Definition sas_robot_driver_client.cpp:229
std::tuple< VectorXd, VectorXd > get_joint_limits() const
Retrieve the joint limits as a tuple (min, max).
Definition sas_robot_driver_client.cpp:253
VectorXd get_joint_velocities() const
Get the last received joint velocities.
Definition sas_robot_driver_client.cpp:237
MODE_BLACKLIST_FLAG
Flags used to blacklist client modes when constructing the client.
Definition sas_robot_driver_client.hpp:66
void send_clear_positions_signal(const VectorXi &clear_positions_signal)
Send a signal to clear positions on the controller side.
Definition sas_robot_driver_client.cpp:180
void send_homing_signal(const VectorXi &homing_signal)
Send a homing signal to the robot.
Definition sas_robot_driver_client.cpp:168
bool is_enabled(const RobotDriver::Functionality &supported_functionality=RobotDriver::Functionality::PositionControl) const
Check whether the client is enabled for a given functionality.
Definition sas_robot_driver_client.cpp:274
void send_shutdown_signal()
Request a shutdown via the robot driver topics.
Definition sas_robot_driver_client.cpp:222
void send_watchdog_trigger(const bool &watchdog_trigger_status, const double &period_in_seconds=1.0, const double &maximum_acceptable_delay=0.5)
Trigger the watchdog from the client.
Definition sas_robot_driver_client.cpp:200
void send_target_joint_velocities(const VectorXd &target_joint_velocities)
Publish target joint velocities.
Definition sas_robot_driver_client.cpp:142
void send_target_joint_forces(const VectorXd &target_joint_forces)
Publish target joint forces/torques.
Definition sas_robot_driver_client.cpp:155
void send_target_joint_positions(const VectorXd &target_joint_positions)
Publish target joint positions.
Definition sas_robot_driver_client.cpp:129
VectorXd get_joint_forces() const
Get the last received joint forces.
Definition sas_robot_driver_client.cpp:245
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.