ros2_control - foxy
Loading...
Searching...
No Matches
gripper_action_controller.hpp
1// Copyright 2014, SRI International
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
16
17#ifndef GRIPPER_CONTROLLERS__GRIPPER_ACTION_CONTROLLER_HPP_
18#define GRIPPER_CONTROLLERS__GRIPPER_ACTION_CONTROLLER_HPP_
19
20// C++ standard
21#include <cassert>
22#include <memory>
23#include <stdexcept>
24#include <string>
25// TODO(JafarAbdi): Remove experimental once the default standard is C++17
26#include "experimental/optional"
27
28// ROS
29#include "rclcpp/rclcpp.hpp"
30
31// ROS messages
32#include "control_msgs/action/gripper_command.hpp"
33
34// rclcpp_action
35#include "rclcpp_action/create_server.hpp"
36
37// ros_controls
38#include "controller_interface/controller_interface.hpp"
39#include "gripper_controllers/visibility_control.hpp"
40#include "hardware_interface/loaned_command_interface.hpp"
41#include "hardware_interface/loaned_state_interface.hpp"
42#include "realtime_tools/realtime_buffer.h"
43#include "realtime_tools/realtime_server_goal_handle.h"
44
45// Project
46#include "gripper_controllers/hardware_interface_adapter.hpp"
47
49{
58template <const char * HardwareInterface>
60{
61public:
66 struct Commands
67 {
68 double position_; // Last commanded position
69 double max_effort_; // Max allowed effort
70 };
71
72 GRIPPER_ACTION_CONTROLLER_PUBLIC GripperActionController();
73
74 GRIPPER_ACTION_CONTROLLER_PUBLIC
75 controller_interface::return_type init(const std::string & controller_name) override;
76
81 GRIPPER_ACTION_CONTROLLER_PUBLIC
83
88 GRIPPER_ACTION_CONTROLLER_PUBLIC
90
91 GRIPPER_ACTION_CONTROLLER_PUBLIC
92 controller_interface::return_type update() override;
93
94 GRIPPER_ACTION_CONTROLLER_PUBLIC
95 rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn on_configure(
96 const rclcpp_lifecycle::State & previous_state) override;
97
98 GRIPPER_ACTION_CONTROLLER_PUBLIC
99 rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn on_activate(
100 const rclcpp_lifecycle::State & previous_state) override;
101
102 GRIPPER_ACTION_CONTROLLER_PUBLIC
103 rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn on_deactivate(
104 const rclcpp_lifecycle::State & previous_state) override;
105
107 // pre-allocated memory that is re-used to set the realtime buffer
108 Commands command_struct_, command_struct_rt_;
109
110private:
111 using GripperCommandAction = control_msgs::action::GripperCommand;
112 using ActionServer = rclcpp_action::Server<GripperCommandAction>;
113 using ActionServerPtr = ActionServer::SharedPtr;
115 using RealtimeGoalHandle =
117 using RealtimeGoalHandlePtr = std::shared_ptr<RealtimeGoalHandle>;
118
120
121 bool update_hold_position_;
122
123 bool verbose_ = false;
124 std::string name_;
125 std::experimental::optional<std::reference_wrapper<hardware_interface::LoanedCommandInterface>>
126 joint_position_command_interface_;
127 std::experimental::optional<std::reference_wrapper<hardware_interface::LoanedStateInterface>>
128 joint_position_state_interface_;
129 std::experimental::optional<std::reference_wrapper<hardware_interface::LoanedStateInterface>>
130 joint_velocity_state_interface_;
131
132 std::string joint_name_;
133
134 HwIfaceAdapter hw_iface_adapter_;
135
136 RealtimeGoalHandlePtr rt_active_goal_;
137 control_msgs::action::GripperCommand::Result::SharedPtr pre_alloc_result_;
138
139 rclcpp::Duration action_monitor_period_;
140
141 // ROS API
142 ActionServerPtr action_server_;
143
144 rclcpp::TimerBase::SharedPtr goal_handle_timer_;
145
146 rclcpp_action::GoalResponse goal_callback(
147 const rclcpp_action::GoalUUID & uuid, std::shared_ptr<const GripperCommandAction::Goal> goal);
148
149 rclcpp_action::CancelResponse cancel_callback(const std::shared_ptr<GoalHandle> goal_handle);
150
151 void accepted_callback(std::shared_ptr<GoalHandle> goal_handle);
152
153 void preempt_active_goal();
154
155 void set_hold_position();
156
157 rclcpp::Time last_movement_time_ = rclcpp::Time(0, 0, RCL_ROS_TIME);
158 double computed_command_;
159
160 double stall_timeout_,
161 stall_velocity_threshold_;
162 double default_max_effort_;
163 double goal_tolerance_;
164
168 void check_for_success(
169 const rclcpp::Time & time, double error_position, double current_position,
170 double current_velocity);
171};
172
173} // namespace gripper_action_controller
174
175#include "gripper_controllers/gripper_action_controller_impl.hpp"
176
177#endif // GRIPPER_CONTROLLERS__GRIPPER_ACTION_CONTROLLER_HPP_
Helper class to simplify integrating the GripperActionController with different hardware interfaces.
Definition hardware_interface_adapter.hpp:44
Definition controller_interface.hpp:69
Controller for executing a gripper command action for simple single-dof grippers.
Definition gripper_action_controller.hpp:60
GRIPPER_ACTION_CONTROLLER_PUBLIC controller_interface::InterfaceConfiguration state_interface_configuration() const override
command_interface_configuration This controller requires the position and velocity state interfaces f...
Definition gripper_action_controller_impl.hpp:327
GRIPPER_ACTION_CONTROLLER_PUBLIC controller_interface::InterfaceConfiguration command_interface_configuration() const override
command_interface_configuration This controller requires the position command interfaces for the cont...
Definition gripper_action_controller_impl.hpp:318
Definition joint_trajectory_controller.hpp:50
Definition realtime_buffer.h:51
Definition realtime_server_goal_handle.h:44
Definition gripper_action_controller.hpp:49
Configuring what command/state interfaces to claim.
Definition controller_interface.hpp:63
Store position and max effort in struct to allow easier realtime buffer usage.
Definition gripper_action_controller.hpp:67