Skip to content

refactor(jtc): improve jtc tolerances#2133

Open
thedevmystic wants to merge 7 commits intoros-controls:masterfrom
thedevmystic:jtc-tolerances
Open

refactor(jtc): improve jtc tolerances#2133
thedevmystic wants to merge 7 commits intoros-controls:masterfrom
thedevmystic:jtc-tolerances

Conversation

@thedevmystic
Copy link
Copy Markdown
Contributor

@thedevmystic thedevmystic commented Jan 29, 2026

Hello respected maintainers and reviewers!
This is Surya!

This PR addresses the following:

  • Seperate declaration from definition for better compilation speed and readability.
  • Refactor functions for better readability.
  • Add new function (create_error_trajectory_point).
  • Add extensive doxygen-style comments.
  • Add tests for new function (create_error_trajectory_point).

  1. If you have question, why I moved (or seperated) it to tolerances.cpp it is because the file was getting way too long for no reason. It would both increase compile time and future maintainance.

  2. If you have question, why I added create_error_trajectory_point it is because we can calculate the current error point and then compare it with tolerances with ease!


A note: This is a continuation of the previous PR #2048 (closed now). Instead of doing new features (new tolerances option) and refactoring in one PR. I split them into 2 PRs one doing refactoring (current) and another future PR adding feature.

This commit addresses the following:
  - Seperate declaration from definition for better compilation
    speed and readability.
  - Add new function (create_error_trajectory_point).
  - Add extensive doxygen-style comments.
  - Add tests for new function (create_error_trajectory_point).
@codecov
Copy link
Copy Markdown

codecov bot commented Jan 29, 2026

Codecov Report

❌ Patch coverage is 92.70073% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 84.90%. Comparing base (272ac69) to head (fd82eab).

Files with missing lines Patch % Lines
...include/joint_trajectory_controller/tolerances.hpp 70.58% 6 Missing and 4 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2133      +/-   ##
==========================================
+ Coverage   84.80%   84.90%   +0.10%     
==========================================
  Files         151      152       +1     
  Lines       14836    14890      +54     
  Branches     1286     1296      +10     
==========================================
+ Hits        12581    12642      +61     
+ Misses       1784     1779       -5     
+ Partials      471      469       -2     
Flag Coverage Δ
unittests 84.90% <92.70%> (+0.10%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
joint_trajectory_controller/src/tolerances.cpp 100.00% <100.00%> (ø)
...int_trajectory_controller/test/test_tolerances.cpp 100.00% <100.00%> (ø)
...include/joint_trajectory_controller/tolerances.hpp 74.00% <70.58%> (-5.80%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@thedevmystic
Copy link
Copy Markdown
Contributor Author

Just dropping a comment since it's been 2 weeks with no follow ups :)

@thedevmystic
Copy link
Copy Markdown
Contributor Author

P.S.

Initially I didn't knew create_error_trajectory_point already has been implemented.


While we have compute_error_for_point in joint_trajectory_controller.hpp, that file is almost 2000 lines long.
So, we can move that logic from there to here. This function utilizes STL's std::transform and has hardened checks. And it also makes sense to put it here, as we create error point to check it with tolerances anyways.


But if we have to remove it then say it to me :)

@thedevmystic
Copy link
Copy Markdown
Contributor Author

@christophfroehlich, sorry to tag you. But it's been almost 4 weeks without any follow-up. Thank you, and willing to make changes to suit the project!

@thedevmystic
Copy link
Copy Markdown
Contributor Author

@christophfroehlich, It is ready for review! I would really appreciate a review as it has been more than a month. Thanks!

@saikishor, sorry to tag you but the previous tagging to Christoph didn't gave any attention. I think you would understand that it's been more than a month with one-sided comments by me :)

@saikishor
Copy link
Copy Markdown
Member

@christophfroehlich, It is ready for review! I would really appreciate a review as it has been more than a month. Thanks!

@saikishor, sorry to tag you but the previous tagging to Christoph didn't gave any attention. I think you would understand that it's been more than a month with one-sided comments by me :)

@thedevmystic We understand, however, it is not only @christophfroehlich who has to review, there are other bnunch of reviewers too. Everyone of us are also busy with our day-to.day jobs, we will try to get back to this when we find some time. Lately, last few months the reviews are delayed for some reasons, we will do as much as we can to coverup

@christophfroehlich
Copy link
Copy Markdown
Member

+1 . so we have to triage PRs and fix urgent stuff first. but you could help a lot in doing reviews in other PRs

Copy link
Copy Markdown
Member

@saikishor saikishor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move the respective codebase into the .cpp and check for duplications

