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

Scaled jtc #1191

Open
wants to merge 50 commits into
base: master
Choose a base branch
from
Open

Scaled jtc #1191

wants to merge 50 commits into from

Conversation

fmauch
Copy link
Contributor

@fmauch fmauch commented Jul 3, 2024

This is my take2 on #301.

I plan to finish this until Friday, @firesurfer feel free to poke me :-)

Currently missing

  • tests for scaled execution
  • There are some ToDos in the documentation:
    • Algorithmics
    • Handling tolerances

Things that will get changed, as discussed in the latest working group meeting

  • Allowing scaling factors above 1 might get postponed to a later point.
  • Report the scaling factor in the controller state
  • Use a custom datatype for the scaling_factor subscriber (std_msgs are deprecated)
  • Change subscription to transient_local. This will require documentation, as a standard ros2 topic pub will not work with this.

fmauch and others added 13 commits July 3, 2024 17:38
This adds a scaling factor between 0 and 1 to the JTC so that the trajectory
time inside the controller is extended respectively. A value of 0.5 means
that trajectory execution will take twice as long as the trajectory states.

The scaling factor itself is read from the hardware for now.
This avoids writing the explicit conversion by hand

Internally that basically does:
static_cast<rcl_duration_value_t>(static_cast<long double>(rcl_duration_.nanoseconds) * scale_ld)
That was changed in a previous commit
used

The current implementation only works correctly when a position
interface is used.

When the hardware in fact slows down the robot (as UR does), also velocity interfaces
should be scaled correctly, but that't rather an edge case right now.
It is accessed from the RT thread only, anyway.
@fmauch
Copy link
Contributor Author

fmauch commented Jul 3, 2024

Thoughts on tests I should implement:

  • Execution with scaling factor of 0.5 takes twice as long (and does not fail, when no tolerances are set)
  • Execution with scaling < 1 and goal time tolerance leads to an early halt and failed execution
  • Execution with scaling < 1 and path tolerances set should not fail (if goal_time_tolerance is large enough)
  • Execution with scaling > 1 should not fail independent of the tolerances set <-- is that true?

@firesurfer
Copy link
Contributor

hi @fmauch Great to see this being worked on again. I added some comments to the code.

Regarding the tests:

Execution with scaling factor of 0.5 takes twice as long (and does not fail, when no tolerances are set)

Makes sense

Execution with scaling < 1 and goal time tolerance leads to an early halt and failed execution

Isn't this what we patched in: UniversalRobots/Universal_Robots_ROS2_Driver#882. As far as I can tell you also backported this patch. (And I still think the goal time should be also scaled ;) )

Execution with scaling > 1 should not fail independent of the tolerances set <-- is that true?

Same as above. From heavily using this controller in our system I have the opinion that in most use cases it makes sense (and is what a user would expect) that the goal time should also be scaled. But perhaps I understood your suggestion wrong.

@fmauch
Copy link
Contributor Author

fmauch commented Jul 4, 2024

From heavily using this controller in our system I have the opinion that in most use cases it makes sense (and is what a user would expect) that the goal time should also be scaled. But perhaps I understood your suggestion wrong.

Thank you for your input. That's why I put my brain dump on that here, so we can discuss this :-) And that's also why I didn't write the documentation on that, yet.

I'll wrap my head around this a little more and try to get a better feeling for the current behavior, then come back to this.

ros2_controllers-not-released.jazzy.repos Outdated Show resolved Hide resolved
ros2_controllers-not-released.rolling.repos Outdated Show resolved Hide resolved
@firesurfer firesurfer mentioned this pull request Jul 4, 2024
@fmauch
Copy link
Contributor Author

fmauch commented Oct 14, 2024

Another update:

Edit:

Note: You will need ros-controls/ros2_control#1774 in order to get valid period times.

@fmauch fmauch mentioned this pull request Nov 27, 2024
@fmauch fmauch marked this pull request as ready for review December 3, 2024 06:36
@fmauch
Copy link
Contributor Author

fmauch commented Dec 3, 2024

This should be a state that could be started to get reviewed. There are a couple of things left that I'm not 100% happy, but they don't necessarily have to be covered in this PR in my opinion:

  • I started using the feedback's actual.time_from_start to show the controller time passed since the trajectory started and desired.time_from_start for the scaled trajectory time since the trajectory started. This was mainly done since I needed a way to ovserve scaled time for testing purposes.
  • The scaling method assumes (as mentioned in the docs) that the robot is scaling down the trajectory, so we have to scale time when looking at the beginning of the control period (How much of one period have we actually progressed in the last period?) and then we sample one full period ahead. If the robot doesn't scale down but we still want to use scaling, this will leave us with a tracking error. In that case we should scale the period for sampling the control target. My idea would be to make those two scaling methods available with a scaling_type parameteter with the values HARDWARE and CONTROLLER. I would also be happy to move that to a follow-up PR in order to get this one finally wrapped up. @RobertWilbrandt does this summarize the discussion we had a couple of days ago?
  • There are a couple of builds failing that I don't quite understand. gpio controller is complaining about missing messages. Is this a cache thing? Because it is building on the master branch and also locally things are fine, so at least the semi-binary builds should be happy.

@fmauch fmauch requested a review from firesurfer December 3, 2024 06:47
@christophfroehlich
Copy link
Contributor

