Welcome! Log In Create A New Profile

Advanced

Jerk and Acceleration in Marlin

Posted by Logrod 
Jerk and Acceleration in Marlin
December 02, 2012 05:09PM
Can someone explain the difference between max acceleration and jerk in Marlin and what the risks are if either are too high or low please?
Re: Jerk and Acceleration in Marlin
December 02, 2012 08:45PM
Jerk is the instantaneous change in velocity, Acceleration is the rate at which it changes velocity between the Jerk setting and the requested velocity.
Re: Jerk and Acceleration in Marlin
December 02, 2012 09:12PM
from what i can tell xy jerk is the same as start speed, and acceleration is the rate of acceleration to max speed of motors.

the only issue with setting xy jerk low is prints take longer, and with setting it to high prints misaligned. acceleration is only an issue if max speed is not calibrated correctly. then a long move will cause motor to stall.
Re: Jerk and Acceleration in Marlin
December 20, 2012 03:41PM
Speed is the rate of change of position.
Acceleration is the rate of change of speed.
Jerk is the rate of change of acceleration.
Re: Jerk and Acceleration in Marlin
December 20, 2012 07:29PM
Yes in a mathematical sense they are all the derivatives of each other as you said Dale.

There are also the terms "snap", "crackle" and "pop" to describe the fourth, fifth and sixth derivatives. I don't believe these are ever really used in practical applications, although I think you can apply them to find the optimal path around objects (depending what you are trying to minimize, be it acceleration forces, power required, speed or distance e.t.c)

Correct me if I'm wrong, but I'm pretty sure that the implementation in Marlin is not the derivative of acceleration and "jerk" is just the highest allowable instantaneous change in velocity vector.

Since on a 3D printer all parts are described by lots of tiny straight lines, there are hundreds of corners that the head moves through when, for example, it goes around a circle. There are no smooth curves, even when using curve G codes, your controller breaks the curve down into lots of tiny lines, smaller than you would find in any sensible sized STL. Mathematically if you go around a corner at speed your acceleration and (real) jerk go to infinity.

So to handle the maths, either you can't go around a corner at speed and have to keep stopping, you actively round the corners slightly to avoid infinite jerk/accel, or you just completely fudge the maths. What the jerk setting does is impose a limit on instant velocity change at each corner and then the printer accelerates at a constant rate away from there. This allows your printer to go very fast around gently curved surfaces, since the change in velocity vector is very small at each vertex, and allows it to go in a slow controlled manner around sharp corners. The actual jerk your printer sees will be defined by its springyness.

Edited 2 time(s). Last edit at 12/20/2012 07:34PM by konwiddak.
Re: Jerk and Acceleration in Marlin
December 20, 2012 07:41PM
jamesdanielv Wrote:
-------------------------------------------------------
> the only issue with setting xy jerk low is prints
> take longer,

Actually it is the main cause of prints with blobs in the corners and other places. If you increase the jerk setting you will see the blobs go away.


FFF Settings Calculator Gcode post processors Geometric Object Deposition Tool Blog
Tantillus.org Mini Printable Lathe How NOT to install a Pololu driver
Re: Jerk and Acceleration in Marlin
December 21, 2012 07:57AM
So what would be a sensible range of jerk to test out?
Re: Jerk and Acceleration in Marlin
December 21, 2012 08:27AM
Quote
Dale Dunn
Jerk is the rate of change of acceleration.

Nope. As Polygonhell said, jerk is an instantaneous change of speed (not acceleration). In principle, it's physically impossible; still it can make sense tro try anyways. Either because jerk is lower than the stepper motor's resolution or because the printer frame will bend a bit to compensate.


Generation 7 Electronics Teacup Firmware RepRap DIY
     
Re: Jerk and Acceleration in Marlin
December 21, 2012 09:02AM
Traumflug Wrote:
-------------------------------------------------------
> Jerk is the rate of change of acceleration.
>
> Nope. As Polygonhell said, jerk is an
> instantaneous change of speed (not acceleration).
> In principle, it's physically impossible; still it
> can make sense tro try anyways. Either because
> jerk is lower than the stepper motor's resolution
> or because the printer frame will bend a bit to
> compensate.

That might be what you think, but it doesn't match general usage [en.wikipedia.org]

I believe that konwiddaks explanation is correct.
Re: Jerk and Acceleration in Marlin
December 21, 2012 10:02AM
i use a setting between 20-35 for jerk settings. and 1 on the z axis setting. this is about right for my machine. any faster print quality suffers, and i have parts start to loosen up. you do want this as high as possible because prints will take less time. there are a lot of short moves in a print job. this setting effects the short moves. acceleration kicks in afterwards.

