YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
HapticDevice_nws_ros2.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2023 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: BSD-3-Clause
4 */
5
6#ifndef YARP_DEV_HAPTICDEVICE_NWS_ROS2_H
7#define YARP_DEV_HAPTICDEVICE_NWS_ROS2_H
8
9#include <string>
10#include <vector>
11
16
17#include <Ros2Spinner.h>
18
19#include <rclcpp/rclcpp.hpp>
20#include <geometry_msgs/msg/pose.hpp>
21#include <geometry_msgs/msg/vector3.hpp>
22#include <std_msgs/msg/int32_multi_array.hpp>
23#include <std_srvs/srv/trigger.hpp>
24#include <yarp_control_msgs/srv/get_max_feedback.hpp>
25#include <yarp_control_msgs/srv/get_transformation.hpp>
26#include <yarp_control_msgs/srv/set_transformation.hpp>
27
29
44{
45public:
51 ~HapticDevice_nws_ros2() override = default;
52
53 // yarp::dev::DeviceDriver
54 bool open(yarp::os::Searchable& config) override;
55 bool close() override;
56
57 // yarp::dev::WrapperSingle
58 bool attach(yarp::dev::PolyDriver* poly) override;
59 bool detach() override;
60
61 // yarp::os::PeriodicThread
62 void run() override;
63
64private:
65 // ROS2 handler setup / teardown
66 bool publisherConfigureRosHandlers();
67 bool subscriberConfigureRosHandlers();
68 bool servicesConfigureRosHandlers();
69 void destroyRosHandlers();
70
71 // Callbacks subscribed
72 void feedbackCallback(const geometry_msgs::msg::Vector3::SharedPtr msg);
73
74 // Callbacks for services
75 void stopFeedbackCallback(
76 const std::shared_ptr<std_srvs::srv::Trigger::Request> request,
77 std::shared_ptr<std_srvs::srv::Trigger::Response> response);
78 void maxFeedbackCallback(
79 const std::shared_ptr<yarp_control_msgs::srv::GetMaxFeedback::Request> request,
80 std::shared_ptr<yarp_control_msgs::srv::GetMaxFeedback::Response> response);
81 void getTransformationCallback(
82 const std::shared_ptr<yarp_control_msgs::srv::GetTransformation::Request> request,
83 std::shared_ptr<yarp_control_msgs::srv::GetTransformation::Response> response);
84 void setTransformationCallback(
85 const std::shared_ptr<yarp_control_msgs::srv::SetTransformation::Request> request,
86 std::shared_ptr<yarp_control_msgs::srv::SetTransformation::Response> response);
87
88 // Callbacks for parameters
89 bool configureRosParameters();
90 bool forceModeCallback(const std::string& mode);
91 rcl_interfaces::msg::SetParametersResult parameter_callback(
92 const std::vector<rclcpp::Parameter> & parameters);
93
94 // ROS2 node and spinner
95 rclcpp::Node::SharedPtr m_node;
96 Ros2Spinner* m_spinner {nullptr};
97 rclcpp::Node::OnSetParametersCallbackHandle::SharedPtr m_params;
98
99 // Publishers
100 rclcpp::Publisher<geometry_msgs::msg::Pose>::SharedPtr m_stat;
101 rclcpp::Publisher<std_msgs::msg::Int32MultiArray>::SharedPtr m_buttons;
102
103 // Subscribers
104 rclcpp::Subscription<geometry_msgs::msg::Vector3>::SharedPtr m_feedback;
105
106 // Services
107 rclcpp::Service<std_srvs::srv::Trigger>::SharedPtr m_stopFeedbackService;
108 rclcpp::Service<yarp_control_msgs::srv::GetMaxFeedback>::SharedPtr m_maxForce;
109 rclcpp::Service<yarp_control_msgs::srv::GetTransformation>::SharedPtr m_getTransformation;
110 rclcpp::Service<yarp_control_msgs::srv::SetTransformation>::SharedPtr m_setTransformation;
111
112 // Parameters
113 std::string mode_feedback;
114
115 // Device interface
116 yarp::dev::IHapticDevice* iHapticDevice {nullptr};
117};
118
119#endif // YARP_DEV_HAPTICDEVICE_NWS_ROS2_H
defines control board standard interfaces
This class is the parameters parser for class HapticDevice_nws_ros2.
HapticDevice_nws_ros2: A HapticDevice network wrapper server for ROS2.
HapticDevice_nws_ros2(const HapticDevice_nws_ros2 &)=delete
bool close() override
Close the DeviceDriver.
bool attach(yarp::dev::PolyDriver *poly) override
Attach to another object.
HapticDevice_nws_ros2 & operator=(const HapticDevice_nws_ros2 &)=delete
void run() override
Loop function.
bool detach() override
Detach the object (you must have first called attach).
~HapticDevice_nws_ros2() override=default
HapticDevice_nws_ros2(HapticDevice_nws_ros2 &&)=delete
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
HapticDevice_nws_ros2 & operator=(HapticDevice_nws_ros2 &&)=delete
Interface implemented by all device drivers.
A container for a device driver.
Definition PolyDriver.h:23
Helper interface for an object that can wrap/or "attach" to a single other device.
An abstraction for a periodic thread.
A base class for nested structures that can be searched.
Definition Searchable.h:31