Skip to content

Commit b1450e7

Browse files
authored
Merge branch 'master' into pid_controller_feedforward_1270_1
2 parents f4a72a6 + 5486fcd commit b1450e7

File tree

4 files changed

+98
-3
lines changed

4 files changed

+98
-3
lines changed

diff_drive_controller/doc/userdoc.rst

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Other features
2020
+ Odometry publishing
2121
+ Task-space velocity, acceleration and jerk limits
2222
+ Automatic stop after command time-out
23+
+ Chainable Controller
2324

2425

2526
Description of controller's interfaces
@@ -28,7 +29,13 @@ Description of controller's interfaces
2829
References
2930
,,,,,,,,,,,,,,,,,,
3031

31-
(the controller is not yet implemented as chainable controller)
32+
When controller is in chained mode, it exposes the following references which can be commanded by the preceding controller:
33+
34+
- ``<controller_name>/linear/velocity`` double, in m/s
35+
- ``<controller_name>/angular/velocity`` double, in rad/s
36+
37+
Together, these represent the body twist (which in unchained-mode would be obtained from ~/cmd_vel).
38+
The ``<controller_name>`` is commonly set to ``diff_drive_controller``.
3239

3340
Feedback
3441
,,,,,,,,,,,,,,

doc/writing_new_controller.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,4 +141,7 @@ That's it! Enjoy writing great controllers!
141141
Useful External References
142142
---------------------------
143143

144-
- `Templates and scripts for generating controllers shell <https://rtw.stoglrobotics.de/master/use-cases/ros2_control/setup_controller.html>`_
144+
- `Templates and scripts for generating controllers shell <https://rtw.b-robotized.com/master/use-cases/ros2_control/setup_controller.html>`_
145+
146+
147+
.. NOTE:: The script is currently only recommended to use with Humble, not compatible with the API from Jazzy and onwards.

joint_trajectory_controller/src/joint_trajectory_controller.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1000,7 +1000,7 @@ controller_interface::CallbackReturn JointTrajectoryController::on_deactivate(
10001000
auto action_res = std::make_shared<FollowJTrajAction::Result>();
10011001
action_res->set__error_code(FollowJTrajAction::Result::INVALID_GOAL);
10021002
action_res->set__error_string("Current goal cancelled during deactivate transition.");
1003-
active_goal->setCanceled(action_res);
1003+
active_goal->setAborted(action_res);
10041004
rt_active_goal_.writeFromNonRT(RealtimeGoalHandlePtr());
10051005
}
10061006

joint_trajectory_controller/test/test_trajectory_actions.cpp

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -969,6 +969,91 @@ TEST_P(TestTrajectoryActionsTestParameterized, test_allow_nonzero_velocity_at_tr
969969
EXPECT_TRUE(gh_future.get());
970970
}
971971

972+
TEST_P(TestTrajectoryActionsTestParameterized, deactivate_controller_aborts_action)
973+
{
974+
// deactivate velocity tolerance
975+
std::vector<rclcpp::Parameter> params = {
976+
rclcpp::Parameter("constraints.stopped_velocity_tolerance", 0.0)};
977+
SetUpExecutor(params, false, 1.0, 0.0);
978+
979+
// We use our own hardware thread here, as we want to make sure the controller is deactivated
980+
auto controller_thread = std::thread(
981+
[&]()
982+
{
983+
// controller hardware cycle update loop
984+
auto clock = rclcpp::Clock(RCL_STEADY_TIME);
985+
auto now_time = clock.now();
986+
auto last_time = now_time;
987+
rclcpp::Duration wait = rclcpp::Duration::from_seconds(0.5);
988+
auto end_time = last_time + wait;
989+
while (now_time < end_time)
990+
{
991+
now_time = now_time + rclcpp::Duration::from_seconds(0.01);
992+
traj_controller_->update(now_time, now_time - last_time);
993+
last_time = now_time;
994+
std::this_thread::sleep_for(std::chrono::milliseconds(10));
995+
}
996+
RCLCPP_INFO(node_->get_logger(), "Controller hardware thread finished");
997+
traj_controller_->get_node()->deactivate();
998+
std::this_thread::sleep_for(std::chrono::milliseconds(100));
999+
});
1000+
1001+
std::shared_future<typename GoalHandle::SharedPtr> gh_future;
1002+
// send goal
1003+
std::vector<double> point_positions{1.0, 2.0, 3.0};
1004+
{
1005+
std::vector<JointTrajectoryPoint> points;
1006+
JointTrajectoryPoint point;
1007+
point.time_from_start = rclcpp::Duration::from_seconds(2.5);
1008+
point.positions = point_positions;
1009+
1010+
points.push_back(point);
1011+
1012+
gh_future = sendActionGoal(points, 1.0, goal_options_);
1013+
}
1014+
1015+
controller_thread.join();
1016+
1017+
EXPECT_TRUE(gh_future.get());
1018+
EXPECT_EQ(rclcpp_action::ResultCode::ABORTED, common_resultcode_);
1019+
1020+
auto state_ref = traj_controller_->get_state_reference();
1021+
auto state = traj_controller_->get_state_feedback();
1022+
1023+
// run an update
1024+
updateControllerAsync(rclcpp::Duration::from_seconds(0.01));
1025+
1026+
// There will be no active trajectory upon deactivation, so we can't use the expectCommandPoint
1027+
// method.
1028+
if (traj_controller_->has_position_command_interface())
1029+
{
1030+
EXPECT_NEAR(state_ref.positions.at(0), joint_pos_[0], COMMON_THRESHOLD);
1031+
EXPECT_NEAR(state_ref.positions.at(1), joint_pos_[1], COMMON_THRESHOLD);
1032+
EXPECT_NEAR(state_ref.positions.at(2), joint_pos_[2], COMMON_THRESHOLD);
1033+
}
1034+
1035+
if (traj_controller_->has_velocity_command_interface())
1036+
{
1037+
EXPECT_EQ(0.0, joint_vel_[0]);
1038+
EXPECT_EQ(0.0, joint_vel_[1]);
1039+
EXPECT_EQ(0.0, joint_vel_[2]);
1040+
}
1041+
1042+
if (traj_controller_->has_acceleration_command_interface())
1043+
{
1044+
EXPECT_EQ(0.0, joint_acc_[0]);
1045+
EXPECT_EQ(0.0, joint_acc_[1]);
1046+
EXPECT_EQ(0.0, joint_acc_[2]);
1047+
}
1048+
1049+
if (traj_controller_->has_effort_command_interface())
1050+
{
1051+
EXPECT_EQ(0.0, joint_eff_[0]);
1052+
EXPECT_EQ(0.0, joint_eff_[1]);
1053+
EXPECT_EQ(0.0, joint_eff_[2]);
1054+
}
1055+
}
1056+
9721057
// position controllers
9731058
INSTANTIATE_TEST_SUITE_P(
9741059
PositionTrajectoryControllersActions, TestTrajectoryActionsTestParameterized,

0 commit comments

Comments
 (0)