Skip to content

Commit d9f5ed0

Browse files
Merge pull request #1 from AivotRobotics/humble-backport-1002
Backport of ros-controls#1002 to Humble
2 parents 2b94b32 + 6d010f4 commit d9f5ed0

14 files changed

Lines changed: 1154 additions & 0 deletions

doc/controllers_index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ The controllers are using `common hardware interface definitions`_, and may use
5353
Forward Command Controller <../forward_command_controller/doc/userdoc.rst>
5454
Gripper Controller <../gripper_controllers/doc/userdoc.rst>
5555
Joint Trajectory Controller <../joint_trajectory_controller/doc/userdoc.rst>
56+
Parallel Gripper Controller <../parallel_gripper_controller/doc/userdoc.rst>
5657
PID Controller <../pid_controller/doc/userdoc.rst>
5758
Position Controllers <../position_controllers/doc/userdoc.rst>
5859
Velocity Controllers <../velocity_controllers/doc/userdoc.rst>

gripper_controllers/include/gripper_controllers/gripper_action_controller_impl.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ void GripperActionController<HardwareInterface>::preempt_active_goal()
4040
template <const char * HardwareInterface>
4141
controller_interface::CallbackReturn GripperActionController<HardwareInterface>::on_init()
4242
{
43+
RCLCPP_WARN(
44+
get_node()->get_logger(),
45+
"[Deprecated]: the `position_controllers/GripperActionController` and "
46+
"`effort_controllers::GripperActionController` controllers are replaced by "
47+
"'parallel_gripper_controllers/GripperActionController' controller");
4348
try
4449
{
4550
param_listener_ = std::make_shared<ParamListener>(get_node());
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
cmake_minimum_required(VERSION 3.16)
2+
project(parallel_gripper_controller LANGUAGES CXX)
3+
4+
if(CMAKE_CXX_COMPILER_ID MATCHES "(GNU|Clang)")
5+
add_compile_options(-Wall -Wextra -Wpedantic -Werror=conversion -Werror=unused-but-set-variable
6+
-Werror=return-type -Werror=shadow -Werror=format)
7+
endif()
8+
9+
set(THIS_PACKAGE_INCLUDE_DEPENDS
10+
control_msgs
11+
control_toolbox
12+
controller_interface
13+
generate_parameter_library
14+
hardware_interface
15+
pluginlib
16+
rclcpp
17+
rclcpp_action
18+
realtime_tools
19+
)
20+
21+
find_package(ament_cmake REQUIRED)
22+
find_package(backward_ros REQUIRED)
23+
foreach(Dependency IN ITEMS ${THIS_PACKAGE_INCLUDE_DEPENDS})
24+
find_package(${Dependency} REQUIRED)
25+
endforeach()
26+
27+
generate_parameter_library(parallel_gripper_action_controller_parameters
28+
src/gripper_action_controller_parameters.yaml
29+
)
30+
31+
add_library(parallel_gripper_action_controller SHARED
32+
src/parallel_gripper_action_controller.cpp
33+
)
34+
target_compile_features(parallel_gripper_action_controller PUBLIC cxx_std_17)
35+
target_include_directories(parallel_gripper_action_controller PUBLIC
36+
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
37+
$<INSTALL_INTERFACE:include/parallel_gripper_action_controller>
38+
)
39+
target_link_libraries(parallel_gripper_action_controller PUBLIC
40+
parallel_gripper_action_controller_parameters
41+
)
42+
ament_target_dependencies(parallel_gripper_action_controller PUBLIC ${THIS_PACKAGE_INCLUDE_DEPENDS})
43+
44+
pluginlib_export_plugin_description_file(controller_interface ros_control_plugins.xml)
45+
46+
if(BUILD_TESTING)
47+
find_package(ament_cmake_gmock REQUIRED)
48+
find_package(controller_manager REQUIRED)
49+
find_package(ros2_control_test_assets REQUIRED)
50+
51+
ament_add_gmock(test_load_parallel_gripper_action_controllers
52+
test/test_load_parallel_gripper_action_controller.cpp
53+
)
54+
ament_target_dependencies(test_load_parallel_gripper_action_controllers
55+
controller_manager
56+
ros2_control_test_assets
57+
)
58+
59+
ament_add_gmock(test_parallel_gripper_controller
60+
test/test_parallel_gripper_controller.cpp
61+
)
62+
target_link_libraries(test_parallel_gripper_controller
63+
parallel_gripper_action_controller
64+
)
65+
endif()
66+
67+
install(
68+
DIRECTORY include/
69+
DESTINATION include/parallel_gripper_action_controller
70+
)
71+
install(
72+
TARGETS
73+
parallel_gripper_action_controller
74+
parallel_gripper_action_controller_parameters
75+
EXPORT export_parallel_gripper_action_controller
76+
RUNTIME DESTINATION bin
77+
ARCHIVE DESTINATION lib
78+
LIBRARY DESTINATION lib
79+
INCLUDES DESTINATION include
80+
)
81+
82+
ament_export_targets(export_parallel_gripper_action_controller HAS_LIBRARY_TARGET)
83+
ament_export_dependencies(${THIS_PACKAGE_INCLUDE_DEPENDS})
84+
ament_package()
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
:github_url: https://github.com/ros-controls/ros2_controllers/blob/{REPOS_FILE_BRANCH}/parallel_gripper_controller/doc/userdoc.rst
2+
3+
.. _parallel_gripper_controller_userdoc:
4+
5+
Parallel Gripper Action Controller
6+
-----------------------------------
7+
8+
Controller for executing a ``ParallelGripperCommand`` action for simple parallel grippers.
9+
This controller supports grippers that offer position only control as well as grippers that allow configuring the velocity and effort.
10+
By default, the controller will only claim the ``{joint}/position`` interface for control.
11+
The velocity and effort interfaces can be optionally claimed by setting the ``max_velocity_interface`` and ``max_effort_interface`` parameter, respectively.
12+
By default, the controller will try to claim position and velocity state interfaces.
13+
The claimed state interfaces can be configured by setting the ``state_interfaces`` parameter.
14+
15+
Parameters
16+
^^^^^^^^^^^
17+
This controller uses the `generate_parameter_library <https://github.com/PickNikRobotics/generate_parameter_library>`_ to handle its parameters.
18+
19+
.. generate_parameter_library_details:: ../src/gripper_action_controller_parameters.yaml
Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
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+
15+
/// \author Sachin Chitta, Adolfo Rodriguez Tsouroukdissian
16+
17+
#ifndef PARALLEL_GRIPPER_CONTROLLER__PARALLEL_GRIPPER_ACTION_CONTROLLER_HPP_
18+
#define PARALLEL_GRIPPER_CONTROLLER__PARALLEL_GRIPPER_ACTION_CONTROLLER_HPP_
19+
20+
// C++ standard
21+
#include <cassert>
22+
#include <memory>
23+
#include <stdexcept>
24+
#include <string>
25+
26+
// ROS
27+
#include "rclcpp/rclcpp.hpp"
28+
29+
// ROS messages
30+
#include "control_msgs/action/parallel_gripper_command.hpp"
31+
32+
// rclcpp_action
33+
#include "rclcpp_action/create_server.hpp"
34+
35+
// ros_controls
36+
#include "controller_interface/controller_interface.hpp"
37+
#include "hardware_interface/loaned_command_interface.hpp"
38+
#include "hardware_interface/loaned_state_interface.hpp"
39+
#include "parallel_gripper_controller/visibility_control.hpp"
40+
#include "realtime_tools/realtime_buffer.h"
41+
#include "realtime_tools/realtime_server_goal_handle.h"
42+
43+
// Project
44+
#include "parallel_gripper_action_controller_parameters.hpp"
45+
46+
namespace parallel_gripper_action_controller
47+
{
48+
/**
49+
* \brief Controller for executing a `ParallelGripperCommand` action.
50+
*
51+
* \tparam HardwareInterface Controller hardware interface. Currently \p
52+
* hardware_interface::HW_IF_POSITION and \p
53+
* hardware_interface::HW_IF_EFFORT are supported out-of-the-box.
54+
*/
55+
56+
class GripperActionController : public controller_interface::ControllerInterface
57+
{
58+
public:
59+
/**
60+
* \brief Store position and max effort in struct to allow easier realtime
61+
* buffer usage
62+
*/
63+
struct Commands
64+
{
65+
double position_cmd_; // Commanded position
66+
double max_velocity_; // Desired max gripper velocity
67+
double max_effort_; // Desired max allowed effort
68+
};
69+
70+
GRIPPER_ACTION_CONTROLLER_PUBLIC GripperActionController();
71+
72+
/**
73+
* @brief command_interface_configuration This controller requires the
74+
* position command interfaces for the controlled joints
75+
*/
76+
GRIPPER_ACTION_CONTROLLER_PUBLIC
77+
controller_interface::InterfaceConfiguration command_interface_configuration() const override;
78+
79+
/**
80+
* @brief command_interface_configuration This controller requires the
81+
* position and velocity state interfaces for the controlled joints
82+
*/
83+
GRIPPER_ACTION_CONTROLLER_PUBLIC
84+
controller_interface::InterfaceConfiguration state_interface_configuration() const override;
85+
86+
GRIPPER_ACTION_CONTROLLER_PUBLIC
87+
controller_interface::return_type update(
88+
const rclcpp::Time & time, const rclcpp::Duration & period) override;
89+
90+
GRIPPER_ACTION_CONTROLLER_PUBLIC
91+
controller_interface::CallbackReturn on_init() override;
92+
93+
GRIPPER_ACTION_CONTROLLER_PUBLIC
94+
controller_interface::CallbackReturn on_configure(
95+
const rclcpp_lifecycle::State & previous_state) override;
96+
97+
GRIPPER_ACTION_CONTROLLER_PUBLIC
98+
controller_interface::CallbackReturn on_activate(
99+
const rclcpp_lifecycle::State & previous_state) override;
100+
101+
GRIPPER_ACTION_CONTROLLER_PUBLIC
102+
controller_interface::CallbackReturn on_deactivate(
103+
const rclcpp_lifecycle::State & previous_state) override;
104+
105+
realtime_tools::RealtimeBuffer<Commands> command_;
106+
// pre-allocated memory that is re-used to set the realtime buffer
107+
Commands command_struct_, command_struct_rt_;
108+
109+
protected:
110+
using GripperCommandAction = control_msgs::action::ParallelGripperCommand;
111+
using ActionServer = rclcpp_action::Server<GripperCommandAction>;
112+
using ActionServerPtr = ActionServer::SharedPtr;
113+
using GoalHandle = rclcpp_action::ServerGoalHandle<GripperCommandAction>;
114+
using RealtimeGoalHandle =
115+
realtime_tools::RealtimeServerGoalHandle<control_msgs::action::ParallelGripperCommand>;
116+
using RealtimeGoalHandlePtr = std::shared_ptr<RealtimeGoalHandle>;
117+
using RealtimeGoalHandleBuffer = realtime_tools::RealtimeBuffer<RealtimeGoalHandlePtr>;
118+
119+
bool update_hold_position_;
120+
121+
bool verbose_ = false; ///< Hard coded verbose flag to help in debugging
122+
std::string name_; ///< Controller name.
123+
std::optional<std::reference_wrapper<hardware_interface::LoanedCommandInterface>>
124+
joint_command_interface_;
125+
std::optional<std::reference_wrapper<hardware_interface::LoanedCommandInterface>>
126+
effort_interface_;
127+
std::optional<std::reference_wrapper<hardware_interface::LoanedCommandInterface>>
128+
speed_interface_;
129+
std::optional<std::reference_wrapper<hardware_interface::LoanedStateInterface>>
130+
joint_position_state_interface_;
131+
std::optional<std::reference_wrapper<hardware_interface::LoanedStateInterface>>
132+
joint_velocity_state_interface_;
133+
134+
std::shared_ptr<ParamListener> param_listener_;
135+
Params params_;
136+
137+
RealtimeGoalHandleBuffer
138+
rt_active_goal_; ///< Container for the currently active action goal, if any.
139+
control_msgs::action::ParallelGripperCommand::Result::SharedPtr pre_alloc_result_;
140+
141+
rclcpp::Duration action_monitor_period_;
142+
143+
// ROS API
144+
ActionServerPtr action_server_;
145+
146+
rclcpp::TimerBase::SharedPtr goal_handle_timer_;
147+
148+
rclcpp_action::GoalResponse goal_callback(
149+
const rclcpp_action::GoalUUID & uuid, std::shared_ptr<const GripperCommandAction::Goal> goal);
150+
151+
rclcpp_action::CancelResponse cancel_callback(const std::shared_ptr<GoalHandle> goal_handle);
152+
153+
void accepted_callback(std::shared_ptr<GoalHandle> goal_handle);
154+
155+
void preempt_active_goal();
156+
157+
void set_hold_position();
158+
159+
rclcpp::Time last_movement_time_ = rclcpp::Time(0, 0, RCL_ROS_TIME); ///< Store stall time
160+
double computed_command_; ///< Computed command
161+
162+
/**
163+
* \brief Check for success and publish appropriate result and feedback.
164+
**/
165+
void check_for_success(
166+
const rclcpp::Time & time, double error_position, double current_position,
167+
double current_velocity);
168+
};
169+
170+
} // namespace parallel_gripper_action_controller
171+
172+
#include "parallel_gripper_controller/parallel_gripper_action_controller_impl.hpp"
173+
174+
#endif // PARALLEL_GRIPPER_CONTROLLER__PARALLEL_GRIPPER_ACTION_CONTROLLER_HPP_

0 commit comments

Comments
 (0)