christophfroehlich commented Dec 3, 2024

* There are a couple of builds failing that I don't quite understand. gpio controller is complaining about missing messages. Is this a cache thing? Because it is building on the master branch and also locally things are fine, so at least the semi-binary builds should be happy.

I had a look now, I don't know tbh. The debian build fails with the same error, but this one doesn't use caches.
Ah, I found the issue ;)

Co-authored-by: Felix Exner (fexner) <[email protected]>
Copy link

codecov bot commented Dec 3, 2024

Codecov Report

Attention: Patch coverage is 58.62069% with 36 lines in your changes missing coverage. Please review.

Project coverage is 83.37%. Comparing base (36068e1) to head (7844221).
Report is 6 commits behind head on master.

Files with missing lines Patch % Lines
...ory_controller/src/joint_trajectory_controller.cpp 26.53% 28 Missing and 8 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1191      +/-   ##
==========================================
- Coverage   83.56%   83.37%   -0.19%     
==========================================
  Files         122      122              
  Lines       10992    11076      +84     
  Branches      937      951      +14     
==========================================
+ Hits         9185     9235      +50     
- Misses       1493     1520      +27     
- Partials      314      321       +7     
Flag Coverage Δ
unittests 83.37% <58.62%> (-0.19%) ⬇️

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% <ø> (ø)
...ectory_controller/test/test_trajectory_actions.cpp 97.93% <100.00%> (+0.16%) ⬆️
...ory_controller/test/test_trajectory_controller.cpp 99.74% <100.00%> (+<0.01%) ⬆️
...ory_controller/src/joint_trajectory_controller.cpp 80.10% <26.53%> (-3.81%) ⬇️

... and 3 files with indirect coverage changes

@fmauch
Copy link
Contributor Author

fmauch commented Dec 3, 2024

I had a look now, I don't know tbh. The debian build fails with the same error, but this one doesn't use caches. Ah, I found the issue ;)

facepalm I thought I changed that back some time ago already.

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.

Some first remarks

  • Add a short description to the release_notes please.
  • Add the new ROS interfaces here

@@ -1580,6 +1683,32 @@ void JointTrajectoryController::resize_joint_trajectory_point_command(
}
}

bool JointTrajectoryController::set_scaling_factor(const double scaling_factor)
Copy link
Contributor

Choose a reason for hiding this comment

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

This method has no test coverage

@@ -902,6 +967,34 @@ controller_interface::CallbackReturn JointTrajectoryController::on_activate(
// parse remaining parameters
default_tolerances_ = get_segment_tolerances(logger, params_);

// Set scaling interfaces
Copy link
Contributor

Choose a reason for hiding this comment

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

This part has no test coverage

=============

The ``joint_trajectory_controller`` (JTC) supports dynamically scaling its trajectory execution speed.
That means, when specifying a scaling factor :math:`{f}` of less than 1, execution will proceed only
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it possible to specify a value > 1 for simulation purposes ? We are using this quite a lot in our setup.
What would the maximum rate be? I saw the limit with the old implementation at 2.5

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it can be greater than 1. I haven't investigated a limit, though.


.. note::
The current implementation only works for position-based interfaces.

Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps I am too tired after the ROScon. But could it be that it doesn't become 100% clear how to select a specfic mode?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What do you mean by "how to select a specific mode"? The current implementation will simply not do speed scaling when any other interface than position is configured for the controller.

Copy link
Contributor

Choose a reason for hiding this comment

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

If I just read the documentation I would think:

a) There are multiple modes I can choose from with the hint that on-robot scaling probably produces the better results
b) If there are multiple modes I would think: Ok somehow I have to tell the JTC to select which mode.

"of speed scaling, please only use a position interface when configuring this controller.");
scaling_factor_ = 1.0;
}
if (!params_.speed_scaling_state_interface_name.empty())
Copy link
Contributor

Choose a reason for hiding this comment

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

Does it make sense to allow changing the scaling_factor via the topic and from the teach panel ?

Copy link
Contributor Author

@fmauch fmauch Dec 4, 2024

Choose a reason for hiding this comment

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

It should be either topic or hardware, at least that was my intention. I'll revisit that to verify that that;s what I've implemented.

Edit: It's in the JointTrajectoryController::set_scaling_factor function. If speed scaling is set with a speed scaling state interface configured, but not with a command interface it will print a warning. This way it will also update the value on the teach pendant.

@@ -1012,3 +1021,74 @@ INSTANTIATE_TEST_SUITE_P(
std::make_tuple(
std::vector<std::string>({"effort"}),
std::vector<std::string>({"position", "velocity", "acceleration"}))));

TEST_P(TestTrajectoryActionsTestScalingFactor, test_scaling_execution_time_succeeds)
Copy link
Contributor

Choose a reason for hiding this comment

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

I have the feeling that just adding one test for such a complex feature is probably not enough.

I think it is missing some parts:

  1. It just checks the if the trajectory took the right amount of time -> It does not check if the trajectory was executed in the right way (e.g. had a spike what ever)

  2. Executing multiple trajectories in series

  3. Proper behavior regarding state and goal tolerances (and goal time tolerances)

2/3. are motivated by: UniversalRobots/Universal_Robots_ROS2_Driver#882

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