ros2_control - rolling
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 bool on_init() override
34 {
35 const bool result = (number_of_joints_ == 1);
36 if (!result && has_logging_interface())
37 {
38 RCLCPP_ERROR(
39 node_logging_itf_->get_logger(),
40 "JointInterfacesSaturationLimiter: Expects the number of joints to be 1, but given : "
41 "%zu",
42 number_of_joints_);
43 }
44 prev_command_ = JointControlInterfacesData();
45 return result;
46 }
47
48 bool on_enforce(
50 const rclcpp::Duration & dt) override;
51
52 bool has_soft_position_limits(const joint_limits::SoftJointLimits & soft_joint_limits)
53 {
54 return std::isfinite(soft_joint_limits.min_position) &&
55 std::isfinite(soft_joint_limits.max_position) &&
56 (soft_joint_limits.max_position - soft_joint_limits.min_position) >
57 VALUE_CONSIDERED_ZERO;
58 }
59
60 bool has_soft_limits(const joint_limits::SoftJointLimits & soft_joint_limits)
61 {
62 return has_soft_position_limits(soft_joint_limits) &&
63 std::isfinite(soft_joint_limits.k_position) &&
64 std::abs(soft_joint_limits.k_position) > VALUE_CONSIDERED_ZERO;
65 }
66};
67
68} // namespace joint_limits
69
70#endif // JOINT_LIMITS__JOINT_SOFT_LIMITER_HPP_
bool has_logging_interface() const
Checks if the logging interface is set.
Definition joint_limiter_interface.hpp:246
Definition joint_saturation_limiter.hpp:38
Definition joint_soft_limiter.hpp:31
bool on_init() override
Method is realized by an implementation.
Definition joint_soft_limiter.hpp:33
Definition data_structures.hpp:37
Definition data_structures.hpp:45
Definition joint_limits.hpp:113