Skip to content

Commit 2485c2e

Browse files
committed
Add utility functionality to extract limits from JMG
1 parent 5e3d003 commit 2485c2e

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

moveit_core/robot_model/include/moveit/robot_model/joint_model_group.h

+19
Original file line numberDiff line numberDiff line change
@@ -754,5 +754,24 @@ class JointModelGroup
754754
/** \brief The names of the default states specified for this group in the SRDF */
755755
std::vector<std::string> default_states_names_;
756756
};
757+
758+
/**
759+
* @brief Get the lower and upper position limits of a given joint group.
760+
*
761+
* @param group Joint model group from which the limits are read
762+
* @return std::pair<Eigen::VectorXd, Eigen::VectorXd> Containing the joint limits
763+
*/
764+
[[nodiscard]] std::pair<Eigen::VectorXd, Eigen::VectorXd>
765+
getLowerAndUpperLimits(const moveit::core::JointModelGroup& group);
766+
767+
/**
768+
* @brief Gets the pair of maximum joint velocities/accelerations for a given group. Asserts that the group contains
769+
* only single-variable joints,
770+
*
771+
* @param group Joint model group from which the limits are read
772+
* @return std::pair<Eigen::VectorXd, Eigen::VectorXd> Containing the velocity and acceleration limits
773+
*/
774+
[[nodiscard]] std::pair<Eigen::VectorXd, Eigen::VectorXd>
775+
getMaximumVelocitiesAndAccelerations(const moveit::core::JointModelGroup& group);
757776
} // namespace core
758777
} // namespace moveit

moveit_core/robot_model/src/joint_model_group.cpp

+36
Original file line numberDiff line numberDiff line change
@@ -831,5 +831,41 @@ bool JointModelGroup::isValidVelocityMove(const double* from_joint_pose, const d
831831

832832
return true;
833833
}
834+
835+
std::pair<Eigen::VectorXd, Eigen::VectorXd> getLowerAndUpperLimits(const moveit::core::JointModelGroup& group)
836+
{
837+
// Get the group joints lower/upper position limits.
838+
Eigen::VectorXd lower_limits(group.getActiveVariableCount());
839+
Eigen::VectorXd upper_limits(group.getActiveVariableCount());
840+
const moveit::core::JointBoundsVector& group_bounds = group.getActiveJointModelsBounds();
841+
int joint_index = 0;
842+
for (const moveit::core::JointModel::Bounds* joint_bounds : group_bounds)
843+
{
844+
for (const moveit::core::VariableBounds& variable_bounds : *joint_bounds)
845+
{
846+
lower_limits[joint_index] = variable_bounds.min_position_;
847+
upper_limits[joint_index] = variable_bounds.max_position_;
848+
joint_index++;
849+
}
850+
}
851+
return { lower_limits, upper_limits };
852+
}
853+
854+
std::pair<Eigen::VectorXd, Eigen::VectorXd>
855+
getMaximumVelocitiesAndAccelerations(const moveit::core::JointModelGroup& group)
856+
{
857+
const std::size_t n_dofs = group.getActiveVariableCount();
858+
Eigen::VectorXd max_joint_velocities = Eigen::VectorXd::Constant(n_dofs, 0.0);
859+
Eigen::VectorXd max_joint_accelerations = Eigen::VectorXd::Constant(n_dofs, 0.0);
860+
const moveit::core::JointBoundsVector& bounds = group.getActiveJointModelsBounds();
861+
assert(bounds.size() == n_dofs);
862+
for (std::size_t i = 0; i < bounds.size(); ++i)
863+
{
864+
assert(bounds[i]->size() == 1); // single-variable joints.
865+
max_joint_velocities[i] = std::min(-bounds[i]->at(0).min_velocity_, bounds[i]->at(0).max_velocity_);
866+
max_joint_accelerations[i] = std::min(-bounds[i]->at(0).min_acceleration_, bounds[i]->at(0).max_acceleration_);
867+
}
868+
return { max_joint_velocities, max_joint_accelerations };
869+
}
834870
} // end of namespace core
835871
} // end of namespace moveit

0 commit comments

Comments
 (0)