Skip to content

Commit 8c715ac

Browse files
christophfroehlichbmagyar
authored andcommitted
[JTC] Tolerance tests + Hold on time violation (backport #613)
* Add new test to ensure that controller goes into position holding when tolerances are violated * Hold position if goal_time is exceeded with topic interface * Fix hold on time-violation
1 parent 5b4b662 commit 8c715ac

File tree

2 files changed

+72
-3
lines changed

2 files changed

+72
-3
lines changed

joint_trajectory_controller/src/joint_trajectory_controller.cpp

+11-3
Original file line numberDiff line numberDiff line change
@@ -365,19 +365,27 @@ controller_interface::return_type JointTrajectoryController::update(
365365
traj_msg_external_point_ptr_.reset();
366366
traj_msg_external_point_ptr_.initRT(set_hold_position());
367367
}
368-
// else, run another cycle while waiting for outside_goal_tolerance
369-
// to be satisfied or violated within the goal_time_tolerance
370368
}
371369
}
372370
else if (tolerance_violated_while_moving && *(rt_has_pending_goal_.readFromRT()) == false)
373371
{
374372
// we need to ensure that there is no pending goal -> we get a race condition otherwise
375-
376373
RCLCPP_ERROR(get_node()->get_logger(), "Holding position due to state tolerance violation");
377374

378375
traj_msg_external_point_ptr_.reset();
379376
traj_msg_external_point_ptr_.initRT(set_hold_position());
380377
}
378+
else if (
379+
!before_last_point && !within_goal_time && *(rt_has_pending_goal_.readFromRT()) == false)
380+
{
381+
RCLCPP_ERROR(get_node()->get_logger(), "Exceeded goal_time_tolerance: holding position...");
382+
383+
traj_msg_external_point_ptr_.reset();
384+
traj_msg_external_point_ptr_.initRT(set_hold_position());
385+
}
386+
// else, run another cycle while waiting for outside_goal_tolerance
387+
// to be satisfied (will stay in this state until new message arrives)
388+
// or outside_goal_tolerance violated within the goal_time_tolerance
381389
}
382390
}
383391

joint_trajectory_controller/test/test_trajectory_controller.cpp

+61
Original file line numberDiff line numberDiff line change
@@ -1666,6 +1666,67 @@ TEST_P(TrajectoryControllerTestParameterized, test_hw_states_has_offset_later_co
16661666
executor.cancel();
16671667
}
16681668

1669+
TEST_P(TrajectoryControllerTestParameterized, test_state_tolerances_fail)
1670+
{
1671+
// set joint tolerance parameters
1672+
const double state_tol = 0.0001;
1673+
std::vector<rclcpp::Parameter> params = {
1674+
rclcpp::Parameter("constraints.joint1.trajectory", state_tol),
1675+
rclcpp::Parameter("constraints.joint2.trajectory", state_tol),
1676+
rclcpp::Parameter("constraints.joint3.trajectory", state_tol)};
1677+
1678+
rclcpp::executors::MultiThreadedExecutor executor;
1679+
SetUpAndActivateTrajectoryController(executor, false, {params}, true);
1680+
1681+
// send msg
1682+
constexpr auto FIRST_POINT_TIME = std::chrono::milliseconds(100);
1683+
builtin_interfaces::msg::Duration time_from_start{rclcpp::Duration(FIRST_POINT_TIME)};
1684+
// *INDENT-OFF*
1685+
std::vector<std::vector<double>> points{
1686+
{{3.3, 4.4, 5.5}}, {{7.7, 8.8, 9.9}}, {{10.10, 11.11, 12.12}}};
1687+
std::vector<std::vector<double>> points_velocities{
1688+
{{0.01, 0.01, 0.01}}, {{0.05, 0.05, 0.05}}, {{0.06, 0.06, 0.06}}};
1689+
// *INDENT-ON*
1690+
publish(time_from_start, points, rclcpp::Time(0, 0, RCL_STEADY_TIME), {}, points_velocities);
1691+
traj_controller_->wait_for_trajectory(executor);
1692+
updateController(rclcpp::Duration(FIRST_POINT_TIME));
1693+
1694+
// it should have aborted and be holding now
1695+
expectHoldingPoint(joint_state_pos_);
1696+
}
1697+
1698+
TEST_P(TrajectoryControllerTestParameterized, test_goal_tolerances_fail)
1699+
{
1700+
// set joint tolerance parameters
1701+
const double goal_tol = 0.1;
1702+
// set very small goal_time so that goal_time is violated
1703+
const double goal_time = 0.000001;
1704+
std::vector<rclcpp::Parameter> params = {
1705+
rclcpp::Parameter("constraints.joint1.goal", goal_tol),
1706+
rclcpp::Parameter("constraints.joint2.goal", goal_tol),
1707+
rclcpp::Parameter("constraints.joint3.goal", goal_tol),
1708+
rclcpp::Parameter("constraints.goal_time", goal_time)};
1709+
1710+
rclcpp::executors::MultiThreadedExecutor executor;
1711+
SetUpAndActivateTrajectoryController(executor, false, {params}, true);
1712+
1713+
// send msg
1714+
constexpr auto FIRST_POINT_TIME = std::chrono::milliseconds(100);
1715+
builtin_interfaces::msg::Duration time_from_start{rclcpp::Duration(FIRST_POINT_TIME)};
1716+
// *INDENT-OFF*
1717+
std::vector<std::vector<double>> points{
1718+
{{3.3, 4.4, 5.5}}, {{7.7, 8.8, 9.9}}, {{10.10, 11.11, 12.12}}};
1719+
std::vector<std::vector<double>> points_velocities{
1720+
{{0.01, 0.01, 0.01}}, {{0.05, 0.05, 0.05}}, {{0.06, 0.06, 0.06}}};
1721+
// *INDENT-ON*
1722+
publish(time_from_start, points, rclcpp::Time(0, 0, RCL_STEADY_TIME), {}, points_velocities);
1723+
traj_controller_->wait_for_trajectory(executor);
1724+
updateController(rclcpp::Duration(4 * FIRST_POINT_TIME));
1725+
1726+
// it should have aborted and be holding now
1727+
expectHoldingPoint(joint_state_pos_);
1728+
}
1729+
16691730
// position controllers
16701731
INSTANTIATE_TEST_SUITE_P(
16711732
PositionTrajectoryControllers, TrajectoryControllerTestParameterized,

0 commit comments

Comments
 (0)