I think default settings are around 15. currently I have set my latest printer a prusa to 25 for x,y and 1 for z.
Re: Jerk and Acceleration in Marlin
December 21, 2012 10:57AM
bobc Wrote:
-------------------------------------------------------
> Traumflug Wrote:
> --------------------------------------------------
> -----
> > Jerk is the rate of change of acceleration.
> >
> > Nope. As Polygonhell said, jerk is an
> > instantaneous change of speed (not
> acceleration).
> > In principle, it's physically impossible; still
> it
> > can make sense tro try anyways. Either because
> > jerk is lower than the stepper motor's
> resolution
> > or because the printer frame will bend a bit to
> > compensate.
>
> That might be what you think, but it doesn't match
> general usage
> [en.wikipedia.org]
>
> I believe that konwiddaks explanation is correct.

Yes the term is misused in the firmware and doesn't match the mathematical definition.
If you look at the firmware code it's the Instantaneous change in velocity.
I assume what we care about here is how it's used in the firmware not the mathematical definition.
Re: Jerk and Acceleration in Marlin
December 21, 2012 11:09AM
Thanks for thoses values James, I'll try playing with my settings see if it has an effect. Is jerk setting for E important as well?
Re: Jerk and Acceleration in Marlin
December 21, 2012 11:15AM
Logrod Wrote:
-------------------------------------------------------
> Thanks for thoses values James, I'll try playing
> with my settings see if it has an effect. Is jerk
> setting for E important as well?


Yes and no, because the firmware has to move all of the axis in sync, so you are always constrained by the slowest axis in a move.
However E moves are usually really small, and stepper velocities low, so almost any setting will mean the move is constrained by the XY and not E
Re: Jerk and Acceleration in Marlin
December 21, 2012 05:44PM
Polygonhell Wrote:
-------------------------------------------------------
> Logrod Wrote:
> --------------------------------------------------
> -----
> > Thanks for thoses values James, I'll try
> playing
> > with my settings see if it has an effect. Is
> jerk
> > setting for E important as well?
>
>
> Yes and no, because the firmware has to move all
> of the axis in sync, so you are always constrained
> by the slowest axis in a move.
> However E moves are usually really small, and
> stepper velocities low, so almost any setting will
> mean the move is constrained by the XY and not E

The E jerk and acceleration are used during Retracts so they are important and do effect the print in a way. For Tantillus I have the Acceleration set to 10000 for E and the Jerk set to 100 because of the need for a 5.5mm retract on the Bowden cable and we want it instantaneous. This may not work for most printers since on a bowden machine the filament springiness is enough to accelerate the extruder backwards really fast and prevent skipped steps while retracting.


FFF Settings Calculator Gcode post processors Geometric Object Deposition Tool Blog
Tantillus.org Mini Printable Lathe How NOT to install a Pololu driver
Re: Jerk and Acceleration in Marlin
December 22, 2012 04:10AM
Polygonhell Wrote:
-------------------------------------------------------
> Yes the term is misused in the firmware and
> doesn't match the mathematical definition.
> If you look at the firmware code it's the
> Instantaneous change in velocity.
> I assume what we care about here is how it's used
> in the firmware not the mathematical definition.

I have ported grbl derived code to another platform, and fixed a few bugs in it, so I am familiar with the code. Change in velocity is of course acceleration, whether instantaneous or not. What the firmware actually does is a specific fix to reduce the speed at junctions to allow for change in direction (aka acceleration). The "jerk" is a fudge factor which effectively reduces acceleration in this specific case. This is the same goal as a third-order motion profile, so is not that dissimilar to real jerk. It's a quick estimation, rather than a full calculation.

Within a move though, or if there are several moves in a line say, then the speed follows a straight trapezoidal profile and there is no jerk limiting.
Re: Jerk and Acceleration in Marlin
December 22, 2012 06:52AM
Quote

The "jerk" is a fudge factor which effectively reduces acceleration in this specific case.

Unless I'm missing something substantial, GRBL/Marlin/Sprinter move, except on G2/G3, straight lines only. With strictly straight lines, you have to stop at each corner or you fudge on physics. Because any sudden change in speed or direction requires infinite acceleration, which is physically impossible.

The firmware jerk factor replaces some controlled acceleration by an (adjustable) amount of this fudging. Makes some sense in practice, but isn't mathematically clean.

Because of this, more advanced motion controllers, like EMC, EMC2 or industrial CNC controllers, have no jerk setting. They stick to physics and provide the G64 G-code: [geekbraindump.blogspot.de]


Generation 7 Electronics Teacup Firmware RepRap DIY
     
Re: Jerk and Acceleration in Marlin
December 23, 2012 08:03PM
the arc is also calculated on marlin thru a line that intersects an another line with a different angle, so going around a corner when x stops and y begins, there is an opportunity for acceleration to being early for y, around the arc of the angle. arc commands from host takes less data to process and keep the buffer full, and you can easily predict the speed and acceleration because you are in an arc for a specified angle. this is already part of grbl, which marlins is based off of. marlin adds path planing for extruder compensation, meaning e steps advance and create flow before x,y move .

Edited 1 time(s). Last edit at 12/23/2012 08:08PM by jamesdanielv.
Re: Jerk and Acceleration in Marlin
December 24, 2012 08:06AM
Quote

going around a corner when x stops and y begins, there is an opportunity for acceleration to being early for y, around the arc of the angle.

Yes, there is the opportunity, but GRBL doesn't take that opptortunity. To be sure, I just took another look into GRBL's sources and found stuff like this:

Line 95, motion_control.c:
// The arc is approximated by generating a huge number of tiny, linear segments.
==> GRBL can't do curved movements. G2/G3 lowers communications from the host, but doesn't approxximate curves at the single step level.

// NOTE: This is basically an exact path mode (G61), but it doesn't come to a complete stop unless
// the junction deviation value is high. In the future, if continuous mode (G64) is desired, [...]
Here they explicitely state they don't do path blending or corner rounding.

Looking at stepper.c line 276ff, where the actual stepper pulses are generated, I can't even find a constant acceleration algorithm. They accelerate by subtracting a constant value from the time interval between two pulses (higher speeds) or by simply dividing the interval by 2 (lower speeds).

Blending two linear segments is possible, but not exactly trivial when using the Bresenham algorithm. I tried many times and always failed so far. Bresenham depends on a "fast axis", which is the axis with the most step pulses. This axis provides the speed, but can change between two linear segments.

Now, GRBL has an advantage here, it uses sort of a virtual axis ("event_count") which isn't directly tied to a stepper motor. The virtual axis is for speed calculations, only. As I have to stop writing this comment somewhere only this: a virtual axis comes with new problems, especially on machines with vastly different steps/mm on distinct axes.


Generation 7 Electronics Teacup Firmware RepRap DIY
     
Re: Jerk and Acceleration in Marlin
September 22, 2016 05:08AM
what decides the speed of 3d printing in marlin
Re: Jerk and Acceleration in Marlin
September 23, 2016 05:51AM
Its the gcode produced by your slicer that sets the speed of the moves that do the printing.

So if using slic3r, on the speed tab you set the speed you want for different moves, eg perimeters, infill, support etc.... Your firmware is only relevant to speed if you have limits set which are below the speeds you ask for in your slicer. So if you set the speed for x axis (max feedrate) to 100 mm/s (6000 mm/min) in firmware, and then slice a model with perimeter speed set at 150 mm/s in the slicer, it will only move at 100mm/s the firmware won't allow it to go faster.

Acceleration and jerk are set in the firmware as they relate to the mechanical abilities of the printer. So having low accelerations isn't going to be a problem unless you are on a mission to print fast.

Having too high jerk setting might affect accuracy as your printer might not be stiff enough to instantly change direction that quickly. Too low and your corners get rounded off. The default in Marlin, 20 is about right for most machines, but try higher and lower se what happens.


Simon Khoury

Co-founder of [www.precisionpiezo.co.uk] Accurate, repeatable, versatile Z-Probes
Published:Inventions
Re: Jerk and Acceleration in Marlin
September 23, 2016 12:20PM
Just to chime in, the jerk and acceleration settings are a battle between over-extrusion at the corners vs. a ribbed "ringing" pattern in the side of the print. The over-extrusion at the corners is a result extruder hysteresis. When you slow down to take a corner, the actual extrusion process lags a little bit (even thought the extrusion motor is perfectly synched) so that the flow rate is still a little high as you go around the corner. There is there is then some under-extrusion as you start down the next side, but that's not usually so visible. The temptation, then, is to take the corner like a bat out of hell and not slow down the XY motion or the extruder, keeping both at a constant speed (ie, high accel and jerk settings). However, because your printer can't actually change direction instantaneously like you ask it to, the belts and even entire frame get stretched like a sling shot. As you are launched around the corner, you also end up ringing back & forth like a bungee jumper until you settle again into a constant velocity.

The default Marlin XY speed and jerk (9000 and 20) are actually way too high for most machines, and tend to produce a lot of ringing. It all depends, though, on whether you are bothered more by the ringing pattern or the corner over-extrusion.
Re: Jerk and Acceleration in Marlin
September 23, 2016 07:53PM
Lots of good information here from everyone.

I want to expand one area regarding "what decides the speed of 3d printing in Marlin", and propose a method for testing Jerk.

