ros2_control - rolling
Loading...
Searching...
No Matches
joint_saturation_limiter.hpp
1// Copyright (c) 2024, PickNik Inc.
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 JOINT_LIMITS__JOINT_SATURATION_LIMITER_HPP_
18#define JOINT_LIMITS__JOINT_SATURATION_LIMITER_HPP_
19
20#include <memory>
21#include <vector>
22
23#include "joint_limits/data_structures.hpp"
24#include "joint_limits/joint_limiter_interface.hpp"
25#include "rclcpp/clock.hpp"
26#include "rclcpp/duration.hpp"
27
28namespace joint_limits
29{
38template <typename JointLimitsStateDataType>
39class JointSaturationLimiter : public JointLimiterInterface<JointLimitsStateDataType>
40{
41public:
44
47
48 bool on_init() override;
49
50 bool on_configure(const JointLimitsStateDataType & current_joint_states) override
51 {
52 prev_command_ = current_joint_states;
53 return true;
54 }
55
75 const JointLimitsStateDataType & current_joint_states,
76 JointLimitsStateDataType & desired_joint_states, const rclcpp::Duration & dt) override;
77
84 void reset_internals() override
85 {
86 std::lock_guard<std::mutex> lock(mutex_);
87 prev_command_ = JointLimitsStateDataType();
88 }
89
90protected:
91 rclcpp::Clock::SharedPtr clock_;
92 JointLimitsStateDataType prev_command_;
93 std::mutex mutex_;
94};
95
96template <typename JointLimitsStateDataType>
98: JointLimiterInterface<JointLimitsStateDataType>()
99{
100 clock_ = std::make_shared<rclcpp::Clock>(rclcpp::Clock(RCL_ROS_TIME));
101}
102
103template <typename JointLimitsStateDataType>
107
108template <typename JointLimitsStateDataType>
113
114template <>
116
117} // namespace joint_limits
118
119#endif // JOINT_LIMITS__JOINT_SATURATION_LIMITER_HPP_
Definition joint_limiter_interface.hpp:35
Limit joints' position, velocity and acceleration by clamping to their allowed ranges.
Definition joint_saturation_limiter.hpp:40
JointSaturationLimiter()
Constructor.
Definition joint_saturation_limiter.hpp:97
bool on_enforce(const JointLimitsStateDataType &current_joint_states, JointLimitsStateDataType &desired_joint_states, const rclcpp::Duration &dt) override
Enforce joint limits to desired position, velocity and acceleration using clamping.
virtual ~JointSaturationLimiter()
Destructor.
Definition joint_saturation_limiter.hpp:104
bool on_init() override
Initialize the limiter's internal states and libraries.
Definition joint_saturation_limiter.hpp:109
void reset_internals() override
Reset internal states of the limiter.
Definition joint_saturation_limiter.hpp:84
bool on_configure(const JointLimitsStateDataType &current_joint_states) override
Configure the limiter's internal states and libraries.
Definition joint_saturation_limiter.hpp:50
Definition data_structures.hpp:39