curve smoothing

More
06 May 2013 23:40 - 07 May 2013 00:39 #9634 by PhracturedBlue
curve smoothing was created by PhracturedBlue
I have a curve-smoothing algorithm now that seems to work the way I like. The attached patch has the algorithm and replaces the standard linear interpolation with a cubic-spline interpolation (with some heuristics for the control points). you cannot switch between linear and bezier, this is just a proof-of-concept, not ready for checkin.

I am curious how folks will feel if you can only use 11-point (or less) curves with smoothing?

Adding more fields to the curve structure has a large impact on memory usage. the alternative of not pre-calculating the control-points has a potential performance impact.

On the Devo8/10/12 we have lots of RAM so I could pre-calculate the control-points without issue.
On the Devo7e, I'm in a bind because I don't want to increase memory allocation.

So my options are:
1) not support curve-smoothing on the 7e
2) do something special for the 7e (support fewer mixers or curve-points)
3) be consistent and limit all models to 9-point curves when using smoothing
4) increase the memory usage on the devo7e (probably limiting other capabilities in the future)
5) do-not pre-caclulate and hope we have enough spare cycles to not impact the system

I really don't like option (2) or (5) but I'm not sure what the best solution is here. I'm leaning towards (1) since I don't really want the devo7e to prevent me from developing features for the other radios, but I know a lot of folks use it, and this is one of the most-requested features.


Assuming you build from source, from the 'src' dir, run:
patch -p2 < path_to_bezier_patch_file
Attachments:
Last edit: 07 May 2013 00:39 by PhracturedBlue.

Please Log in or Create an account to join the conversation.

More
07 May 2013 01:36 #9637 by clearprop88
Replied by clearprop88 on topic curve smoothing
I have a Devo 8, and vote for curve-smoothing.

Please Log in or Create an account to join the conversation.

More
07 May 2013 03:12 - 07 May 2013 03:15 #9638 by Hexperience
Replied by Hexperience on topic curve smoothing
3) Wouldn't a smooth 9 point curve be more accurate than a normal 13 point one? Personally the most I've ever used is 5

4) I don't have a 7e, so take this with that in mind, but why "save" the memory for an as yet unknown feature in the future? I'm sure you have plans for the memory usage, but if the 7e users know what they may loose they can make an informed decision. i.e. They can have 9 point smoothing, but will loose X. They may want X more than Y... ;)

Question though.. Let's say I have a 3 point "curve" -20,0,+100. How would that smooth? I want a straight line from -20 to 0 and another straight line from 0 to +100. Would the smoothing only apply to 5 point curves and higher?

There are 10 types of people in this world. Those that understand binary and those that don't.
Last edit: 07 May 2013 03:15 by Hexperience.

Please Log in or Create an account to join the conversation.

More
07 May 2013 03:26 #9639 by PhracturedBlue
Replied by PhracturedBlue on topic curve smoothing
It looks like this:



I may do some tweaking to the endpoints as they are not quite as straight as I'd like, but I think it is just a matter of tuning.
Attachments:

Please Log in or Create an account to join the conversation.

More
07 May 2013 04:32 #9643 by PhracturedBlue
Replied by PhracturedBlue on topic curve smoothing
I just checked in the code. You can play with it and see what you think. In the end I optimized it sufficiently that I think (5) will be ok. I also implemented (4) as a backup but it is currently disabled.

Please Log in or Create an account to join the conversation.

More
07 May 2013 06:04 #9650 by vlad_vy
Replied by vlad_vy on topic curve smoothing
Code need some tuning, straight line is not straight.



Attachments:

Please Log in or Create an account to join the conversation.

More
07 May 2013 09:39 - 07 May 2013 14:34 #9656 by richardclli
Replied by richardclli on topic curve smoothing
I don't think cubic spline is suitable for this kind of curve fitting, since cubic function will have overshoot effect. I think something like parabolic/exponential fitting function may fit better.

Anyway, I will try to look into it and see if there are any better choices.
Last edit: 07 May 2013 14:34 by richardclli.

Please Log in or Create an account to join the conversation.

More
07 May 2013 10:14 #9657 by sbstnp
Replied by sbstnp on topic curve smoothing

richardclli wrote: I don't cubic spline is suitable for this kind of curve fitting, since cubic function will have overshoot effect. I think something like parabolic/exponential fitting function may fit better.

Anyway, I will try to look into it and see if there are any better choices.


Yeah this is known.

Devo 10 + 4in1
Spektrum Dx9
FrSky Taranis + TBS Crossfire

Please Log in or Create an account to join the conversation.

More
07 May 2013 12:22 - 07 May 2013 12:24 #9664 by PhracturedBlue
Replied by PhracturedBlue on topic curve smoothing
I have specifically tailored the spline so that there will never be any overshoot. Since I define the control points, I can prevent that. That doesn't mean that there isn't more tuning to do (or even a better algorithm), but I've tried a lot of things, and this is the 1st time I was remotely happy with the outcome.

