ros2_control - jazzy
Loading...
Searching...
No Matches
joint_soft_limiter.hpp
1// Copyright 2024 PAL Robotics S.L.
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_SOFT_LIMITER_HPP_
18#define JOINT_LIMITS__JOINT_SOFT_LIMITER_HPP_
19
20#include <cmath>
21#include "joint_limits/data_structures.hpp"
22#include "joint_limits/joint_limits_helpers.hpp"
23#include "joint_limits/joint_saturation_limiter.hpp"
24
25constexpr double VALUE_CONSIDERED_ZERO = 1e-10;
26
27namespace joint_limits
28{
29
30class JointSoftLimiter : public JointSaturationLimiter<JointControlInterfacesData>
31{
32public:
33 virtual ~JointSoftLimiter() = default;
34
35 bool on_init() override
36 {
37 const bool result = (number_of_joints_ == 1);
38 if (!result && has_logging_interface())
39 {
40 RCLCPP_ERROR(
41 node_logging_itf_->get_logger(),
42 "JointInterfacesSaturationLimiter: Expects the number of joints to be 1, but given : "
43 "%zu",
44 number_of_joints_);
45 }
46 prev_command_ = JointControlInterfacesData();
47 return result;
48 }
49
50 bool on_enforce(
52 const rclcpp::Duration & dt) override;
53
54 bool has_soft_position_limits(const joint_limits::SoftJointLimits & soft_joint_limits)
55 {
56 return std::isfinite(soft_joint_limits.min_position) &&
57 std::isfinite(soft_joint_limits.max_position) &&
58 (soft_joint_limits.max_position - soft_joint_limits.min_position) >
59 VALUE_CONSIDERED_ZERO;
60 }
61
62 bool has_soft_limits(const joint_limits::SoftJointLimits & soft_joint_limits)
63 {
64 return has_soft_position_limits(soft_joint_limits) &&
65 std::isfinite(soft_joint_limits.k_position) &&
66 std::abs(soft_joint_limits.k_position) > VALUE_CONSIDERED_ZERO;
67 }
68};
69
70} // namespace joint_limits
71
72#endif // JOINT_LIMITS__JOINT_SOFT_LIMITER_HPP_
bool has_logging_interface() const
Checks if the logging interface is set.
Definition joint_limiter_interface.hpp:248
Definition joint_saturation_limiter.hpp:38
Definition joint_soft_limiter.hpp:31
bool on_enforce(const JointControlInterfacesData &actual, JointControlInterfacesData &desired, const rclcpp::Duration &dt) override
Definition joint_soft_limiter.cpp:22
bool on_init() override
Method is realized by an implementation.
Definition joint_soft_limiter.hpp:35
Definition data_structures.hpp:39
Definition data_structures.hpp:47
Definition joint_limits.hpp:113