Tesseract
Motion Planning Environment
Loading...
Searching...
No Matches
kinematic_limits.h
Go to the documentation of this file.
1
26#ifndef TESSERACT_COMMON_KINEMATIC_LIMITS_H
27#define TESSERACT_COMMON_KINEMATIC_LIMITS_H
30#include <Eigen/Core>
31#include <Eigen/Geometry>
32#include <boost/serialization/base_object.hpp>
34
35namespace tesseract_common
36{
39{
40 // LCOV_EXCL_START
41 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
42 // LCOV_EXCL_STOP
43
45 Eigen::MatrixX2d joint_limits;
46
48 Eigen::VectorXd velocity_limits;
49
51 Eigen::VectorXd acceleration_limits;
52
53 void resize(Eigen::Index size);
54
55 bool operator==(const KinematicLimits& rhs) const;
56 bool operator!=(const KinematicLimits& rhs) const;
57
58private:
60 template <class Archive>
61 void serialize(Archive& ar, const unsigned int version); // NOLINT
62};
63
70template <typename FloatType>
71bool isWithinPositionLimits(const Eigen::Ref<const Eigen::Matrix<FloatType, Eigen::Dynamic, 1>>& joint_positions,
72 const Eigen::Ref<const Eigen::Matrix<FloatType, Eigen::Dynamic, 2>>& position_limits)
73{
74 auto p = joint_positions.array();
75 auto l0 = position_limits.col(0).array();
76 auto l1 = position_limits.col(1).array();
77 return (!(p > l1).any() && !(p < l0).any());
78}
79
90template <typename FloatType>
91bool satisfiesPositionLimits(const Eigen::Ref<const Eigen::Matrix<FloatType, Eigen::Dynamic, 1>>& joint_positions,
92 const Eigen::Ref<const Eigen::Matrix<FloatType, Eigen::Dynamic, 2>>& position_limits,
93 const Eigen::Ref<const Eigen::Matrix<FloatType, Eigen::Dynamic, 1>>& max_diff,
94 const Eigen::Ref<const Eigen::Matrix<FloatType, Eigen::Dynamic, 1>>& max_rel_diff)
95{
96 auto p = joint_positions.array();
97 auto l0 = position_limits.col(0).array();
98 auto l1 = position_limits.col(1).array();
99 auto md = max_diff.array();
100 auto mrd = max_rel_diff.array();
101
102 auto lower_diff_abs = (p - l0).abs();
103 auto lower_diff = (lower_diff_abs <= md);
104 auto lower_relative_diff = (lower_diff_abs <= mrd * p.abs().max(l0.abs()));
105 auto lower_check = p > l0 || lower_diff || lower_relative_diff;
106
107 auto upper_diff_abs = (p - l1).abs();
108 auto upper_diff = (upper_diff_abs <= md);
109 auto upper_relative_diff = (upper_diff_abs <= mrd * p.abs().max(l1.abs()));
110 auto upper_check = p < l1 || upper_diff || upper_relative_diff;
111
112 return (lower_check.all() && upper_check.all());
113}
114
125template <typename FloatType>
126bool satisfiesPositionLimits(const Eigen::Ref<const Eigen::Matrix<FloatType, Eigen::Dynamic, 1>>& joint_positions,
127 const Eigen::Ref<const Eigen::Matrix<FloatType, Eigen::Dynamic, 2>>& position_limits,
128 FloatType max_diff = static_cast<FloatType>(1e-6),
129 FloatType max_rel_diff = std::numeric_limits<FloatType>::epsilon())
130{
131 const auto eigen_max_diff = Eigen::Matrix<FloatType, Eigen::Dynamic, 1>::Constant(joint_positions.size(), max_diff);
132 const auto eigen_max_rel_diff =
133 Eigen::Matrix<FloatType, Eigen::Dynamic, 1>::Constant(joint_positions.size(), max_rel_diff);
134 // NOLINTNEXTLINE(clang-analyzer-core.uninitialized.UndefReturn)
135 return satisfiesPositionLimits<FloatType>(joint_positions, position_limits, eigen_max_diff, eigen_max_rel_diff);
136}
137
143template <typename FloatType>
144void enforcePositionLimits(Eigen::Ref<Eigen::Matrix<FloatType, Eigen::Dynamic, 1>> joint_positions,
145 const Eigen::Ref<const Eigen::Matrix<FloatType, Eigen::Dynamic, 2>>& position_limits)
146{
147 joint_positions = joint_positions.array().min(position_limits.col(1).array()).max(position_limits.col(0).array());
148}
149} // namespace tesseract_common
150
151#endif // TESSERACT_COMMON_KINEMATIC_LIMITS_H
Common Tesseract Macros.
#define TESSERACT_COMMON_IGNORE_WARNINGS_PUSH
Definition: macros.h:71
Definition: create_convex_hull.cpp:36
Definition: allowed_collision_matrix.h:16
void enforcePositionLimits(Eigen::Ref< Eigen::Matrix< FloatType, Eigen::Dynamic, 1 > > joint_positions, const Eigen::Ref< const Eigen::Matrix< FloatType, Eigen::Dynamic, 2 > > &position_limits)
Enforce position to be within the provided limits.
Definition: kinematic_limits.h:144
bool satisfiesPositionLimits(const Eigen::Ref< const Eigen::Matrix< FloatType, Eigen::Dynamic, 1 > > &joint_positions, const Eigen::Ref< const Eigen::Matrix< FloatType, Eigen::Dynamic, 2 > > &position_limits, const Eigen::Ref< const Eigen::Matrix< FloatType, Eigen::Dynamic, 1 > > &max_diff, const Eigen::Ref< const Eigen::Matrix< FloatType, Eigen::Dynamic, 1 > > &max_rel_diff)
Check if joint position is within bounds or relatively equal to a limit.
Definition: kinematic_limits.h:91
bool isWithinPositionLimits(const Eigen::Ref< const Eigen::Matrix< FloatType, Eigen::Dynamic, 1 > > &joint_positions, const Eigen::Ref< const Eigen::Matrix< FloatType, Eigen::Dynamic, 2 > > &position_limits)
Check if within position limits.
Definition: kinematic_limits.h:71
Store kinematic limits.
Definition: kinematic_limits.h:39
bool operator!=(const KinematicLimits &rhs) const
Definition: kinematic_limits.cpp:54
EIGEN_MAKE_ALIGNED_OPERATOR_NEW Eigen::MatrixX2d joint_limits
The position limits.
Definition: kinematic_limits.h:45
Eigen::VectorXd acceleration_limits
The acceleration limits.
Definition: kinematic_limits.h:51
void serialize(Archive &ar, const unsigned int version)
Definition: kinematic_limits.cpp:57
void resize(Eigen::Index size)
Definition: kinematic_limits.cpp:38
friend class boost::serialization::access
Definition: kinematic_limits.h:59
bool operator==(const KinematicLimits &rhs) const
Definition: kinematic_limits.cpp:45
Eigen::VectorXd velocity_limits
The velocity limits.
Definition: kinematic_limits.h:48