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

fix mistake in jerk limit #388

Open
wants to merge 3 commits into
base: melodic-devel
Choose a base branch
from

Conversation

schadocalex
Copy link

@schadocalex schadocalex commented Nov 28, 2018

The mistake is not only on melodic.

image

There's not a factor 2 in the formulas.

@mathias-luedtke
Copy link
Contributor

The same formula is used in diff_drive_controller.

@schadocalex
Copy link
Author

I fixed it too thanks.

Is there a way in this repo to factorize files between packages or not?

@mathias-luedtke
Copy link
Contributor

Is there a way in this repo to factorize files between packages or not?

Creating a base package... (#377)

@bmagyar
Copy link
Member

bmagyar commented Dec 5, 2018

...and now the limits test is failing.
@artivis @efernandez ?

@schadocalex
Copy link
Author

I have fixed the tests doubling the jerk limits. If you prefer to modify end values (after the simulation), tell me.

@artivis
Copy link
Contributor

artivis commented Dec 6, 2018

I have the feeling that there is a notation issue, dts are not actually the same in the rightmost development of the second line.
The way I understand it, the calculation of jerk actually 'spans' two iterations of the control loop (e.g. first iteration from t-2->t-1, second from t-1->t) thus dt * 2 iterations.
I'll have a deeper look asap.

@schadocalex
Copy link
Author

schadocalex commented Dec 6, 2018

Yes I thought that the mistake came from the two iterations process (there is 2 times dt between t-2 and t).

The way I understand it, the calculation of jerk actually 'spans' two iterations of the control loop

You can see it a different way if you define the jerk as the difference between current and last acceleration. In this process it 'spans' only one dt. And the computation of each acceleration is independant (each one use one dt). That was I try to explain with the maths above.

Notice that I did not verify the formulas to find the mistake, I was plotting the jerk and saw it was doubled. Then I got back to the code and the maths.

@schadocalex
Copy link
Author

I ran 3 times the tests and it fails due to instability of joint_trajectory_controller :

Summary: 201 tests, 0 errors, 0 failures, 0 skipped

joint_trajectory_controller/rosunit-joint_trajectory_controller_vel_test.xml: 26 tests, 0 errors, 1 failures, 0 skipped
Summary: 201 tests, 0 errors, 1 failures, 0 skipped

Summary: 201 tests, 0 errors, 0 failures, 0 skipped

@chapulina
Copy link

For what it's worth, we've been using these speed limiter functions on Ignition Gazebo, and while writing tests for it today, I noticed there was a mistake on the jerk calculation. The change proposed here fixed my tests in gazebosim/gz-math#194.

@bmagyar bmagyar mentioned this pull request Mar 4, 2021
@matthew-reynolds
Copy link
Member

This LGTM, glad to hear that the issue has been identified by others and the fix has been validated there too. Plus, the math makes sense.

I think part of the reason this got mixed up at first is because of the variable naming. da/da_min/da_max are pretty poor names IMO, really those terms are d2v.

I think it becomes much clearer as follows, though I admit this does take a few extra cycles since it divides.

const double a  = (v  - v0) / dt;
const double a0 = (v0 - v1) / dt;
  
const double da = clamp(a - a0, min_jerk*dt, max_jerk*dt);
v = v0 + (a0 + da)*dt;

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.

6 participants