Skip to content

Conversation

@lthall
Copy link
Contributor

@lthall lthall commented Jan 3, 2026

The current real time S-Curves have two problems that this PR addresses:

  1. There is a small overshoot as it approaches the target position in some combinations of input.
  2. The deceleration it generates is significantly less than the limits specify.

This PR produces the full deceleration specified by the square root controller and maintains the time constant based approach to the position target. This time constant based approach makes this algorithm act as a filter making it suitable for noisy or inputs and means that the algorithm does not oscillate or buzz near the set-point.

Below is a plot showing the original square root controller, the current Real Time S Curve, This Jerk Square Root algorithm and the standard rectangular jerk S Curve (Optimal).

There are two reasons we would choose not to use the Optimal solution:

  1. Computational Complexity.
  2. Lack of any soft approach to set-point.

Both of these make Optimal less appealing to high update rate applications.

image

Meant to be merged after #31870 and #31848

@lthall lthall force-pushed the 20260101_SqrtJerk_Controller branch from 54d25fe to 39cb323 Compare January 4, 2026 07:20
@lthall lthall requested review from IamPete1 and Copilot January 4, 2026 12:53
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@lthall lthall force-pushed the 20260101_SqrtJerk_Controller branch from 4a9d358 to e05fdc3 Compare January 5, 2026 02:22
@amilcarlucas
Copy link
Contributor

The mem cost seams reasonably small:

Binary Name      Text [B]        Data [B]     BSS (B)        Total Flash Change [B] (%)      Flash Free After PR (B)
---------------  --------------  -----------  -------------  ----------------------------  -------------------------
ardurover        280 (+0.0197%)  0 (0.0000%)  0 (0.0000%)    280 (+0.0196%)                                   277564
arducopter-heli  780 (+0.0500%)  0 (0.0000%)  4 (+0.0016%)   780 (+0.0498%)                                   137276
arducopter       780 (+0.0499%)  0 (0.0000%)  4 (+0.0016%)   780 (+0.0497%)                                   134340
arduplane        780 (+0.0501%)  0 (0.0000%)  -4 (-0.0016%)  780 (+0.0499%)                                   140680
antennatracker   0 (0.0000%)     0 (0.0000%)  0 (0.0000%)    0 (0.0000%)                                      565104
blimp            0 (0.0000%)     0 (0.0000%)  0 (0.0000%)    0 (0.0000%)                                      545748
ardusub          652 (+0.0463%)  0 (0.0000%)  4 (+0.0015%)   652 (+0.0462%)                                   292140

@andyp1per
Copy link
Contributor

I get the intent, but I don't understand what this affects as it seems to change the behaviour of existing methods?

@lthall
Copy link
Contributor Author

lthall commented Jan 6, 2026

I get the intent, but I don't understand what this affects as it seems to change the behaviour of existing methods?

Yes, it performs the same behaviour as the existing method but has improved stopping behaviour.

  1. It stops with a jerk / acceleration profile that is closer to ideal.
  2. It does not overshoot in some cases.

I don't think it is inferior in any way but offers significant improvements.

@lthall lthall force-pushed the 20260101_SqrtJerk_Controller branch from e05fdc3 to 791c48b Compare January 7, 2026 01:52
@lthall lthall requested review from peterbarker and rmackay9 January 7, 2026 01:58
@lthall lthall force-pushed the 20260101_SqrtJerk_Controller branch 2 times, most recently from 3706bba to 2dcbc81 Compare January 7, 2026 07:48
@lthall lthall changed the title AP_Math: Update shaping to use improved command model Step 3: AP_Math: Update shaping to use improved jerk limited algorithm. Jan 7, 2026
@lthall lthall force-pushed the 20260101_SqrtJerk_Controller branch 2 times, most recently from 1b3de6e to 95b8cbd Compare January 8, 2026 00:52
@lthall lthall requested a review from Copilot January 8, 2026 00:57
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@lthall lthall force-pushed the 20260101_SqrtJerk_Controller branch from 487a254 to c69b5b4 Compare January 14, 2026 14:52
Copy link
Contributor

@Ferruccio1984 Ferruccio1984 left a comment

Choose a reason for hiding this comment

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

Exstensively tested on SITL. Remarkable improvement of acceleration and deceleration shaping with overall improvement of the speed profile.
A Python script has been used for testing the behavior in Guided flight mode ensuring consistency across tests.
The following plots offer a comparison of the results :
new_math

old_math

Sharp corners detail:
new
old

Speed profile:
image

Thanks Leonard!

@lthall lthall force-pushed the 20260101_SqrtJerk_Controller branch 3 times, most recently from 3c00a7b to 41d0c67 Compare January 21, 2026 04:37
Copy link
Member

@IamPete1 IamPete1 left a comment

Choose a reason for hiding this comment

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

Looks good, Thanks

@lthall lthall force-pushed the 20260101_SqrtJerk_Controller branch 2 times, most recently from 156eae6 to ac9897f Compare January 25, 2026 03:01
@lthall lthall force-pushed the 20260101_SqrtJerk_Controller branch from ac9897f to 88345a1 Compare January 25, 2026 22:53
@lthall lthall force-pushed the 20260101_SqrtJerk_Controller branch from 88345a1 to 416db4a Compare January 25, 2026 22:55
@rmackay9 rmackay9 merged commit 56f05d6 into ArduPilot:master Jan 27, 2026
107 checks passed
@lthall lthall deleted the 20260101_SqrtJerk_Controller branch January 27, 2026 00:07
@Hwurzburg
Copy link
Contributor

I reverted this change to my POI autotest...I don't know how it could have passed without the delay to ARRIVE at the new position...it certainly does not if I run the test locally...the wait times out while it is still traveling to its destination...it takes over 15sec just to get there, and it must be that the mount check is loosened enough that it passes while its far enough away and low enough to pass.....

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants