ros2_control - rolling
Loading...
Searching...
No Matches
joint_limits_urdf.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_LIMITS_URDF_HPP_
18#define JOINT_LIMITS__JOINT_LIMITS_URDF_HPP_
19
20#include <cmath>
21
22#include "joint_limits/joint_limits.hpp"
23#include "urdf_model/joint.h"
24
25namespace joint_limits
26{
27
36inline bool getJointLimits(urdf::JointConstSharedPtr urdf_joint, JointLimits & limits)
37{
38 if (!urdf_joint || !urdf_joint->limits)
39 {
40 return false;
41 }
42
43 limits.has_position_limits =
44 urdf_joint->type == urdf::Joint::REVOLUTE || urdf_joint->type == urdf::Joint::PRISMATIC;
45 if (limits.has_position_limits)
46 {
47 limits.min_position = urdf_joint->limits->lower;
48 limits.max_position = urdf_joint->limits->upper;
49 }
50
51 if (!limits.has_position_limits && urdf_joint->type == urdf::Joint::CONTINUOUS)
52 {
53 limits.angle_wraparound = true;
54 }
55
56 limits.has_velocity_limits = true;
57 limits.max_velocity = std::abs(urdf_joint->limits->velocity);
58
59 limits.has_acceleration_limits = false;
60
61 limits.has_effort_limits = true;
62 limits.max_effort = std::abs(urdf_joint->limits->effort);
63
64 return true;
65}
66
74inline bool getSoftJointLimits(urdf::JointConstSharedPtr urdf_joint, SoftJointLimits & soft_limits)
75{
76 if (!urdf_joint || !urdf_joint->safety)
77 {
78 return false;
79 }
80
81 soft_limits.min_position = urdf_joint->safety->soft_lower_limit;
82 soft_limits.max_position = urdf_joint->safety->soft_upper_limit;
83 soft_limits.k_position = urdf_joint->safety->k_position;
84 soft_limits.k_velocity = urdf_joint->safety->k_velocity;
85
86 return true;
87}
88} // namespace joint_limits
89#endif // JOINT_LIMITS__JOINT_LIMITS_URDF_HPP_
Definition data_structures.hpp:38
bool getSoftJointLimits(urdf::JointConstSharedPtr urdf_joint, SoftJointLimits &soft_limits)
Populate a SoftJointLimits instance from URDF joint data.
Definition joint_limits_urdf.hpp:74
bool getJointLimits(urdf::JointConstSharedPtr urdf_joint, JointLimits &limits)
Populate a JointLimits instance from URDF joint data.
Definition joint_limits_urdf.hpp:36
Store joint limits values from YAML definition or URDF <limits> tag.
Definition joint_limits.hpp:36
Store soft joint limits values from the URDF <safety_controller> tag.
Definition joint_limits.hpp:130