* \param[in] show_errors If true, logging messages about size mismatches will be shown.
* \return A JointTrajectoryPoint where positions, velocities, etc., are the difference.
*/
trajectory_msgs::msg::JointTrajectoryPoint create_error_trajectory_point(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
trajectory_msgs::msg::JointTrajectoryPoint create_error_trajectory_point(
trajectory_msgs::msg::JointTrajectoryPoint compute_error_trajectory_point(

* \param[in] state_error The difference (error) between the actual and desired joint state.
* \param[in] joint_idx The index of the joint in the `state_error` message to be checked.
* \param[in] state_tolerance The tolerance structure defining the maximum allowed absolute errors.
* \param[in] show_errors If true, logging messages about the tolerance violation will be shown.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* \param[in] show_errors If true, logging messages about the tolerance violation will be shown.
* \param[in] show_errors If true, log messages about the tolerance violation will be printed

* \param[in] desired_state The commanded state point.
* \param[in] current_state The actual state point from the hardware.
* \param[in] is_wraparounds A vector indicating which joints are wraparound (e.g., continuous).
* \param[in] show_errors If true, logging messages about size mismatches will be shown.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* \param[in] show_errors If true, logging messages about size mismatches will be shown.
* \param[in] show_errors If true, log messages about size mismatches will be printed.

*
* \param[in] state_error Error point (difference between commanded and actual) for all joints.
* \param[in] segment_tolerances StateTolerances for all joints in the trajectory.
* \param[in] show_errors If the joint that violates its tolerance should be output to console
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* \param[in] show_errors If the joint that violates its tolerance should be output to console
* \param[in] show_errors If true, the joint that violates its tolerance should be output to console.

Comment on lines +224 to +226
bool check_trajectory_point_tolerance(
const trajectory_msgs::msg::JointTrajectoryPoint & state_error,
const std::vector<StateTolerances> & segment_tolerances, bool show_errors = false);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this repeated? and why not move the code to .cpp?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In previous implementation it was inline, so I kept it inline. And we can't move a inline function to .cpp that's why.

Comment on lines +387 to +388
inline bool check_trajectory_point_tolerance(
const trajectory_msgs::msg::JointTrajectoryPoint & state_error,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is repeated right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not repeated (as I written it). The above one is the declaration and the other one is the implementation.

I follow ROS style guide but when something is not mentioned in it I follow Google C++ Style Guide.

So, in it, when a function is inline but it is also long, we usually implement it in the bottom in Inline function implementation section.

It is not repeated but one is dec and other is impl.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And again if you have question why it's inline, then it's again because previous implementation has it.

Comment on lines +230 to +234
inline trajectory_msgs::msg::JointTrajectoryPoint create_error_trajectory_point(
const trajectory_msgs::msg::JointTrajectoryPoint & desired_state,
const trajectory_msgs::msg::JointTrajectoryPoint & current_state,
const std::vector<bool> & is_wraparounds, bool show_errors)
{
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here why is the codebase in .hpp?

Copy link
Copy Markdown
Contributor Author

@thedevmystic thedevmystic Mar 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of this reply but create_error_trajectory_point and compute_error_for_point are functional similar.

The first one calculates for entire trajectory, while the later one checks for a specific point.

I think that we can move it here and change joint_trajectory_controller.cpp to use it. As that file is already long. So, breaking it's functionality would be better.

Anyways, what you want to do:

  1. Remove create_error_trajectory_point()
  2. Keep it and remove compute_error_for_point() and change the implementation to use it.

Whatever is best, I can do!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here why is the codebase in .hpp?

It's because I marked it inline. If you want me to drop it then I can!

@thedevmystic
Copy link
Copy Markdown
Contributor Author

thedevmystic commented Mar 9, 2026

@christophfroehlich, It is ready for review! I would really appreciate a review as it has been more than a month. Thanks!
@saikishor, sorry to tag you but the previous tagging to Christoph didn't gave any attention. I think you would understand that it's been more than a month with one-sided comments by me :)

@thedevmystic We understand, however, it is not only @christophfroehlich who has to review, there are other bnunch of reviewers too. Everyone of us are also busy with our day-to.day jobs, we will try to get back to this when we find some time. Lately, last few months the reviews are delayed for some reasons, we will do as much as we can to coverup

I really understand your problems too. But like it's been a month and a half. That's why. Anyways, thank you for giving your time.

And the reason I tagged him is that the Contributing guidelines said we can tag maintainers (I think I misunderstood it), and another PR that was not being reviewed for over a month the author tagged the maintainer reviewer and not others.

And also I did that because the first tag was more than 2 weeks ago without any follow up.

Anyways, thanks again :)

@thedevmystic
Copy link
Copy Markdown
Contributor Author

+1 . so we have to triage PRs and fix urgent stuff first. but you could help a lot in doing reviews in other PRs

I thought that only reviewers can do reviews, I do some kind of small reviews in other PRs. But thank you for considering me able to do reviews!

@christophfroehlich
Copy link
Copy Markdown
Member

christophfroehlich commented Mar 15, 2026

+1 . so we have to triage PRs and fix urgent stuff first. but you could help a lot in doing reviews in other PRs

I thought that only reviewers can do reviews, I do some kind of small reviews in other PRs. But thank you for considering me able to do reviews!

I am sure that you have carefully read the contributing guidelines. There we clearly encourage you to do so

Even if you are not a maintainer, you are still encouraged to review pull requests.
This helps us increase the review pace and increase code quality.
Also, you are very likely to find some issues/limitations nobody else is seeing.

Everyone can leave official reviews from github UI via the "Changes" tab.

@thedevmystic
Copy link
Copy Markdown
Contributor Author

thedevmystic commented Mar 17, 2026

Yeah! I did re-read it. Because when I first read it I misread it and didn't read it that carefully as I said earlier that "I misunderstood". Silly me :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants