38#include <Eigen/Eigenvalues>
42#include <rclcpp/logger.hpp>
43#include <rclcpp/logging.hpp>
59 if (fabs(penalty_multiplier_) <= std::numeric_limits<double>::min())
61 double joint_limits_multiplier(1.0);
62 const std::vector<const moveit::core::JointModel*>& joint_model_vector = joint_model_group->
getJointModels();
75 if (bounds[0].min_position_ == -std::numeric_limits<double>::max() ||
76 bounds[0].max_position_ == std::numeric_limits<double>::max() ||
77 bounds[1].min_position_ == -std::numeric_limits<double>::max() ||
78 bounds[1].max_position_ == std::numeric_limits<double>::max() || bounds[2].min_position_ == -M_PI ||
79 bounds[2].max_position_ == M_PI)
89 std::vector<double> lower_bounds, upper_bounds;
92 lower_bounds.push_back(bound.min_position_);
93 upper_bounds.push_back(bound.max_position_);
95 double lower_bound_distance = joint_model->distance(joint_values, &lower_bounds[0]);
96 double upper_bound_distance = joint_model->distance(joint_values, &upper_bounds[0]);
97 double range = lower_bound_distance + upper_bound_distance;
98 if (range <= std::numeric_limits<double>::min())
100 joint_limits_multiplier *= (lower_bound_distance * upper_bound_distance / (range * range));
102 return (1.0 - exp(-penalty_multiplier_ * joint_limits_multiplier));
106 double& manipulability_index,
bool translation)
const
109 if (joint_model_group)
121 double& manipulability_index,
bool translation)
const
124 if (!joint_model_group->
isChain())
129 Eigen::MatrixXd jacobian = state.
getJacobian(joint_model_group);
131 double penalty = getJointLimitsPenalty(state, joint_model_group);
134 if (jacobian.cols() < 6)
136 Eigen::JacobiSVD<Eigen::MatrixXd> svdsolver(jacobian.topLeftCorner(3, jacobian.cols()));
137 Eigen::MatrixXd singular_values = svdsolver.singularValues();
138 manipulability_index = 1.0;
139 for (
unsigned int i = 0; i < singular_values.rows(); ++i)
141 RCLCPP_DEBUG(getLogger(),
"Singular value: %d %f", i, singular_values(i, 0));
142 manipulability_index *= singular_values(i, 0);
145 manipulability_index = penalty * manipulability_index;
149 Eigen::MatrixXd jacobian_2 = jacobian.topLeftCorner(3, jacobian.cols());
150 Eigen::MatrixXd matrix = jacobian_2 * jacobian_2.transpose();
152 manipulability_index = penalty * sqrt(matrix.determinant());
157 if (jacobian.cols() < 6)
159 Eigen::JacobiSVD<Eigen::MatrixXd> svdsolver(jacobian);
160 Eigen::MatrixXd singular_values = svdsolver.singularValues();
161 manipulability_index = 1.0;
162 for (
unsigned int i = 0; i < singular_values.rows(); ++i)
164 RCLCPP_DEBUG(getLogger(),
"Singular value: %d %f", i, singular_values(i, 0));
165 manipulability_index *= singular_values(i, 0);
168 manipulability_index = penalty * manipulability_index;
172 Eigen::MatrixXd matrix = jacobian * jacobian.transpose();
174 manipulability_index = penalty * sqrt(matrix.determinant());
181 Eigen::MatrixXcd& eigen_values,
182 Eigen::MatrixXcd& eigen_vectors)
const
185 if (joint_model_group)
197 Eigen::MatrixXcd& eigen_values,
198 Eigen::MatrixXcd& eigen_vectors)
const
201 if (!joint_model_group->
isChain())
206 Eigen::MatrixXd jacobian = state.
getJacobian(joint_model_group);
207 Eigen::MatrixXd matrix = jacobian * jacobian.transpose();
208 Eigen::EigenSolver<Eigen::MatrixXd> eigensolver(matrix.block(0, 0, 3, 3));
209 eigen_values = eigensolver.eigenvalues();
210 eigen_vectors = eigensolver.eigenvectors();
215 double& manipulability,
bool translation)
const
218 if (joint_model_group)
230 double& manipulability,
bool translation)
const
233 if (!joint_model_group->
isChain())
238 double penalty = getJointLimitsPenalty(state, joint_model_group);
241 Eigen::MatrixXd jacobian = state.
getJacobian(joint_model_group);
242 Eigen::JacobiSVD<Eigen::MatrixXd> svdsolver(jacobian.topLeftCorner(3, jacobian.cols()));
243 Eigen::MatrixXd singular_values = svdsolver.singularValues();
244 for (
int i = 0; i < singular_values.rows(); ++i)
246 RCLCPP_DEBUG(getLogger(),
"Singular value: %d %f", i, singular_values(i, 0));
249 manipulability = penalty * singular_values.minCoeff() / singular_values.maxCoeff();
253 Eigen::MatrixXd jacobian = state.
getJacobian(joint_model_group);
254 Eigen::JacobiSVD<Eigen::MatrixXd> svdsolver(jacobian);
255 Eigen::MatrixXd singular_values = svdsolver.singularValues();
256 for (
int i = 0; i < singular_values.rows(); ++i)
258 RCLCPP_DEBUG(getLogger(),
"Singular value: %d %f", i, singular_values(i, 0));
260 manipulability = penalty * singular_values.minCoeff() / singular_values.maxCoeff();
bool getManipulability(const moveit::core::RobotState &state, const std::string &group_name, double &condition_number, bool translation=false) const
Get the manipulability = sigma_min/sigma_max where sigma_min and sigma_max are the smallest and large...
bool getManipulabilityIndex(const moveit::core::RobotState &state, const std::string &group_name, double &manipulability_index, bool translation=false) const
Get the manipulability for a given group at a given joint configuration.
moveit::core::RobotModelConstPtr robot_model_
bool getManipulabilityEllipsoid(const moveit::core::RobotState &state, const std::string &group_name, Eigen::MatrixXcd &eigen_values, Eigen::MatrixXcd &eigen_vectors) const
Get the (translation) manipulability ellipsoid for a given group at a given joint configuration.
bool isChain() const
Check if this group is a linear chain.
const std::vector< const JointModel * > & getJointModels() const
Get all the joints in this group (including fixed and mimic joints).
A joint from the robot. Models the transform that this joint applies in the kinematic chain....
std::vector< VariableBounds > Bounds
The datatype for the joint bounds.
const VariableBounds & getVariableBounds(const std::string &variable) const
Get the bounds for a variable. Throw an exception if the variable was not found.
bool isContinuous() const
Check if this joint wraps around.
Representation of a robot's state. This includes position, velocity, acceleration and effort.
bool getJacobian(const JointModelGroup *group, const LinkModel *link, const Eigen::Vector3d &reference_point_position, Eigen::MatrixXd &jacobian, bool use_quaternion_representation=false) const
Compute the Jacobian with reference to a particular point on a given link, for a specified group.
const double * getJointPositions(const std::string &joint_name) const
rclcpp::Logger getLogger()
Namespace for kinematics metrics.
rclcpp::Logger getLogger(const std::string &name)
Creates a namespaced logger.