26#ifndef TESSERACT_COMMON_KINEMATIC_LIMITS_H
27#define TESSERACT_COMMON_KINEMATIC_LIMITS_H
31#include <Eigen/Geometry>
32#include <boost/serialization/base_object.hpp>
41 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
53 void resize(Eigen::Index size);
60 template <
class Archive>
61 void serialize(Archive& ar,
const unsigned int version);
70template <
typename FloatType>
72 const Eigen::Ref<
const Eigen::Matrix<FloatType, Eigen::Dynamic, 2>>& position_limits)
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());
90template <
typename FloatType>
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)
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();
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;
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;
112 return (lower_check.all() && upper_check.all());
125template <
typename FloatType>
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())
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);
135 return satisfiesPositionLimits<FloatType>(joint_positions, position_limits, eigen_max_diff, eigen_max_rel_diff);
143template <
typename FloatType>
145 const Eigen::Ref<
const Eigen::Matrix<FloatType, Eigen::Dynamic, 2>>& position_limits)
147 joint_positions = joint_positions.array().min(position_limits.col(1).array()).max(position_limits.col(0).array());
#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