S-Curve/ sinusoidal , Jerk +acceleration
-
Alden Hart
4 years ago
Acceleration is performed using a piecewise linear representation of a constant-jerk equation. This is the 3rd derivative of position instead of the 2nd derivative (constant acceleration) that is commonly used. The pulse rate is computed for each of the S-curve segments. Each axis is run as a "minor axis" of the 50 Khz clock rate. This minimizes jitter and aliasing - at the expense of running a fast clock rate all the time. The code is on github under tinyg if you want to take a look.perhaps look here.
Id donate for you to take a serious look at this but something about your intellect tells me you're good for money dc42
source:
-
Yes I know there is code out there to do S-curve acceleration. What I am saying is that it's pointless using it in 3D printing unless we do something about the requirement to command instantaneous velocity changes in 3D printing, which is necessitated by the approximation of curves by straight line segments together with the need to avoid stop/start motion for each line segment.
Commanding instantaneous velocity changes is likely to be far worse than commanding instantaneous acceleration changes, because it's asking for infinite acceleration. I could implement S-curve acceleration, but unless you set maximum jerk to a very low value, you would still excite vibrations when printing curves. And if you did set jerk to zero, it would print the curves very slowly and jerkily.
S-curve acceleration may make more sense for CNC machines for two reasons. The G2 and G3 commands are more commonly used to print arcs, rather than approximating curves using line segments. Speeds are much lower, so jerk can be set very low, perhaps even to zero.
I'm not saying that I won't implement S-curve acceleration in the future, I am saying that it has limited value in the context of 3D printing. OK for printing straight lines, useless for printing curves. If it was easy to do it properly, I would probably have done it already. But doing it properly requires the solution of cubic equations to calculate the step pulse times (currently RRF solves quadratic equations to calculate them).
So I would rather focus on a solution to jerk first, probably by deliberately deviating the tool path from the commanded path a little. When that's sorted, I can look at S-curve acceleration.
It would be interesting to calculate the forces generated in a typical 3D print due to to jerk and step changes in acceleration, then take the Fourier transform and see what the various contributions are in the most important frequency bands.
-
I wonder if you can put an accelerometer onto tool head and input on the duet, to record the feedback,
you perhaps could use that data… and the real time data to create a PID tuning system to dampen out the oscillation real-time.. perfect printing. also you could use that accelerometer to judge if there have been skipped steps or nozzle crashes..
?
...imagine having that setup then somebody mounts their accelerometers off axis and the whole printer goes haywire correcting wrong values lol
alright Thanks for hearing me out Dc42- I hear you’re doing exciting things with duet. Keep up the good work- best wishes.
the struggles to get rid of belt wobble are real. -
So a few weeks late to the party but…
So I would rather focus on a solution to jerk first, probably by deliberately deviating the tool path from the commanded path a little. When that's sorted, I can look at S-curve acceleration.
I think this is the best solution and could greatly help out. Machine tools that use Fanuc controllers have an option to use a technique called Smoothing/Nano smoothing that does exactly what you are proposing. Many modern day CAM packages approximate complex curves as straight lines, same as our slicers do with STL files. There are some high performance machine tools that can approach 3d printing speeds while machining. Fanuc's answer was to allow deviations in the tool path by using look-ahead and building a NURBS curve. It is even intelligent enough to automatically turn off when the movement vector exceeds a specified angle.
https://www.fanucamerica.com/home/products-services/cnc/cnc-technology/high-precision-machining
-
Both AMF and OBJ file formats support curve approximation in different ways. It seems that Microsoft's 3MF does too. Doesn't mean any common CAD software actually properly exports that feature of the file formats. I understand that there aren't any slicers which would properly handle this yet either.
Looks like Cosine Additive has some G2/G3 stuff figured out. I know this is already implemented in Firmware. It's beyond my capabilities but maybe a post processor could bridge the gap between current slicer capabilities and what the firmware is capable of?
https://www.cosineadditive.com/blog/2015/7/1/g2-g3-vector-based-printing -
Curve approximation as straight segments would really be fine if there was hardware accurate/precise enough to create artifacts in FDM prints just from the "error" of microstepping, right? Polyjet machines are amazing because they show stl roughness. We still don't have proper pressure regulation within hotends. Nor do we have common methods for modeling kinematics (which may follow with the dissemination of higher order movement planning in desktop printing platforms). Perhaps a feature like s-curve movements will drive better hardware. It should lift the acceleration/payload and velocity ceilings a bit. I'd like to know if s-curves even match to "advance" behavior in a standard hotend like a titan aero.
-
@mak said in S-Curve/ sinusoidal , Jerk +acceleration:
Bottom is a square wave, not a trapezoid. You'd see 4 sploshing events if it were a trapezoid.
-
I have ready 3D printing s-curve velocity profile. And continuing velocity to next move in tangential directiin. Support corner shape to move without stop to next directiin and start from 0. Now i rewrite code to custom moderboard with pic32mz 200mhz. On pic24hj128gp202 calculate next move is abow 4us. . Now i must write communication protokol to support g code. In this moment i have G0 G1 G2 G3 and G4. Hi this pass for testing.
-
While I was on vacation I did a Fourier analysis of the effects of trapezoidal and S-curve acceleration on exciting ringing. My conclusion was that whether S-curve acceleration helps or not depends on the relationship between the time spent accelerating or decelerating and the frequency of the ringing that you are trying to avoid.
Here is the summary. Let T be the time spent accelerating or decelerating, and let F be the frequency of ringing that you want to avoid.
- If F << 1/T then constant acceleration and S-curve acceleration are equally bad.
- Otherwise, if F < 1.3/T then constant acceleration is better than S-curve (triangular profile) acceleration. In particular, when F = 1/T then constant acceleration will hardly excite the ringing at all; whereas S-curve acceleration will excite it greatly.
- When F > 1.3T, S-curve acceleration wins at most frequencies. The higher F is, the better S-curve acceleration is - although the tendency to excite ringing when using constant acceleration also falls with rising F.
Here is a chart to compare how the two acceleration profiles excite ringing at different frequencies.
Based on this analysis, I discussed how to adjust the acceleration time to reduce ringing in this thread https://forum.duet3d.com/topic/5951/periodicity-of-ringing/39 and received reports that it worked. Today I found time to do my own beer-sloshing tests (see the video I posted to that thread), and they too have confirmed the theory for constant acceleration (trapezoidal) motion.
So before you decide that you must have S-curve acceleration, you really need to know the frequency of the ringing that you are trying to eliminate. If the ringing frequencies are high enough, then S-curve acceleration will help. But if they are low, then it will probably be better to use trapezoidal motion, and cancel out the lowest ringing frequency by choosing the acceleration carefully.
I'll write up the maths in a blog post when I find time.
-
Hi, it is not too surprising that there is a certain time between the acceleration changes, which causes to increase or reduce ringing.
Every time the acting force (acceleration) changes the system gets bumped and stars to oscillate. So every acceleration change introduces one oscillation and all oscillations together get super-positioned, meaning the waves can amplify or cancel each other. If the big bumps (ramp start and end) are spaced in time in a way the big waves overlap, the ringing will be maximized and vice versa. This effect will appear at multiple acceleration times (it is periodic).
But it is surprising, that a more gentle change of acceleration will increase the problem anywhere. More gentle means less dominant waves and less chance of amplifying these dominant waves. Maybe it is just bad luck or a bad coincidence. At least in theory it seems hard to find a not too academic explanation for that behavior.
Which s-curve profile did you use ? How big was the maximum acceleration using s-curve compared to the constant ramp acceleration ? How much was it higher ? Was the max speed or speed at the end the same ?
What also should help to avoid amplifying interference is to use different acceleration changing shapes at start and end of a ramp. E.g. start with d(acceleration)/dt <> 0 and end with d(acceleration)/dt == 0.
-
The S-curve profile I used was triangular, i.e. ramp up the acceleration linearly to its peak value, then immediately ramp it down towards zero again. The peak acceleration in the S-curve case has to be twice the steady acceleration of the trapezoidal case in order to keep the total acceleration time the same.
S-curve profiles that are in between the two (i.e. including a steady acceleration part) will give excitation factors in between the two curves plotted above. I'll plot some specific examples when I have time.
-
@dc42: i cannot see any chart what do i do wrong ?
below
Here is a chart to compare how the two acceleration profiles excite ringing at different frequencies.
is nothing (at least for me)
-
@vp said in S-Curve/ sinusoidal , Jerk +acceleration:
@dc42: i cannot see any chart what do i do wrong ?
below
Here is a chart to compare how the two acceleration profiles excite ringing at different frequencies.
is nothing (at least for me)
Try refreshing the page?
-
i can see the chart on my tablet, but not on my PC, something seems to block the url/domain on my PC. Thanks.
Some well working theory/basics:
Given a spring mass system with mass m and spring stiffness c and force excitation it follows:-
If the acceleration (force) is changed stepwise by amount k1, the amplitude a1 of the oscillation caused by this step is directly proportional to the step size k1.
-
If the acceleration is changed like a ramp with ramp rate k2, the amplitude a2 of the oscillation caused by the ramp start is directly proportional to the ramp rate k2.
It follows that a2 / a1 == k2 * sqrt(m / c) * k1. [EDIT: typo correction -> m/c corrected to sqrt(m/c)]
So depending on the ramp rate (or step size) and also on m/c, the generated oscillation has a bigger or smaller amplitude for a step wise change or a ramp - it depends on the system (m & c) and tuning settings (k1 & k2).
I didn´t include damping because with damping the results are by far not as obvious and beautiful - but in principle it is exactly the same. A real fdm printer is also a combination of mass/spring/damper systems, but one frequency will dominate (ringing) and the above is also still valid.The frequency (sqrt(stiffness/mass)) is naturally the same for ramp and step.
So in case one big wave is generated (ramp start) compared to a lot of smaller waves (s-curve), it must be bad timing if the ringing is worse with s-curve OR it might come from a2 / a1 = k2 * sqrt(m / c) * k1.
E.g. if one big wave is generated at acceleration start and the next bump/wave start follows at acceleration end with an unlucky phase shift, it will superposition and amplify (triangular s-curve). It is easy to add one big wave to another big wave, so that they amplify each other. But it is much harder to superposition many smaller amplitude varying waves (real s-curve) in a way that they amplify each other - which doesn´t mean it is not possible in principle.In the end the triangular acceleration profile might be an unlucky profile to compare s-curve with the step wise acceleration change !
So depending on the above the ringing test results may vary. In general, many fdm printers will have comparable m/c and k2/k1 (k1 and k2 can be set anyhow). I didn´t check if this can be a game changer for some fdm printers. But there are very stiff and light (m/c is very small) as well as heavy and soft printers (m/c very high) out there....
-
-
@vp said in S-Curve/ sinusoidal , Jerk +acceleration:
Given a spring mass system with mass m and spring stiffness c and force excitation it follows:
-
If the acceleration (force) is changed stepwise by amount k1, the amplitude a1 of the oscillation caused by this step is directly proportional to the step size k1.
-
If the acceleration is changed like a ramp with ramp rate k2, the amplitude a2 of the oscillation caused by the ramp start is directly proportional to the ramp rate k2.
It follows that a2 / a1 == k2 * m / c * k1.
Only if the proportionality constant is the same in both cases. Is it?
The frequency (sqrt(stiffness/mass)) is naturally the same for ramp and step.
So in case one big wave is generated (ramp start) compared to a lot of smaller waves (s-curve), it must be bad timing if the ringing is worse with s-curve OR it might come from a2 / a1 = k2 * m / c * k1.
Yes, it is bad timing. With stepwise acceleration, the first frequency at which the oscillations produced by the start and end of the step cancel each other out is when 1/T where T is the length of the step. With triangular profile S-curve acceleration, it is 2/T where T is the total length of the triangular pulse.
In the end the triangular acceleration profile might be an unlucky profile to compare s-curve with the step wise acceleration change !
I am fairly sure that a trapezoidal acceleration profile will give results between the step case and the triangle case (because at the extremes it becomes one or the other), but I haven't done the maths yet.
-
-
Some input from my side - i am also surprised, but a triangular speed change doesn't seem to improve ringing at all times compared to a rectangular one. I would be glad if somebody finds a mistake below
1. What happens in between a speed change ?
For a mass spring system like m * xdotdot +c * x = c * y(t) with y(t) as a step or ramp follows:the position over time equals for a step wise change of y(t)
x(t) = (k_step * t^2)/2 - (k_step * m)/c + (k_step * m * cos((c^(1/2) * t)/m^(1/2)))/c
and for a ramp wise change of y(t)
x(t) = (k_ramp * t^3)/6 + (k_ramp * m^(3/2) * sin((c^(1/2) * t)/m^(1/2)))/c^(3/2) - (k_ramp * m * t)/c
k_step is the step size/acceleration [m/s^2] and k_ramp the ramp rate [m/s^3].
So every change of the acceleration causes a wave. Many acceleration changes causes many waves and these waves get superpositioned, that means they are just summed up. A rectangular acceleration profile consists of 2 stepwise changes of the acceleration - it produces 2 waves, which interfere. A triangular one creates 3 waves, because 3 ramp wise changes are needed.
The amplitude of the possible oscillations (ringing) is defined by k_step * m/c in the step case and k_ramp * sqrt(m)^(3/2)/c^(3/2). This is just the amplitude of a single wave, not the superposition of many waves.
Which method (ramp or step) does produces bigger waves ?
Dividing k_ramp * sqrt(m)^(3/2)/c^(3/2) by k_step * m/c leads to k_ramp/k_step * sqrt(m/c). By that the ratio of the amplitudes is a function of c/m.The frequency doesn´t change, it is defined by the system itself - not by the applied motion profile.
If the speed has to be the same after the same time for a rectangular shaped acceleration change as for an triangular shaped one of a certain pulse width, k_ramp equals to 4 * k_step/pulse_width. Substituting this k_ramp into k_ramp/k_step * sqrt(m/c) gives amplitude_ramp/amplitude_step = 4 * sqrt(m/c) / pulse_width.
So depending on sqrt(m/c) and the pulse width, the oscillations during the speed change can be higher or smaller, comparing a rectangular or triangular shaped acceleration change profile. BTW sqrt(c/m)/2/pi is the natural frequency and 2 * pi * sqrt(m/c) the period time T.
In other words, if the pulse width is bigger than 2 * T/pi a single ramp produces smaller waves than a single step, used in a rectangular or triangular profile.The natural frequencies f of the most important parts (steppers, belts, tubes) of my stiff/fast 3d printer are in the range of 300 - 70 Hz, or periods of 0.003 to 0.015 s. They can oscillate alone at their own natural frequency or all together with frequencies close to the smallest frequency. My slow printer is about factor 10-50 "slower" and less stiff. If damping is increased, these frequencies get smaller.
I use printing accelerations > 1g on my fast printer, so if the acceleration takes 0.01 s (pulse width) with 1g, the speed increases by > 100 mm/s.
In this case amplitude_ramp/amplitude_step = 2 * T/pi/pulse_width --> 2 * 0.003/pi/0.01 = 0.19 and 2 * 0.015/pi/0.01 = 0.96. So the fast parts gets 0.19 times less excited by the ramp, the slow parts not really.If the speed change would be only 25 mm/s, it would only take 0.0025 s and by that a triangular acceleration profile would generate bigger waves compared to a rectangular one. Because in the middle of the triangular shape we need a "double" sized ramp rate change to flip the sign of the acceleration change, the triangular shaped change can be even worse .
On my slow printer c/m is much smaller, but also the used acceleration, so in total it also ends up, that triangular can be better but doesn´t have to. To make it even more complex, depending on the various parts (steppers, belts, tubes etc.) and their different natural frequencies, it can be that the steppers would need a triangular shaped acceleration change and the belts a rectangular....
In case the pulse width equals to the period time T, "amplitude triangular / amplitude rectangular = 2/pi". That means the produced single waves comparing a single step with a single ramp, will be by a factor of 0.64 smaller in the ramp case
2. What does a fourier spectrum of a triangular pulse and rectangular pulse show ?
It just shows the amplitudes after applying the total speed change. It doesn´t show what happens during the speed change. Above equations show it.
The Fourier transform of the rectangular and triangular change show which frequencies gets excited by the rectangular and triangle acceleration profile. If the fourier shows the amplitude is zero for e.g. all frequencies with multiples of period T, these frequencies doesn't get excited by the speed change as a whole. If this is the natural frequency of the mass spring damper system sqrt(c/m)/2/pi, it means the total oscillation of the total speed change will be zero. It doesn't mean, that there are no oscillations happening during the speed change. Only the superposition of all waves together is zero.Because we talk about ringing, for pure x/y/z printers we don't see ringing during the speed change in our prints, we see it after the speed change has been done. But for all others (deltas scaras, Hs, etc.) the ringing during the speed change will also create artifacts.
Damping (which is significant) is also not included. Therefore the zero amplitude positions are just not there - at least by far not perfectly.
The fourier spectrum also doesn't compare the maximum total deviation of the target and actual trajectory, it just compares the amplitudes. This is ok, as long as we only compare ringing. To compare dimensional accuracy, this would be wrong.
The fourier spectrum shows:
- The rectangular acceleration change has cancellation positions at multiples of T.
- The triangular acceleration change has cancellation positions at multiples of 2 * T.
- Above 1.29 * T the triangular shape is - excluding all of the above written - better as the rectangular shape and vice versa.
- A triangular shape can be blended into a rectangular one, using a trapezoidal shape (but that doesn't mean that all, that all possible shapes are included in this comparison).
- Close to zero (< 0.2 T), there is not significant difference between different profiles - that is our normal operating position.
- The rectangular change excites higher frequencies much more than the triangular one, this is because of the sharp edges of the step.
- Using different trapezoid shapes, it is possible to generate cancellation locations “everywhere” between the rectangular and triangular profile.
The following Fourier spectrum compares different acceleration profiles, which all have the same pulse width and same end speed.
Another figure to show how a rectangular change can be blended into a triangular one using a trapezoidal shape.
-
3. How to utilize the cancellation points ?
From the Fourier transform we know, we could have no ringing after (that doesn't mean not in between) a speed change. To be able to use the zero amplitude positions to cancel the total ringing of a complete speed change, we have to know the period time which is 2 * pi/sqrt(c/m). Unfortunately c/m is by far not constant and not only one c/m has to dominate. It will vary among different fdm printers by a factor of up to 100 and it will vary also during a print. E.g. on a prusa style printer with a moving bed, the mass as well as the stiffness changes significantly. For the 1st layer c/m is big and for the last layer e.g. 200 mm above the bed with 500 g printed c/m will be very small, depending on the shape of the print, it might vary arbitrarily. On ultimaker style printer the same is valid, in a corner the stiffness is max and in the middle min. If the stepper current is doubled, c/m of the stepper is doubled. If the current of the stepper drops at high velocities, c/m of the stepper follows.... so c/m is not constant and in addition there is more than 1 mass spring damper system acting !So in total the length of a speed change would have to be adjusted during the print - to hunt the cancelation points. I don´t claim that this couldn´t be done (in theory), but for e.g prusa printers it won´t be doable or only in certain cases. On ultimaker style printers it will "only" work near e.g. the middle of the bed and as long the stepper current doesnt drop to much due to speed.
In my case my stiff printer has (stepper, belts and tubes) c/m values in the range of 1e5 to 1e6 [N * kg/m]. My slow printer has c/m values about 1e3 to 1e4 [N * kg/m].
A c/m of 1e6 gives a period time T of 2 * pi/sqrt(1e6) = 63ms (or 160 Hz); a c/m of 1e3 gives 199 ms or 5 Hz.
My stiff printer uses printing accelerations > 1g, so in 63 ms the speed change after one period time T of acceleration is > 10.000 * 0.063 = 630 mm/s. With 0.2 g at my slow printer the speed change would be 2000 * 0.2 = 400 mm/s. In other words the nowadays used acceleration settings just "mirrow" c/m and the time used for acceleration when printing is between 0 and << 0.1 - 0.2 * T. The fourier transform doesn´t show a significant difference there between different moveplan profiles - but the amplitudes of the waves generated during the move differ.So if we would print using speeds like before, we would have to reduce the acceleration to catch the 1st wave cancelation point at 1 * T. Increasing the acceleration time will amplify extrusion problems. In addition i don´t want to print slower....
If we would hunt for the 1st wave cancelation point by increasing the max speed, we would get really high speeds, with the need for "max. acceleration as a function of speed" and a working pressure advance.
In case we ask for multiple speed changes (moveplan) and not for a single speed change, the cancelation possibility gets more interesting. Multiple speed changes in a row can stimulate much lower frequencies as a single speed change. So we know that normally a single speed change operates at e.g. << 0.2 T. But multiple speed changes together could easily stimulate at or above 1 T. The high level move planner would have to adjust the move plan in a way, that the speed changes itself act close to the cancelation points. This could be beneficial for a lot of small moves in a row. E.g. when printing top and bottom layers and it fills a gap by zigzag moves.
4. Is a triangular profile a good choice to compare s-curve acceleration with a rectangular change ?
In addition to above, yes and no. It is true that one can blend the fourier transform from a triangle over a trapezoid into a rectangle (see the figure below). But whos says that we have to limit it to that simple kind of shapes ?Just try the following: instead of one triangular shape apply 2 after each other. Both have the half width of the single one and same amplitude. By that the frequency spectrum is shifted to the left by T/2 and the 1st wave cancelation is also at 1 * T, like in the rectangular case (and not like 2 * T in the single triangular case). So comparing a triangular with a rectangular profile just compares two profiles and not all available possibilities.
5. The main fdm problem is extrusion - not ringing.
Ringing can be solved by proper engineering. Extrusion is thermodynamically and fluid wise limited - these limits "cannot" be changed - at least not much. Pressure advance would help a lot, if it would have a chance to work. With a stepwise acceleration change, it can only work under certain limiting conditions. With “s-curve” (a more gentle) acceleration the pressure advance jerk problem caused by the step wise acceleration change would be "wiped away". Pressure advance could show its potential.6. Because one picture says more than 1000 words, i have attached some figs for a system like m * xdotdot +c * x = c * y(t) (so no damping and only one spring mass system). m = c = 1.
In case the acceleration time equals to the time period T, as shown in the fourier transform, the whole rectangular acceleration change produces no remaining waves (only without damping, with damping like in real life this doesn´t work perfectly at all). The triangular as well as trapezoidal acceleration change show waves - which would be damped quickly including damping, but this is the ringing we see on pure x/y/z printers.
Blue is the acceleration change ydotdot(t), orange is only the oscillation part of x(t).
Same for acceleration time equals to the time period T * 2 - now the triangluar change also produces no remaining waves. If instead of one triangle of width "a" 2 triangles of width "a/2" and the same height would be applied, the triangular profiless also would also show no remaining waves at 1 * T - like the rectangular case.
The same for a pulse width of 0.2 T. In real life it looks much better, because damping acts.
-
Just my 2 pence worth, reading this thread it is going to be of great benefit to some but make no difference to others.
From a practical perceptive it would be most useful to have S-curve available under an M-code, it could then be used per print.
I've used it on my Cartesian before I got my Duet (using Marlin2 and an MKS-Sbase) it does allow me to print faster at the same quality, Plus my desk didn't vibrate as much
However it did have those awful stepper drivers, so theres that.
-
@stewwy the option to select which acceleration type is used is part of the plan.
-
When S-curve acceleration is applied will the curve look more like this picture instead of a trapezoid? I got the picture off of the prusa calculator website.