Skip to content

Commit

Permalink
Update tests after changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
destogl committed Nov 21, 2023
1 parent af5e004 commit 4f868b1
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions joint_limits/test/test_simple_joint_limiter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ TEST_F(SimpleJointLimiterTest, when_neigher_poscmd_nor_velcmd_expect_enforce_fai
}
}

TEST_F(SimpleJointLimiterTest, when_no_posstate_expect_enforce_fail)
TEST_F(SimpleJointLimiterTest, when_no_posstate_expect_enforce_false)
{
SetupNode("simple_joint_limiter");
Load();
Expand All @@ -88,10 +88,14 @@ TEST_F(SimpleJointLimiterTest, when_no_posstate_expect_enforce_fail)
// test no position interface
current_joint_states_.positions.clear();
ASSERT_FALSE(joint_limiter_->enforce(current_joint_states_, desired_joint_states_, period));

// also fail if out fo limits
desired_joint_states_.positions[0] = 20.0;
ASSERT_FALSE(joint_limiter_->enforce(current_joint_states_, desired_joint_states_, period));
}
}

TEST_F(SimpleJointLimiterTest, when_no_velstate_expect_enforce_succeed)
TEST_F(SimpleJointLimiterTest, when_no_velstate_expect_limiting)
{
SetupNode("simple_joint_limiter");
Load();
Expand All @@ -104,6 +108,9 @@ TEST_F(SimpleJointLimiterTest, when_no_velstate_expect_enforce_succeed)
rclcpp::Duration period(1, 0); // 1 second
// test no vel interface
current_joint_states_.velocities.clear();
ASSERT_FALSE(joint_limiter_->enforce(current_joint_states_, desired_joint_states_, period));
// also fail if out fo limits
desired_joint_states_.positions[0] = 20.0;
ASSERT_TRUE(joint_limiter_->enforce(current_joint_states_, desired_joint_states_, period));
}
}
Expand All @@ -124,7 +131,7 @@ TEST_F(SimpleJointLimiterTest, when_within_limits_expect_no_limits_applied)
// within limits
desired_joint_states_.positions[0] = 1.0;
desired_joint_states_.velocities[0] = 1.0; // valid pos derivatite as well
ASSERT_TRUE(joint_limiter_->enforce(current_joint_states_, desired_joint_states_, period));
ASSERT_FALSE(joint_limiter_->enforce(current_joint_states_, desired_joint_states_, period));

// check if no limits applied
CHECK_STATE_SINGLE_JOINT(
Expand Down Expand Up @@ -313,10 +320,12 @@ TEST_F(SimpleJointLimiterTest, when_position_close_to_pos_limit_expect_decelerat
desired_joint_states_.velocities[0] = 1.5;

// this setup requires 0.15 distance to stop, and 0.2 seconds (so 4 cycles at 0.05)
std::vector expected_ret = {true, true, true, false};
for (auto i = 0u; i < 4; ++i)
{
auto previous_vel_request = desired_joint_states_.velocities[0];
ASSERT_TRUE(joint_limiter_->enforce(current_joint_states_, desired_joint_states_, period));
// expect limits applied until the end stop
ASSERT_EQ(joint_limiter_->enforce(current_joint_states_, desired_joint_states_, period), expected_ret[i]);

ASSERT_LE(
desired_joint_states_.velocities[0],
Expand Down

0 comments on commit 4f868b1

Please sign in to comment.