-
Notifications
You must be signed in to change notification settings - Fork 496
diff_drive_controller: set parameters as read_only #2293
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
christophfroehlich
merged 7 commits into
ros-controls:master
from
kamal2730:fix/diff-drive-read-only-params
Apr 25, 2026
+196
−1
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
4f9f041
diff_drive_controller: set all parameters as read_only
kamal2730 62196bb
diff_drive_controller: enable runtime parameter updates for dynamic p…
kamal2730 0bddc84
Merge branch 'master' into fix/diff-drive-read-only-params
christophfroehlich 2099242
diff_drive_controller: test runtime parameter updates for speed limiter
kamal2730 c193e83
Merge branch 'master' into fix/diff-drive-read-only-params
christophfroehlich f47ca91
test(diff_drive_controller): refactor speed limiter test for readability
kamal2730 ba1b901
Merge branch 'master' into fix/diff-drive-read-only-params
christophfroehlich File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -672,6 +672,152 @@ TEST_F(TestDiffDriveController, test_speed_limiter) | |||||
| } | ||||||
| } | ||||||
|
|
||||||
| TEST_F(TestDiffDriveController, test_speed_limiter_runtime_update) | ||||||
| { | ||||||
| // If you send a linear velocity command without acceleration limits, | ||||||
| // then the wheel velocity command (rotations/s) will be: | ||||||
| // ideal_wheel_velocity_command (rotations/s) = linear_velocity_command (m/s) / wheel_radius (m). | ||||||
| // (The velocity command looks like a step function). | ||||||
| // However, if there are acceleration limits, then the actual wheel velocity command | ||||||
| // should always be less than the ideal velocity, and should only become | ||||||
| // equal at time = linear_velocity_command (m/s) / acceleration_limit (m/s^2). | ||||||
| // This test verifies that parameters can be updated at runtime. | ||||||
| const double max_acceleration_1 = 2.0; | ||||||
| const double max_acceleration_2 = 5.0; | ||||||
| const double max_deceleration = -4.0; | ||||||
| ASSERT_EQ( | ||||||
| InitController( | ||||||
| left_wheel_names, right_wheel_names, | ||||||
| { | ||||||
| rclcpp::Parameter("linear.x.max_acceleration", rclcpp::ParameterValue(max_acceleration_1)), | ||||||
| rclcpp::Parameter("linear.x.max_deceleration", rclcpp::ParameterValue(max_deceleration)), | ||||||
| }), | ||||||
| controller_interface::return_type::OK); | ||||||
| rclcpp::executors::SingleThreadedExecutor executor; | ||||||
| executor.add_node(controller_->get_node()->get_node_base_interface()); | ||||||
|
|
||||||
| ASSERT_TRUE(configure_succeeds(controller_)); | ||||||
|
|
||||||
| assignResourcesPosFeedback(); | ||||||
|
|
||||||
| ASSERT_TRUE(activate_succeeds(controller_)); | ||||||
|
|
||||||
| waitForSetup(executor); | ||||||
|
|
||||||
| // send msg | ||||||
| publish(0.0, 0.0); | ||||||
| // wait for msg is be published to the system | ||||||
| controller_->wait_for_twist(executor); | ||||||
| // wait for the speed limiter to fill the queue | ||||||
| for (int i = 0; i < 3; ++i) | ||||||
| { | ||||||
| ASSERT_EQ( | ||||||
| controller_->update(rclcpp::Time(0, 0, RCL_ROS_TIME), rclcpp::Duration::from_seconds(0.01)), | ||||||
| controller_interface::return_type::OK); | ||||||
| EXPECT_NEAR(0.0, left_wheel_vel_cmd_->get_optional().value(), 1e-3); | ||||||
| EXPECT_NEAR(0.0, right_wheel_vel_cmd_->get_optional().value(), 1e-3); | ||||||
| } | ||||||
|
|
||||||
| const double dt = 0.001; | ||||||
| const double wheel_radius = 0.1; | ||||||
| // Phase 1: accelerate with max_acceleration = 2.0 | ||||||
| { | ||||||
| const double linear = 1.0; | ||||||
| // send msg | ||||||
| publish(linear, 0.0); | ||||||
| // wait for msg is be published to the system | ||||||
| controller_->wait_for_twist(executor); | ||||||
| const double time_acc = linear / max_acceleration_1; | ||||||
| for (int i = 0; i < floor(time_acc / dt) - 1; ++i) | ||||||
| { | ||||||
| ASSERT_EQ( | ||||||
| controller_->update(rclcpp::Time(0, 0, RCL_ROS_TIME), rclcpp::Duration::from_seconds(dt)), | ||||||
| controller_interface::return_type::OK); | ||||||
| } | ||||||
| ASSERT_EQ( | ||||||
| controller_->update(rclcpp::Time(0, 0, RCL_ROS_TIME), rclcpp::Duration::from_seconds(dt)), | ||||||
| controller_interface::return_type::OK); | ||||||
| EXPECT_NEAR(linear / wheel_radius, left_wheel_vel_cmd_->get_optional().value(), 1e-3); | ||||||
| EXPECT_NEAR(linear / wheel_radius, right_wheel_vel_cmd_->get_optional().value(), 1e-3); | ||||||
| // wait for the speed limiter to fill the queue | ||||||
| for (int i = 0; i < 3; ++i) | ||||||
| { | ||||||
| ASSERT_EQ( | ||||||
| controller_->update(rclcpp::Time(0, 0, RCL_ROS_TIME), rclcpp::Duration::from_seconds(0.01)), | ||||||
| controller_interface::return_type::OK); | ||||||
| EXPECT_NEAR(linear / wheel_radius, left_wheel_vel_cmd_->get_optional().value(), 1e-3); | ||||||
| EXPECT_NEAR(linear / wheel_radius, right_wheel_vel_cmd_->get_optional().value(), 1e-3); | ||||||
| } | ||||||
| } | ||||||
| // Stop the robot | ||||||
| { | ||||||
| const double linear = 0.0; | ||||||
| // send msg | ||||||
| publish(linear, 0.0); | ||||||
| // wait for msg is be published to the system | ||||||
| controller_->wait_for_twist(executor); | ||||||
| const double time_dec = 1.0 / 4.0; | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| for (int i = 0; i < floor(time_dec / dt) - 1; ++i) | ||||||
| { | ||||||
| ASSERT_EQ( | ||||||
| controller_->update(rclcpp::Time(0, 0, RCL_ROS_TIME), rclcpp::Duration::from_seconds(dt)), | ||||||
| controller_interface::return_type::OK); | ||||||
| } | ||||||
| ASSERT_EQ( | ||||||
| controller_->update(rclcpp::Time(0, 0, RCL_ROS_TIME), rclcpp::Duration::from_seconds(dt)), | ||||||
| controller_interface::return_type::OK); | ||||||
| EXPECT_NEAR(linear / wheel_radius, left_wheel_vel_cmd_->get_optional().value(), 1e-3); | ||||||
| EXPECT_NEAR(linear / wheel_radius, right_wheel_vel_cmd_->get_optional().value(), 1e-3); | ||||||
| // wait for the speed limiter to fill the queue | ||||||
| for (int i = 0; i < 3; ++i) | ||||||
| { | ||||||
| ASSERT_EQ( | ||||||
| controller_->update(rclcpp::Time(0, 0, RCL_ROS_TIME), rclcpp::Duration::from_seconds(0.01)), | ||||||
| controller_interface::return_type::OK); | ||||||
| EXPECT_NEAR(linear / wheel_radius, left_wheel_vel_cmd_->get_optional().value(), 1e-3); | ||||||
| EXPECT_NEAR(linear / wheel_radius, right_wheel_vel_cmd_->get_optional().value(), 1e-3); | ||||||
| } | ||||||
| } | ||||||
| // Phase 2: update parameter at runtime to max_acceleration = 5.0 | ||||||
| { | ||||||
| auto result = controller_->get_node()->set_parameter( | ||||||
| rclcpp::Parameter("linear.x.max_acceleration", rclcpp::ParameterValue(max_acceleration_2))); | ||||||
| ASSERT_TRUE(result.successful); | ||||||
| } | ||||||
| // Phase 3: accelerate with max_acceleration = 5.0 | ||||||
| { | ||||||
| const double linear = 1.0; | ||||||
| // send msg | ||||||
| publish(linear, 0.0); | ||||||
| // wait for msg is be published to the system | ||||||
| controller_->wait_for_twist(executor); | ||||||
| const double time_acc_1 = linear / max_acceleration_1; | ||||||
| const double time_acc_2 = linear / max_acceleration_2; | ||||||
| // With higher acceleration, should reach target faster | ||||||
| ASSERT_LT(time_acc_2, time_acc_1); | ||||||
| for (int i = 0; i < floor(time_acc_2 / dt) - 1; ++i) | ||||||
| { | ||||||
| ASSERT_EQ( | ||||||
| controller_->update(rclcpp::Time(0, 0, RCL_ROS_TIME), rclcpp::Duration::from_seconds(dt)), | ||||||
| controller_interface::return_type::OK); | ||||||
| } | ||||||
| ASSERT_EQ( | ||||||
| controller_->update(rclcpp::Time(0, 0, RCL_ROS_TIME), rclcpp::Duration::from_seconds(dt)), | ||||||
| controller_interface::return_type::OK); | ||||||
| EXPECT_NEAR(linear / wheel_radius, left_wheel_vel_cmd_->get_optional().value(), 1e-3); | ||||||
| EXPECT_NEAR(linear / wheel_radius, right_wheel_vel_cmd_->get_optional().value(), 1e-3); | ||||||
| // wait for the speed limiter to fill the queue | ||||||
| for (int i = 0; i < 3; ++i) | ||||||
| { | ||||||
| ASSERT_EQ( | ||||||
| controller_->update(rclcpp::Time(0, 0, RCL_ROS_TIME), rclcpp::Duration::from_seconds(0.01)), | ||||||
| controller_interface::return_type::OK); | ||||||
| EXPECT_NEAR(linear / wheel_radius, left_wheel_vel_cmd_->get_optional().value(), 1e-3); | ||||||
| EXPECT_NEAR(linear / wheel_radius, right_wheel_vel_cmd_->get_optional().value(), 1e-3); | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| TEST_F(TestDiffDriveController, activate_fails_with_wrong_resources_assigned_1) | ||||||
| { | ||||||
| ASSERT_EQ( | ||||||
|
|
||||||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.