Skip to content
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

[JTC] Sample at t + dT instead of the beginning of the control cycle #1306

Merged
merged 17 commits into from
Nov 22, 2024

Conversation

fmauch
Copy link
Contributor

@fmauch fmauch commented Oct 7, 2024

As mentioned in #1191 (comment) and discussed in #697 the JTC currently samples the trajectory at the time given to the update(time, period) method. However, this actually is the beginning of the control cycle and it would make more sense to sample the setpoint for the end of the control cycle, resulting in time + controller_update_period. This PR implements that.

I obviously had to update a couple of tests on the way, since with changing the sampling point, the resulting command can be significantly different.

Copy link

codecov bot commented Oct 7, 2024

Codecov Report

Attention: Patch coverage is 97.22222% with 2 lines in your changes missing coverage. Please review.

Project coverage is 83.60%. Comparing base (79358e3) to head (43c4ac4).
Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
...ory_controller/src/joint_trajectory_controller.cpp 83.33% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1306      +/-   ##
==========================================
+ Coverage   83.57%   83.60%   +0.02%     
==========================================
  Files         122      122              
  Lines       10960    10982      +22     
  Branches      929      934       +5     
==========================================
+ Hits         9160     9181      +21     
- Misses       1489     1490       +1     
  Partials      311      311              
Flag Coverage Δ
unittests 83.60% <97.22%> (+0.02%) ⬆️

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

Files with missing lines Coverage Δ
...jectory_controller/joint_trajectory_controller.hpp 100.00% <ø> (ø)
...include/joint_trajectory_controller/trajectory.hpp 75.00% <ø> (ø)
joint_trajectory_controller/src/trajectory.cpp 91.35% <100.00%> (+0.04%) ⬆️
...ory_controller/test/test_trajectory_controller.cpp 99.74% <100.00%> (+<0.01%) ⬆️
...ntroller/test/test_trajectory_controller_utils.hpp 84.14% <100.00%> (ø)
...ory_controller/src/joint_trajectory_controller.cpp 83.86% <83.33%> (-0.18%) ⬇️

... and 1 file with indirect coverage changes

---- 🚨 Try these New Features:

Copy link
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.

Look good. I've left some questions
I'll continue reviewing after we discuss this part.

Thanks for your great work @fmauch

@fmauch fmauch requested a review from saikishor October 16, 2024 07:24
This isn't used anymore and more or less confusing, as actual will not
be desired as long as the robot is moving, which it is here.
@fmauch
Copy link
Contributor Author

fmauch commented Oct 16, 2024

The changes from ros-controls/ros2_control#1788 require revisiting the tests from this. I expect, that tests on the master branch will fail, as well, however, since I had to set correct rates all over the place within this PR.

Well, maybe not. I'll check this one, though.

Edit: Things are back to normal now.

Some tests require an update rate of 100 which isn't possible
if the default one is at 10.
Copy link
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.

LGTM

Copy link
Contributor

@christophfroehlich christophfroehlich left a comment

Choose a reason for hiding this comment

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

I just read once more the linked issue #697 and I think he is right in this point:

However JTC in ros_controllers is comparing current state with future state (at T + dt), and this seems wrong. This will always lead to a tracking or goal error what ever perfect robot (mirrored cmd/state ifs) there is.

This is exactly what is done in this PR here?

@fmauch
Copy link
Contributor Author

fmauch commented Nov 11, 2024

In 0d00727 I implemented using the trajectory sample point at time T as the desired_state. This is used for checking the tolerances, generating the feedback's desired state and error and to compute the PID value for the closed loop controller. I am unsure about the latter, as it was also discussed in #697.

@christophfroehlich
Copy link
Contributor

In 0d00727 I implemented using the trajectory sample point at time T as the desired_state. This is used for checking the tolerances, generating the feedback's desired state and error and to compute the PID value for the closed loop controller. I am unsure about the latter, as it was also discussed in #697.

I think this is a proper way in handling this, and it's a minimal change in the current behavior by now.
But I'm wondering if there is a problem with #1297: It may happen that the sampling at t_2 of the following update method will sample at a time before t_1+dt?

@fmauch
Copy link
Contributor Author

fmauch commented Nov 12, 2024

In 0d00727 I implemented using the trajectory sample point at time T as the desired_state. This is used for checking the tolerances, generating the feedback's desired state and error and to compute the PID value for the closed loop controller. I am unsure about the latter, as it was also discussed in #697.

I think this is a proper way in handling this, and it's a minimal change in the current behavior by now. But I'm wondering if there is a problem with #1297: It may happen that the sampling at t_2 of the following update method will sample at a time before t_1+dt?

Yes, this may definitively happen, especially once we actually get to time-scaling as it is my overall target with this. I'm not entierly familiar with #1297, so I'll have to read into that.

@fmauch
Copy link
Contributor Author

fmauch commented Nov 13, 2024

Yes, this may definitively happen, especially once we actually get to time-scaling as it is my overall target with this. I'm not entierly familiar with #1297, so I'll have to read into that.

Coming back to this: Yes, this is definitively a problem. One solution could be to make the index progression in the sample method optional such that it could only be moving forwards for the sampling at time T, but not at sampling for T+dT.


Edit: Implemented in 353f664

Copy link
Contributor

@christophfroehlich christophfroehlich left a comment

Choose a reason for hiding this comment

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

That's fine, I also thought about fixing it like this. ABI break should be fine for the trajectory class.

Copy link
Contributor

@MarqRazz MarqRazz left a comment

Choose a reason for hiding this comment

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

Overall this looks good, just a few minor suggestions.

@bmagyar
Copy link
Member

bmagyar commented Nov 22, 2024

Thanks everyone!

@bmagyar bmagyar merged commit 1bd6870 into ros-controls:master Nov 22, 2024
15 of 19 checks passed
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.

5 participants