41 #include <sensor_msgs/msg/joint_state.hpp>
52 std::size_t joint_delta_index{ 0 };
53 double velocity_scaling_factor{ 1.0 };
56 const auto& bounds = joint->getVariableBounds(joint->getName());
57 if (bounds.velocity_bounded_ && velocity(joint_delta_index) != 0.0)
59 const double unbounded_velocity = velocity(joint_delta_index);
61 const auto bounded_velocity = std::min(std::max(unbounded_velocity, bounds.min_velocity_), bounds.max_velocity_);
62 velocity_scaling_factor = std::min(velocity_scaling_factor, bounded_velocity / unbounded_velocity);
67 return velocity_scaling_factor;
73 sensor_msgs::msg::JointState& joint_state,
const double override_velocity_scaling_factor)
76 Eigen::VectorXd velocity =
77 Eigen::Map<Eigen::VectorXd, Eigen::Unaligned>(joint_state.velocity.data(), joint_state.velocity.size());
78 double velocity_scaling_factor = override_velocity_scaling_factor;
80 if (override_velocity_scaling_factor < 0.01)
81 velocity_scaling_factor = getVelocityScalingFactor(joint_model_group, velocity);
84 if (velocity_scaling_factor < 1)
86 Eigen::VectorXd velocity_residuals = (1 - velocity_scaling_factor) * velocity;
87 Eigen::VectorXd positions =
88 Eigen::Map<Eigen::VectorXd, Eigen::Unaligned>(joint_state.position.data(), joint_state.position.size());
89 positions -= velocity_residuals * publish_period;
91 velocity *= velocity_scaling_factor;
93 joint_state.velocity = std::vector<double>(velocity.data(), velocity.data() + velocity.size());
94 joint_state.position = std::vector<double>(positions.data(), positions.data() + positions.size());
const std::vector< const JointModel * > & getActiveJointModels() const
Get the active joints in this group (that have controllable DOF). This does not include mimic joints.
A joint from the robot. Models the transform that this joint applies in the kinematic chain....
void enforceVelocityLimits(const moveit::core::JointModelGroup *joint_model_group, const double publish_period, sensor_msgs::msg::JointState &joint_state, const double override_velocity_scaling_factor=0.0)
Decrease robot position change and velocity, if needed, to satisfy joint velocity limits.