I guess I should have clarified that it is a cubic bezier spline (which has control points in the 1st place, and not some sort of cubic-fit.
Last edit: 07 May 2013 12:24 by PhracturedBlue.

Please Log in or Create an account to join the conversation.

More
07 May 2013 12:51 - 07 May 2013 13:32 #9666 by vlad_vy
Replied by vlad_vy on topic curve smoothing
I found some problem with 13 point curve, it's deposed to the left and on the right there is artifact (jump from -100% to 0%):



Attachments:
Last edit: 07 May 2013 13:32 by vlad_vy.

Please Log in or Create an account to join the conversation.

More
07 May 2013 14:38 #9673 by richardclli
Replied by richardclli on topic curve smoothing
Just think of using parabola to fit the curve using the following formula:

-x'.sinθ + y'.cosθ = a.(x'.cosθ + y'.sinθ)² + b.(x'.cosθ + y'.sinθ) + c

and need to solve this formula using 2 points with 2 slopes on the points. This should give a good effect, but I need somebody good at geometry to solve all the four variables out of 2 points and 2 slopes.

What do you think?

Please Log in or Create an account to join the conversation.

More
07 May 2013 15:47 #9675 by PhracturedBlue
Replied by PhracturedBlue on topic curve smoothing
I think that doing sin or cos calculations on the stm32 will be very complicated for arbitrary values. We do not have floating point, and I don't like math enough to figure out how to do it quickly in fixed-point.

I figured out why vlad was seeing curvature in what should be a straight line. I made the simplifying assumption that f(t) is ~= f(x) which is a terrible assumption. Unfortunately it also means that the whole thing may be bunk, since calculating t from x may require a solver that i don't want to implement.

Please Log in or Create an account to join the conversation.

More
08 May 2013 00:57 #9684 by PhracturedBlue
Replied by PhracturedBlue on topic curve smoothing
I replaced the bezier cubic spline with a hermite cubic spline.
It has several benefits:
1) it can be directly calculated as f(x) which makes it much better suited to our needs (straight-line performance is now good)
2) there are monotone rules for calculating the tangents to guarantee no overshoot. These are better formalized than the home-brew rules I developed for the bezier curve

This was the function that was originally recommended to me in the bitbucket ticket, but I completely missed that it works fine with local maxima.

Anyhow, let me know how it works. I still haven't looked into why the 13-pointcurve isn't functioning right. It is definitely a bug, but I don't think it is directly related to the curve properties.

Please Log in or Create an account to join the conversation.

More
08 May 2013 02:51 #9687 by PhracturedBlue
Replied by PhracturedBlue on topic curve smoothing
I've resolved the offset issue vlad reported with 13-point curves as well now.

Please Log in or Create an account to join the conversation.

More
08 May 2013 03:48 - 08 May 2013 03:52 #9690 by richardclli
Replied by richardclli on topic curve smoothing
Yes! You got it right! The method "hermite cubic spline" is similar to what I am thinking, it requires 2 points and 2 tangents to do the interpolation. Just interested in the method you obtain the tangents, you used finite difference, cardinal difference, or something else?
Last edit: 08 May 2013 03:52 by richardclli.

Please Log in or Create an account to join the conversation.

More
08 May 2013 03:58 #9692 by PhracturedBlue
Replied by PhracturedBlue on topic curve smoothing
I basically follow the 'monotone cubic interpolation' method here:
en.wikipedia.org/wiki/Monotone_cubic_interpolation

The only significant change I made was to not calculate Beta but instead use mk/deltak+1 to enforce the monotonic behavior, since that is what I had available. this may not work perfectly, but so far it seems to be working as expected.

Please Log in or Create an account to join the conversation.

More
08 May 2013 04:39 - 08 May 2013 12:40 #9695 by vlad_vy
Replied by vlad_vy on topic curve smoothing
I found other artifact, spike on curve:

If point 6 value will be lower, spike on curve can overshoot 100%. It has place only with first ans last segment of curve.







Attachments:
Last edit: 08 May 2013 12:40 by vlad_vy.

Please Log in or Create an account to join the conversation.

More
08 May 2013 07:31 - 08 May 2013 21:01 #9700 by RandMental
Replied by RandMental on topic curve smoothing

PhracturedBlue wrote: I still haven't looked into why the 13-pointcurve isn't functioning right. It is definitely a bug, but I don't think it is directly related to the curve properties.


Hi PB,

I had noticed a problem with a 13 point setting a few weeks ago. It was with V3.0.0 and a well formed throttle curve (a valid curve for a heli) but when this model was selected there was almost a 1 second delay on the throttle response, both on the heli and on the bar on the main page. I changed back to a 7 point curve and no more delay. I haven tried revisit or duplicating it yet, 7 points are all I need, but I thought mentioning it while you are looking at the curve smoothing and memory use.

On an earlier question - at least for Helicopters, 9 points curves are plenty and would be my vote if needed to reduce memory requirements.
Last edit: 08 May 2013 21:01 by RandMental.

Please Log in or Create an account to join the conversation.

More
08 May 2013 16:06 #9707 by PhracturedBlue
Replied by PhracturedBlue on topic curve smoothing

vlad_vy wrote: I found other artifact, spike on curve:

If point 6 value will be lower, spike on curve can overshoot 100%. It has place only with first ans last segment of curve.

Thanks vlad. Calculating these splines in only 32bits without any overflow requires very careful management of multipliers. I had the order of operations slightly wrong and that was allowing the values to overflow. I've applied a fix that corrects this. Let me know if you see more issues.

Please Log in or Create an account to join the conversation.

More
24 May 2013 07:24 - 24 May 2013 11:49 #10270 by vlad_vy
Replied by vlad_vy on topic curve smoothing
I've found one more artifact.

7 point curve, throttle (ch3), -100, -25, 25, 55, 75, 90, 100. If throttle (Ch3) = 100%, at channel monitor Ch3 = 0% (and at right panel of emulator). Any decrease and Ch3 value restored. If curve smooth = Off, all works as expected.

Smoothed curve


Curve without smoothing
Attachments:
Last edit: 24 May 2013 11:49 by vlad_vy.

Please Log in or Create an account to join the conversation.

Time to create page: 0.272 seconds
Powered by Kunena Forum