ros2_control - rolling
Loading...
Searching...
No Matches
motion_primitives_base_controller.hpp
1// Copyright (c) 2025, b»robotized
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// Authors: Mathias Fuhrer
16
17#ifndef MOTION_PRIMITIVES_CONTROLLERS__MOTION_PRIMITIVES_BASE_CONTROLLER_HPP_
18#define MOTION_PRIMITIVES_CONTROLLERS__MOTION_PRIMITIVES_BASE_CONTROLLER_HPP_
19
20#include <chrono>
21#include <memory>
22#include <string>
23#include <vector>
24
25#include <realtime_tools/lock_free_queue.hpp>
26#include <realtime_tools/realtime_server_goal_handle.hpp>
27#include "controller_interface/controller_interface.hpp"
28#include "rclcpp_lifecycle/node_interfaces/lifecycle_node_interface.hpp"
29#include "rclcpp_lifecycle/state.hpp"
30#include "realtime_tools/realtime_buffer.hpp"
31#include "realtime_tools/realtime_publisher.hpp"
32#include "realtime_tools/realtime_thread_safe_box.hpp"
33
34#include "control_msgs/msg/motion_primitive.hpp"
35#include "rclcpp_action/rclcpp_action.hpp"
36
37namespace motion_primitives_controllers
38{
39enum class ExecutionState : uint8_t
40{
41 IDLE = 0,
42 EXECUTING = 1,
43 SUCCESS = 2,
44 ERROR = 3,
45 STOPPING = 4,
46 STOPPED = 5
47};
48
49using MotionType = control_msgs::msg::MotionPrimitive;
50enum class MotionHelperType : uint8_t
51{
52 STOP_MOTION = 66,
53 RESET_STOP = 67,
54
55 MOTION_SEQUENCE_START = 100,
56 MOTION_SEQUENCE_END = 101
57};
58
59enum class ReadyForNewPrimitive : uint8_t
60{
61 NOT_READY = 0,
62 READY = 1
63};
64
66{
67public:
69
70 controller_interface::CallbackReturn on_init() override;
71
73
75
76 controller_interface::CallbackReturn on_configure(
77 const rclcpp_lifecycle::State & previous_state) override;
78
79 controller_interface::CallbackReturn on_activate(
80 const rclcpp_lifecycle::State & previous_state) override;
81
82 controller_interface::CallbackReturn on_deactivate(
83 const rclcpp_lifecycle::State & previous_state) override;
84
85 controller_interface::return_type update(
86 const rclcpp::Time & time, const rclcpp::Duration & period) override;
87
88protected:
89 std::string tf_prefix_;
90
91 using MotionPrimitive = control_msgs::msg::MotionPrimitive;
93
94 std::atomic<bool> has_active_goal_ = false;
95 rclcpp::TimerBase::SharedPtr goal_handle_timer_;
96 rclcpp::Duration action_monitor_period_ = rclcpp::Duration(std::chrono::milliseconds(20));
97
98 void reset_command_interfaces();
99 bool set_command_interfaces();
100
101 bool print_error_once_ = true;
102 // cancel requested by the action server
103 std::atomic<bool> cancel_requested_ = false;
104 // robot stop command sent to the hardware interface
105 std::atomic<bool> robot_stop_requested_ = false;
106 bool was_executing_ = false;
107 ExecutionState execution_status_;
108 ReadyForNewPrimitive ready_for_new_primitive_;
109 MotionPrimitive current_moprim_;
110};
111
112} // namespace motion_primitives_controllers
113
114#endif // MOTION_PRIMITIVES_CONTROLLERS__MOTION_PRIMITIVES_BASE_CONTROLLER_HPP_
Definition controller_interface.hpp:27
Definition motion_primitives_base_controller.hpp:66
controller_interface::InterfaceConfiguration command_interface_configuration() const override
Get configuration for controller's required command interfaces.
Definition motion_primitives_base_controller.cpp:48
controller_interface::return_type update(const rclcpp::Time &time, const rclcpp::Duration &period) override
Definition motion_primitives_base_controller.cpp:108
controller_interface::InterfaceConfiguration state_interface_configuration() const override
Get configuration for controller's required state interfaces.
Definition motion_primitives_base_controller.cpp:82
controller_interface::CallbackReturn on_init() override
Extending interface with initialization method which is individual for each controller.
Definition motion_primitives_base_controller.cpp:31
std::conditional_t< Capacity==0, LockFreeQueueBase< DataType, boost::lockfree::spsc_queue< DataType > >, LockFreeQueueBase< DataType, boost::lockfree::spsc_queue< DataType, boost::lockfree::capacity< Capacity > > > > LockFreeSPSCQueue
Lock-free Single Producer Single Consumer Queue.
Definition lock_free_queue.hpp:314
Configuring what command/state interfaces to claim.
Definition controller_interface_base.hpp:58