DjDemonD and others have indicated:
The firmware settings for max speed, acceleration, and Jerk affect the max speed that can be achieved regardless of the speed specified in the slicer.
  • For shorter loops: the printer can not reach full speed and decelerate again in the given distance - because of fixed acceleration limits.
  • For sharp corners the speed is reduced further, as the speed at the corners is lowered in proportion to their sharpness by the Jerk setting. So for example a complicated vase with many small sharp facets may actually print at 60% of the speed you request in the slicer.

Most host programs do not calculate the full acceleration profile for each segment when calculating print time, which is why the actual print time is often longer.


Edit:
For testing Jerk/Junction Deviation settings I created a multi-angle test tower.
You can use this to calibrate your Jerk settings by inserting Gcode to set the Jerk value at regular height increments, like this:

  • Slice the tower with 1 perimeter, and no top layers - in other words as a single walled object, do not use z lift.
  • Decide what your starting Jerk value will be, and how much you want to increment it for each section.
  • Edit the gcode file, look for the G0 Z... or G1 Z.... commands (the layer changes), and starting with the first layer, and then every 3 mm increment, Insert a M205 command to change the Jerk value
  • Example Jerk Gcode for Marlin: M205 X10 Z5 ; Sets X/Y Jerk to 10mms, Z jerk to 5mms
  • At each Z height increment, insert another M205 with an increased X value. For instance the next command could be: M205 X15 Z5
  • Save and Print.
  • Observe the changes at the corners, and changes in ringing.
  • Count the steps to the best area observed to determine which Jerk value you used there.
  • Either add a M205 command with that Jerk value to your start gcode, or update your firmware with it.
  • You may want to test again with a different default acceleration.

You can use the same method for testing Acceleration, temperature etc. Just switch out the gcode you have added at each height.

The gcode setting for Jerk varies by firmware. See here. "Jerk" is called "Junction Deviation" in other firmware and is calculated differently, and so has different setting/values.

Edit:
I have uploaded a test tower that has angles: 20, 30, 40, 50, 60, 70, 80, 90, 100, 140 degrees, with equal sized segments (except between the last and first segment), and slight step in or out (.08mm) every 3 mm to indicate where the changes will be (10 steps - so 9 changes after the first layer).
This will make it easier to determine what Jerk is doing with different angles, where the best value, and the steps make it easier to see where each change was made.

You can get the STL and instructions from Youmagine
Please let me know how it goes (I'm sick at the moment and can't get near my printer).

Edited 2 time(s). Last edit at 09/24/2016 01:23AM by Paul Wanamaker.


My printer: Raptosaur - Large Format Delta - [www.paulwanamaker.wordpress.com]
Can you answer questions about Calibration, Printing issues, Mechanics? Write it up and improve the Wiki!
Re: Jerk and Acceleration in Marlin
March 24, 2017 01:43PM
Sorry for reviving a dead thread, but I have questions that are relavent and posting it here for prosperity seems appropriate.

I am currently having issues finding the right acceleration and jerk. My problem is, if I decrease the jerk, and increase the speed, its great, but if I then decrease the speed for a higher quality print, the lowered jerk then causes problems with corners blobbing up. Is the acceleration the key here? Or do I need to have different jerk settings for every print speed?
High jerk settings (20 ish) with high print speed causes too much vibration and bolts start coming loose, which is real pain as you would suspect. I haven't suffered from misalignment from a high jerk at high speeds, but I do have ghosting problems around walls. The blobs are almost worse, as they slowly snag the nozzle more and more as the print goes on, eventually causing the X or Y axis to skip a step, messing up the whole print. Whats the solution here?
Re: Jerk and Acceleration in Marlin
December 09, 2017 05:44PM
I want to update my "time calculator" for g-code ( [github.com] ) to properly support marlin too but I'm having issues going trough the arduino code structure sad smiley ... attm it works great with smoothieware that's also based on grbl but that kept the junction_deviation instead of jerk so the speed calc is bit different. There's some nicely visualized data here about junction_deviation if anyone is interested and also some more details about the algorithm itself here.

Now, I can't find the same thing for Marlin, how the jerk in Marlin firmware actually affects the speed .. I'm looking at the planner.cpp but the Planner::_buffer_line() is tad too long (750lines) and hard to navigate if you are not familiar with Marlin firmware.. so I'm not sure how are "enter" and "exit" speed of a single segment related to junction and angle to the previous segment? I'll go trough it if I have to but if someone familiar with the system can spit out the relevant formula and save me some time I'd really appreciate grinning smiley

Edited 1 time(s). Last edit at 12/09/2017 05:52PM by arhimed.
Sorry, only registered users may post in this forum.

Click here to login