31 #ifndef JOINT_LIMITS_INTERFACE_JOINT_LIMITS_INTERFACE_H 32 #define JOINT_LIMITS_INTERFACE_JOINT_LIMITS_INTERFACE_H 54 T
saturate(
const T val,
const T min_val,
const T max_val)
56 return std::min(std::max(val, min_val), max_val);
71 if (limits_.has_position_limits)
74 max_pos_limit_ = limits_.max_position;
78 min_pos_limit_ = -std::numeric_limits<double>::max();
79 max_pos_limit_ = std::numeric_limits<double>::max();
82 prev_cmd_ = std::numeric_limits<double>::quiet_NaN();
86 std::string
getName()
const {
return jh_.getName();}
95 if (std::isnan(prev_cmd_))
96 prev_cmd_ = jh_.getPosition();
98 double min_pos, max_pos;
99 if (limits_.has_velocity_limits)
101 const double delta_pos = limits_.max_velocity * period.
toSec();
102 min_pos = std::max(prev_cmd_ - delta_pos, min_pos_limit_);
103 max_pos = std::min(prev_cmd_ + delta_pos, max_pos_limit_);
107 min_pos = min_pos_limit_;
108 max_pos = max_pos_limit_;
120 prev_cmd_ = std::numeric_limits<double>::quiet_NaN();
165 : prev_cmd_(
std::numeric_limits<double>::quiet_NaN())
173 soft_limits_(soft_limits),
174 prev_cmd_(
std::numeric_limits<double>::quiet_NaN())
179 "'. It has no velocity limits specification.");
184 std::string
getName()
const {
return jh_.getName();}
194 assert(period.
toSec() > 0.0);
200 if (std::isnan(prev_cmd_)) {prev_cmd_ = jh_.getPosition();}
201 const double pos = prev_cmd_;
207 if (limits_.has_position_limits)
210 soft_min_vel =
saturate(-soft_limits_.k_position * (pos - soft_limits_.min_position),
211 -limits_.max_velocity,
212 limits_.max_velocity);
214 soft_max_vel =
saturate(-soft_limits_.k_position * (pos - soft_limits_.max_position),
215 -limits_.max_velocity,
216 limits_.max_velocity);
221 soft_min_vel = -limits_.max_velocity;
222 soft_max_vel = limits_.max_velocity;
226 const double dt = period.
toSec();
227 double pos_low = pos + soft_min_vel * dt;
228 double pos_high = pos + soft_max_vel * dt;
230 if (limits_.has_position_limits)
233 pos_low = std::max(pos_low, limits_.min_position);
234 pos_high = std::min(pos_high, limits_.max_position);
238 const double pos_cmd =
saturate(jh_.getCommand(),
241 jh_.setCommand(pos_cmd);
244 prev_cmd_ = jh_.getCommand();
251 prev_cmd_ = std::numeric_limits<double>::quiet_NaN();
274 "'. It has no velocity limits specification.");
279 "'. It has no efforts limits specification.");
284 std::string
getName()
const {
return jh_.getName();}
291 double min_eff = -limits_.max_effort;
292 double max_eff = limits_.max_effort;
294 if (limits_.has_position_limits)
296 const double pos = jh_.getPosition();
297 if (pos < limits_.min_position)
299 else if (pos > limits_.max_position)
303 const double vel = jh_.getVelocity();
304 if (vel < -limits_.max_velocity)
306 else if (vel > limits_.max_velocity)
330 soft_limits_(soft_limits)
335 "'. It has no velocity limits specification.");
340 "'. It has no effort limits specification.");
345 std::string
getName()
const {
return jh_.getName();}
357 const double pos = jh_.getPosition();
358 const double vel = jh_.getVelocity();
364 if (limits_.has_position_limits)
367 soft_min_vel =
saturate(-soft_limits_.k_position * (pos - soft_limits_.min_position),
368 -limits_.max_velocity,
369 limits_.max_velocity);
371 soft_max_vel =
saturate(-soft_limits_.k_position * (pos - soft_limits_.max_position),
372 -limits_.max_velocity,
373 limits_.max_velocity);
378 soft_min_vel = -limits_.max_velocity;
379 soft_max_vel = limits_.max_velocity;
383 const double soft_min_eff =
saturate(-soft_limits_.k_velocity * (vel - soft_min_vel),
387 const double soft_max_eff =
saturate(-soft_limits_.k_velocity * (vel - soft_max_vel),
392 const double eff_cmd =
saturate(jh_.getCommand(),
395 jh_.setCommand(eff_cmd);
418 "'. It has no velocity limits specification.");
423 std::string
getName()
const {
return jh_.getName();}
437 if (limits_.has_acceleration_limits)
439 assert(period.
toSec() > 0.0);
440 const double vel = jh_.getVelocity();
441 const double dt = period.
toSec();
443 vel_low = std::max(vel - limits_.max_acceleration * dt, -limits_.max_velocity);
444 vel_high = std::min(vel + limits_.max_acceleration * dt, limits_.max_velocity);
448 vel_low = -limits_.max_velocity;
449 vel_high = limits_.max_velocity;
453 const double vel_cmd =
saturate(jh_.getCommand(),
456 jh_.setCommand(vel_cmd);
473 soft_limits_ = soft_limits;
477 max_vel_limit_ = std::numeric_limits<double>::max();
481 std::string
getName()
const {
return jh_.getName();}
492 double min_vel, max_vel;
493 if (limits_.has_position_limits)
496 const double pos = jh_.getPosition();
497 min_vel =
saturate(-soft_limits_.k_position * (pos - soft_limits_.min_position),
498 -max_vel_limit_, max_vel_limit_);
499 max_vel =
saturate(-soft_limits_.k_position * (pos - soft_limits_.max_position),
500 -max_vel_limit_, max_vel_limit_);
504 min_vel = -max_vel_limit_;
505 max_vel = max_vel_limit_;
508 if (limits_.has_acceleration_limits)
510 const double vel = jh_.getVelocity();
511 const double delta_t = period.
toSec();
512 min_vel = std::max(vel - limits_.max_acceleration * delta_t, min_vel);
513 max_vel = std::min(vel + limits_.max_acceleration * delta_t, max_vel);
516 jh_.setCommand(
saturate(jh_.getCommand(), min_vel, max_vel));
535 template <
class HandleType>
546 catch(
const std::logic_error& e)
558 for (ItratorType it = this->resource_map_.begin(); it != this->resource_map_.end(); ++it)
560 it->second.enforceLimits(period);
575 for (ItratorType it = this->resource_map_.begin(); it != this->resource_map_.end(); ++it)
592 for (ItratorType it = this->resource_map_.begin(); it != this->resource_map_.end(); ++it)
std::string getName() const
std::string getName() const
VelocityJointSaturationHandle(const hardware_interface::JointHandle &jh, const JointLimits &limits)
PositionJointSoftLimitsHandle()
void enforceLimits(const ros::Duration &)
Enforce position, velocity, and effort limits for a joint that is not subject to soft limits...
std::string getName() const
std::string getName(void *handle)
std::string getName() const
EffortJointSoftLimitsHandle()
PositionJointSaturationHandle(const hardware_interface::JointHandle &jh, const JointLimits &limits)
VelocityJointSaturationHandle()
void reset()
Reset all managed handles.
hardware_interface::JointHandle jh_
PositionJointSoftLimitsHandle(const hardware_interface::JointHandle &jh, const JointLimits &limits, const SoftJointLimits &soft_limits)
A handle used to enforce position and velocity limits of a position-controlled joint that does not ha...
hardware_interface::JointHandle jh_
std::string getName() const
void enforceLimits(const ros::Duration &period)
Enforce limits for all managed handles.
A handle used to enforce position, velocity, and effort limits of an effort-controlled joint that doe...
SoftJointLimits soft_limits_
hardware_interface::JointHandle jh_
void enforceLimits(const ros::Duration &period)
Enforce position, velocity, and acceleration limits for a velocity-controlled joint subject to soft l...
std::string getName() const
A handle used to enforce position, velocity, and acceleration limits of a velocity-controlled joint...
ResourceHandle getHandle(const std::string &name)
void reset()
Reset state, in case of mode switch or e-stop.
VelocityJointSoftLimitsHandle(const hardware_interface::JointHandle &jh, const JointLimits &limits, const SoftJointLimits &soft_limits)
SoftJointLimits soft_limits_
hardware_interface::JointHandle jh_
void enforceLimits(const ros::Duration &period)
Enforce joint velocity and acceleration limits.
EffortJointSoftLimitsHandle(const hardware_interface::JointHandle &jh, const JointLimits &limits, const SoftJointLimits &soft_limits)
HandleType getHandle(const std::string &name)
A handle used to enforce position and velocity limits of a position-controlled joint.
hardware_interface::JointHandle jh_
An exception related to a JointLimitsInterface.
SoftJointLimits soft_limits_
Interface for enforcing joint limits.
A handle used to enforce velocity and acceleration limits of a velocity-controlled joint...
void reset()
Reset state, in case of mode switch or e-stop.
void enforceLimits(const ros::Duration &)
Enforce position, velocity and effort limits for a joint subject to soft limits.
T saturate(const T val, const T min_val, const T max_val)
A handle used to enforce position, velocity and effort limits of an effort-controlled joint...
void enforceLimits(const ros::Duration &period)
Enforce position and velocity limits for a joint subject to soft limits.
void reset()
Reset all managed handles.
hardware_interface::JointHandle jh_
EffortJointSaturationHandle(const hardware_interface::JointHandle &jh, const JointLimits &limits)
void enforceLimits(const ros::Duration &period)
Enforce position and velocity limits for a joint that is not subject to soft limits.