38 #include <Eigen/Dense> 39 #include <Eigen/Eigenvalues> 40 #include <boost/math/constants/constants.hpp> 49 double joint_limits_multiplier(1.0);
50 const std::vector<const robot_model::JointModel*>& joint_model_vector = joint_model_group->
getJointModels();
51 for (std::size_t i = 0; i < joint_model_vector.size(); ++i)
63 if (bounds[0].min_position_ == -std::numeric_limits<double>::max() ||
64 bounds[0].max_position_ == std::numeric_limits<double>::max() ||
65 bounds[1].min_position_ == -std::numeric_limits<double>::max() ||
66 bounds[1].max_position_ == std::numeric_limits<double>::max() ||
67 bounds[2].min_position_ == -boost::math::constants::pi<double>() ||
68 bounds[2].max_position_ == boost::math::constants::pi<double>())
78 std::vector<double> lower_bounds, upper_bounds;
79 for (std::size_t j = 0; j < bounds.size(); ++j)
81 lower_bounds.push_back(bounds[j].min_position_);
82 upper_bounds.push_back(bounds[j].max_position_);
84 double lower_bound_distance = joint_model_vector[i]->distance(joint_values, &lower_bounds[0]);
85 double upper_bound_distance = joint_model_vector[i]->distance(joint_values, &upper_bounds[0]);
86 double range = lower_bound_distance + upper_bound_distance;
87 if (range <= boost::math::tools::epsilon<double>())
89 joint_limits_multiplier *= (lower_bound_distance * upper_bound_distance / (range * range));
95 double& manipulability_index,
bool translation)
const 98 if (joint_model_group)
106 double& manipulability_index,
bool translation)
const 109 if (!joint_model_group->
isChain())
114 Eigen::MatrixXd jacobian = state.
getJacobian(joint_model_group);
119 if (jacobian.cols() < 6)
121 Eigen::JacobiSVD<Eigen::MatrixXd> svdsolver(jacobian.topLeftCorner(3, jacobian.cols()));
122 Eigen::MatrixXd singular_values = svdsolver.singularValues();
123 manipulability_index = 1.0;
124 for (
unsigned int i = 0; i < singular_values.rows(); ++i)
126 ROS_DEBUG_NAMED(
"kinematics_metrics",
"Singular value: %d %f", i, singular_values(i, 0));
127 manipulability_index *= singular_values(i, 0);
130 manipulability_index = penalty * manipulability_index;
134 Eigen::MatrixXd jacobian_2 = jacobian.topLeftCorner(3, jacobian.cols());
135 Eigen::MatrixXd matrix = jacobian_2 * jacobian_2.transpose();
137 manipulability_index = penalty *
sqrt(matrix.determinant());
142 if (jacobian.cols() < 6)
144 Eigen::JacobiSVD<Eigen::MatrixXd> svdsolver(jacobian);
145 Eigen::MatrixXd singular_values = svdsolver.singularValues();
146 manipulability_index = 1.0;
147 for (
unsigned int i = 0; i < singular_values.rows(); ++i)
149 ROS_DEBUG_NAMED(
"kinematics_metrics",
"Singular value: %d %f", i, singular_values(i, 0));
150 manipulability_index *= singular_values(i, 0);
153 manipulability_index = penalty * manipulability_index;
157 Eigen::MatrixXd matrix = jacobian * jacobian.transpose();
159 manipulability_index = penalty *
sqrt(matrix.determinant());
166 Eigen::MatrixXcd& eigen_values,
167 Eigen::MatrixXcd& eigen_vectors)
const 170 if (joint_model_group)
178 Eigen::MatrixXcd& eigen_values,
179 Eigen::MatrixXcd& eigen_vectors)
const 182 if (!joint_model_group->
isChain())
187 Eigen::MatrixXd jacobian = state.
getJacobian(joint_model_group);
188 Eigen::MatrixXd matrix = jacobian * jacobian.transpose();
189 Eigen::EigenSolver<Eigen::MatrixXd> eigensolver(matrix.block(0, 0, 3, 3));
190 eigen_values = eigensolver.eigenvalues();
191 eigen_vectors = eigensolver.eigenvectors();
196 double& manipulability,
bool translation)
const 199 if (joint_model_group)
207 bool translation)
const 210 if (!joint_model_group->
isChain())
218 Eigen::MatrixXd jacobian = state.
getJacobian(joint_model_group);
219 Eigen::JacobiSVD<Eigen::MatrixXd> svdsolver(jacobian.topLeftCorner(3, jacobian.cols()));
220 Eigen::MatrixXd singular_values = svdsolver.singularValues();
221 for (
int i = 0; i < singular_values.rows(); ++i)
222 ROS_DEBUG_NAMED(
"kinematics_metrics",
"Singular value: %d %f", i, singular_values(i, 0));
223 manipulability = penalty * singular_values.minCoeff() / singular_values.maxCoeff();
227 Eigen::MatrixXd jacobian = state.
getJacobian(joint_model_group);
228 Eigen::JacobiSVD<Eigen::MatrixXd> svdsolver(jacobian);
229 Eigen::MatrixXd singular_values = svdsolver.singularValues();
230 for (
int i = 0; i < singular_values.rows(); ++i)
231 ROS_DEBUG_NAMED(
"kinematics_metrics",
"Singular value: %d %f", i, singular_values(i, 0));
232 manipulability = penalty * singular_values.minCoeff() / singular_values.maxCoeff();
bool isChain() const
Check if this group is a linear chain.
double getJointLimitsPenalty(const robot_state::RobotState &state, const robot_model::JointModelGroup *joint_model_group) const
Defines a multiplier for the manipulabilty = 1 - exp ( -penalty_multipler_ * product_{i=1}{n} (distan...
bool isContinuous() const
Check if this joint wraps around.
bool getManipulabilityEllipsoid(const robot_state::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...
#define ROS_DEBUG_NAMED(name,...)
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...
bool getManipulability(const robot_state::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...
INLINE Rall1d< T, V, S > sqrt(const Rall1d< T, V, S > &arg)
const std::vector< const JointModel * > & getJointModels() const
Get all the joints in this group (including fixed and mimic joints).
INLINE Rall1d< T, V, S > exp(const Rall1d< T, V, S > &arg)
robot_model::RobotModelConstPtr robot_model_
Representation of a robot's state. This includes position, velocity, acceleration and effort...
double penalty_multiplier_
bool getManipulabilityIndex(const robot_state::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.
const double * getJointPositions(const std::string &joint_name) const
std::vector< VariableBounds > Bounds
The datatype for the joint bounds.
Namespace for kinematics metrics.