Enhance JointSaturationLimiter with Jerk limits - #3417
Conversation
… expected states Signed-off-by: Sachin Kumar <sachinkum123567@gmail.com>
… to JointSaturationLimiter Signed-off-by: Sachin Kumar <sachinkum123567@gmail.com>
…re by reorganizing conditional checks for desired position, velocity, and acceleration Signed-off-by: Sachin Kumar <sachinkum123567@gmail.com>
… by using boolean flags for position, velocity, acceleration, and deceleration limits, and streamline the clamp_joint_limits method. Signed-off-by: Sachin Kumar <sachinkum123567@gmail.com>
…position_limit methods with detailed step-by-step explanations Signed-off-by: Sachin Kumar <sachinkum123567@gmail.com>
…state tracking Signed-off-by: Sachin Kumar <sachinkum123567@gmail.com>
…onLimiter tests Signed-off-by: Sachin Kumar <sachinkum123567@gmail.com>
Signed-off-by: Sachin Kumar <sachinkum123567@gmail.com>
Signed-off-by: Sachin Kumar <sachinkum123567@gmail.com>
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #3417 +/- ##
==========================================
- Coverage 89.51% 89.47% -0.05%
==========================================
Files 164 164
Lines 21265 21479 +214
Branches 1658 1687 +29
==========================================
+ Hits 19036 19218 +182
- Misses 1530 1555 +25
- Partials 699 706 +7
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
…reference in JointSaturationLimiter methods Signed-off-by: Sachin Kumar <sachinkum123567@gmail.com>
…ter acceleration limiting in JointSaturationLimiter Signed-off-by: Sachin Kumar <sachinkum123567@gmail.com>
Signed-off-by: Sachin Kumar <sachinkum123567@gmail.com>
Signed-off-by: Sachin Kumar <sachinkum123567@gmail.com>
|
This pull request is in conflict. Could you fix it @sachinkum0009? |
Added a re-check mechanism after calculating desired acceleration based on jerk-limited values. This ensures that velocity and acceleration do not violate joint limits due to the influence of jerk-limited acceleration or deceleration calculations. Signed-off-by: Sachin Kumar <sachinkum123567@gmail.com>
Adjusts the logic for calculating safe target velocities when a joint limit is hit to ensure smoother deceleration towards the limit. This replaces the placeholder calculation with physics-based limits considering deceleration and time constraints. Signed-off-by: Sachin Kumar <sachinkum123567@gmail.com>
Removes detailed, multi-step comments from the documentation of the `clamp_joint_limits` and `handle_braking_near_position_limit` methods. These functions' internal workings are complex enough that the previous verbose description became overly long and hard to parse. Signed-off-by: Sachin Kumar <sachinkum123567@gmail.com>
Updates the joint saturation limiter to refactor redundant and complex code blocks related to re-clamping velocity after acceleration limiting. Introduces a local lambda, `post_velocity_check_and_clamp`, to centralize the logic for clamping velocity, recalculating derived values (acceleration and position), and ensuring consistency when multiple limits are hit sequentially. Signed-off-by: Sachin Kumar <sachinkum123567@gmail.com>
Updates `clamp_joint_limits` in both header and source files to accept and use the availability of current joint velocities for more accurate trajectory limiting. The warning message when acceleration limits are configured but current velocity is absent is also updated accordingly. Signed-off-by: Sachin Kumar <sachinkum123567@gmail.com>
Signed-off-by: Sachin Kumar <sachinkum123567@gmail.com>
Signed-off-by: Sachin Kumar <sachinkum123567@gmail.com>
|
Hi @saikishor @christophfroehlich Sorry to ping you. I have self reviewed it couple of times. I know that you are busy, it would really help me learn and contribute to ros2 control and become a maintainer in future. |
Ensure position limits are only applied when configured and re-clamp velocity limits after acceleration and jerk computations to maintain validity. Signed-off-by: Sachin Kumar <sachinkum123567@gmail.com>
destogl
left a comment
There was a problem hiding this comment.
As general comments.
Let's move the following in a separate PR:
- Refactor code to functions for readability
- Pre-allocate vector to avoid malloc when calling enforce fn
Also separate:
- Warn users when implicit vel exceed max velocity and then reclamp velocity to max velocity
And then rebase this PR on those changes it will make them more readable and simpler to merge.
I find this maybe too simple implementation. Are you sure there are no more cases when we have jerk limits. Can you make the tests of all possible cases in robot trajectory where jerk limits will be important?
| prev_command_ = current_joint_states; | ||
| const size_t num_joints = this->number_of_joints_; | ||
|
|
||
| desired_pos_.assign(num_joints, 0.0); |
There was a problem hiding this comment.
This is a very good catch! I would like to see this in a separate PR, as this seems to be merged very fast.
There was a problem hiding this comment.
Separate PR created for this.
| std::mutex mutex_; | ||
|
|
||
| private: | ||
| // Cached vectors to eliminate dynamic memory allocation (malloc) in the real-time execution loop |
There was a problem hiding this comment.
@saikishor is this true that we had the memory allocations previously? Can this be?
| */ | ||
| void clamp_joint_limits( | ||
| const bool has_desired_position, const bool has_desired_velocity, | ||
| const bool has_desired_acceleration, const bool has_current_velocity, |
There was a problem hiding this comment.
This seems to be part of the restructuring. I would like to see this in a separate PR. This is hard to figure out what is important and why.
There was a problem hiding this comment.
Separate PR created for restructuring.
| * Handles the braking near position limit | ||
| */ | ||
| void handle_braking_near_position_limit( | ||
| const std::vector<double> & current_joint_velocities, double dt_seconds, |
There was a problem hiding this comment.
why only "position" and "velocity" input?
| const std::vector<double> & current_joint_velocities, | ||
| bool & braking_near_position_limit_triggered, const double dt_seconds); | ||
|
|
||
| template <> |
There was a problem hiding this comment.
this is template for what exactly?
| } | ||
|
|
||
| // Re-clamp desired velocity after acceleration/jerk may have recomputed it | ||
| if ( |
There was a problem hiding this comment.
this will be done always, why do we then have it above?
| { | ||
| clamp_vel_limit(); | ||
| } | ||
| // Re-clamp desired position after acceleration/jerk may have recomputed it |
| double stopping_distance = | ||
| std::fabs((-desired_vel[index] * desired_vel[index]) / (2 * stopping_deccel)); | ||
| std::fabs((-desired_vel_[index] * desired_vel_[index]) / (2 * stopping_deccel)); | ||
| // compute stopping duration at stopping_deccel |
There was a problem hiding this comment.
OK, but what happens with jerk in that case?
| // 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) | ||
| // cycles 0-3 apply limits (braking + jerk), cycles 4-5 settle at stop |
There was a problem hiding this comment.
I what to see a new test with jerk. Current test should stay the same, as we should test also when no jerk limits are defined.
|
|
||
| rclcpp::Duration period(0, 50000000); | ||
|
|
||
| current_joint_states_.velocities[0] = 1.0; |
There was a problem hiding this comment.
give here more explanation on the numbers in a comment of the test. For all tests.
|
Thank you so much for the review. |
6a56d11 to
b6442a6
Compare
Signed-off-by: Sachin Kumar <sachinkum123567@gmail.com>
Signed-off-by: Sachin Kumar <sachinkum123567@gmail.com>
Description
This PR added the Jerk Limits to
JointSaturationLimiter.enforcefnFixes # (ros-controls/ros2_controllers#2434)
Is this user-facing behavior change?
Did you use Generative AI?
Used Opencode to understand the code and implement tests.
Additional Information
TODOs
To send us a pull request, please:
colcon testandpre-commit run(requires you to install pre-commit bypip3 install pre-commit)