Skip to content

Commit

Permalink
Fixup tests after revert.
Browse files Browse the repository at this point in the history
  • Loading branch information
destogl committed Dec 18, 2023
1 parent 09002b5 commit 8022808
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 14 deletions.
59 changes: 46 additions & 13 deletions joint_limits/src/joint_saturation_limiter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ bool JointSaturationLimiter<JointLimits>::on_enforce(
{
const auto dt_seconds = dt.seconds();
// negative or null is not allowed
if (dt_seconds <= 0.0) return false;
if (dt_seconds <= 0.0)
{
return false;
}

// TODO(gwalck) compute if the max are not implicitly violated with the given dt
// e.g. for max vel 2.0 and max acc 5.0, with dt >0.4
Expand Down Expand Up @@ -150,7 +153,9 @@ bool JointSaturationLimiter<JointLimits>::on_enforce(
return true;
}
else
{
return false;
}
};

// limit acc for pos_cmd and/or vel_cmd
Expand Down Expand Up @@ -314,12 +319,17 @@ bool JointSaturationLimiter<JointLimits>::on_enforce(
current_joint_states.velocities[index] + desired_acc[index] * dt_seconds;
}
if (has_pos_cmd)
{
desired_pos[index] = current_joint_states.positions[index] +
current_joint_states.velocities[index] * dt_seconds +
0.5 * desired_acc[index] * dt_seconds * dt_seconds;
}
}
std::ostringstream ostr;
for (auto jnt : limited_jnts_pos) ostr << jnt << " ";
for (auto jnt : limited_jnts_pos)
{
ostr << jnt << " ";
}
ostr << "\b \b"; // erase last character
RCLCPP_WARN_STREAM_THROTTLE(
node_logging_itf_->get_logger(), *clock_, ROS_LOG_THROTTLE_PERIOD,
Expand All @@ -334,7 +344,10 @@ bool JointSaturationLimiter<JointLimits>::on_enforce(
if (limited_jnts_pos.size() > 0)
{
std::ostringstream ostr;
for (auto jnt : limited_jnts_pos) ostr << jnt << " ";
for (auto jnt : limited_jnts_pos)
{
ostr << jnt << " ";
}
ostr << "\b \b"; // erase last character
RCLCPP_WARN_STREAM_THROTTLE(
node_logging_itf_->get_logger(), *clock_, ROS_LOG_THROTTLE_PERIOD,
Expand All @@ -344,7 +357,10 @@ bool JointSaturationLimiter<JointLimits>::on_enforce(
if (limited_jnts_vel.size() > 0)
{
std::ostringstream ostr;
for (auto jnt : limited_jnts_vel) ostr << jnt << " ";
for (auto jnt : limited_jnts_vel)
{
ostr << jnt << " ";
}
ostr << "\b \b"; // erase last character
RCLCPP_WARN_STREAM_THROTTLE(
node_logging_itf_->get_logger(), *clock_, ROS_LOG_THROTTLE_PERIOD,
Expand All @@ -354,7 +370,10 @@ bool JointSaturationLimiter<JointLimits>::on_enforce(
if (limited_jnts_acc.size() > 0)
{
std::ostringstream ostr;
for (auto jnt : limited_jnts_acc) ostr << jnt << " ";
for (auto jnt : limited_jnts_acc)
{
ostr << jnt << " ";
}
ostr << "\b \b"; // erase last character
RCLCPP_WARN_STREAM_THROTTLE(
node_logging_itf_->get_logger(), *clock_, ROS_LOG_THROTTLE_PERIOD,
Expand All @@ -364,23 +383,35 @@ bool JointSaturationLimiter<JointLimits>::on_enforce(
if (limited_jnts_dec.size() > 0)
{
std::ostringstream ostr;
for (auto jnt : limited_jnts_dec) ostr << jnt << " ";
for (auto jnt : limited_jnts_dec)
{
ostr << jnt << " ";
}
ostr << "\b \b"; // erase last character
RCLCPP_WARN_STREAM_THROTTLE(
node_logging_itf_->get_logger(), *clock_, ROS_LOG_THROTTLE_PERIOD,
"Joint(s) [" << ostr.str().c_str() << "] would exceed deceleration limits, limiting");
}

if (has_pos_cmd) desired_joint_states.positions = desired_pos;
if (has_vel_cmd) desired_joint_states.velocities = desired_vel;
if (has_acc_cmd) desired_joint_states.accelerations = desired_acc;
if (has_pos_cmd)
{
desired_joint_states.positions = desired_pos;
}
if (has_vel_cmd)
{
desired_joint_states.velocities = desired_vel;
}
if (has_acc_cmd)
{
desired_joint_states.accelerations = desired_acc;
}
return true;
}

template <>
bool JointSaturationLimiter<JointLimits>::on_enforce_effort(
trajectory_msgs::msg::JointTrajectoryPoint & current_joint_states,
trajectory_msgs::msg::JointTrajectoryPoint & desired_joint_states, const rclcpp::Duration & dt)
trajectory_msgs::msg::JointTrajectoryPoint &,
trajectory_msgs::msg::JointTrajectoryPoint & desired_joint_states, const rclcpp::Duration &)
{
std::vector<double> desired_effort(number_of_joints_);
std::vector<std::string> limited_joints_effort;
Expand Down Expand Up @@ -415,7 +446,10 @@ bool JointSaturationLimiter<JointLimits>::on_enforce_effort(
if (limited_joints_effort.size() > 0)
{
std::ostringstream ostr;
for (auto jnt : limited_joints_effort) ostr << jnt << " ";
for (auto jnt : limited_joints_effort)
{
ostr << jnt << " ";
}
ostr << "\b \b"; // erase last character
RCLCPP_WARN_STREAM_THROTTLE(
node_logging_itf_->get_logger(), *clock_, ROS_LOG_THROTTLE_PERIOD,
Expand All @@ -428,7 +462,6 @@ bool JointSaturationLimiter<JointLimits>::on_enforce_effort(
}

} // namespace joint_limits
// namespace joint_limits

#include "pluginlib/class_list_macros.hpp"

Expand Down
2 changes: 1 addition & 1 deletion joint_limits/test/test_joint_saturation_limiter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ TEST_F(JointSaturationLimiterTest, when_no_posstate_expect_enforce_false)
}
}

TEST_F(SimpleJointLimiterTest, when_no_velstate_expect_enforce_succeed)
TEST_F(JointSaturationLimiterTest, when_no_velstate_expect_enforce_succeed)
{
SetupNode("joint_saturation_limiter");
Load();
Expand Down

0 comments on commit 8022808

Please sign in to comment.