Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
accel-branch [2017/01/25 16:14]
arthur
accel-branch [2017/01/25 18:54]
arthur
Line 17: Line 17:
 A summary of how we get smoothie to generate steps :  A summary of how we get smoothie to generate steps : 
  
-# We[[https://​github.com/​arthurwolf/​Smoothie/​blob/​edge/​src/​modules/​communication/​SerialConsole.cpp#​L40|receive a line over UART ( for example )]], and[[https://​github.com/​arthurwolf/​Smoothie/​blob/​edge/​src/​modules/​communication/​SerialConsole.cpp#​L61|dispatch it as an event to all modules]]. +# We [[https://​github.com/​arthurwolf/​Smoothie/​blob/​edge/​src/​modules/​communication/​SerialConsole.cpp#​L40|receive a line over UART ( for example )]], and [[https://​github.com/​arthurwolf/​Smoothie/​blob/​edge/​src/​modules/​communication/​SerialConsole.cpp#​L61|dispatch it as an event to all modules]]. 
-# If[[https://​github.com/​arthurwolf/​Smoothie/​blob/​edge/​src/​modules/​communication/​GcodeDispatch.cpp#​L28|that line is a GCode]], we[[https://​github.com/​arthurwolf/​Smoothie/​blob/​edge/​src/​modules/​communication/​GcodeDispatch.cpp#​L100|dispatch that as an event to all modules]]. +# If [[https://​github.com/​arthurwolf/​Smoothie/​blob/​edge/​src/​modules/​communication/​GcodeDispatch.cpp#​L28|that line is a GCode]], we [[https://​github.com/​arthurwolf/​Smoothie/​blob/​edge/​src/​modules/​communication/​GcodeDispatch.cpp#​L100|dispatch that as an event to all modules]]. 
-# The[[https://​github.com/​arthurwolf/​Smoothie/​blob/​edge/​src/​modules/​robot/​Robot.cpp#​L95|Robot like to listen to GCodes]], converts them into small line segments, and[[https://​github.com/​arthurwolf/​Smoothie/​blob/​edge/​src/​modules/​robot/​Robot.cpp#​L253|passes those to the Planner]]. +# The [[https://​github.com/​arthurwolf/​Smoothie/​blob/​edge/​src/​modules/​robot/​Robot.cpp#​L95|Robot like to listen to GCodes]], converts them into small line segments, and [[https://​github.com/​arthurwolf/​Smoothie/​blob/​edge/​src/​modules/​robot/​Robot.cpp#​L253|passes those to the Planner]]. 
-# The[[https://​github.com/​arthurwolf/​Smoothie/​blob/​edge/​src/​modules/​robot/​Planner.cpp#​L39|Planner receives this segment]], and[[https://​github.com/​arthurwolf/​Smoothie/​blob/​edge/​src/​modules/​robot/​Planner.cpp#​L46|turns it into a Block on the Conveyor]], then[[https://​github.com/​arthurwolf/​Smoothie/​blob/​edge/​src/​modules/​robot/​Planner.cpp#​L155|does all kinds of acceleration math/​planning on it to figure out the maximal speeds for each movement]]. The block is now at the end of the Conveyor'​s queue. +# The [[https://​github.com/​arthurwolf/​Smoothie/​blob/​edge/​src/​modules/​robot/​Planner.cpp#​L39|Planner receives this segment]], and [[https://​github.com/​arthurwolf/​Smoothie/​blob/​edge/​src/​modules/​robot/​Planner.cpp#​L46|turns it into a Block on the Conveyor]], then [[https://​github.com/​arthurwolf/​Smoothie/​blob/​edge/​src/​modules/​robot/​Planner.cpp#​L155|does all kinds of acceleration math/​planning on it to figure out the maximal speeds for each movement]]. The block is now at the end of the Conveyor'​s queue. 
-# If this is the first block we added ever, the[[https://​github.com/​arthurwolf/​Smoothie/​blob/​edge/​src/​modules/​robot/​Conveyor.cpp#​L90|conveyor queue starts playing music : ]] the Conveyor[[https://​github.com/​arthurwolf/​Smoothie/​blob/​edge/​src/​modules/​robot/​Conveyor.cpp#​L113|calls the on_block_begin event, warning all modules that this block starts playing]]. +# If this is the first block we added ever, the [[https://​github.com/​arthurwolf/​Smoothie/​blob/​edge/​src/​modules/​robot/​Conveyor.cpp#​L90|conveyor queue starts playing music : ]] the Conveyor [[https://​github.com/​arthurwolf/​Smoothie/​blob/​edge/​src/​modules/​robot/​Conveyor.cpp#​L113|calls the on_block_begin event, warning all modules that this block starts playing]]. 
-# Some modules, like Stepper and Extruder, like[[https://​github.com/​arthurwolf/​Smoothie/​blob/​edge/​src/​modules/​robot/​Stepper.cpp#​L120|to take responsability for a Block]]. We are here interrested in Stepper as it's the one responsible for doing movements. +# Some modules, like Stepper and Extruder, like [[https://​github.com/​arthurwolf/​Smoothie/​blob/​edge/​src/​modules/​robot/​Stepper.cpp#​L120|to take responsability for a Block]]. We are here interrested in Stepper as it's the one responsible for doing movements. 
-# Now the very interresting ( for us, don't be sad, planner people ) part begins :​ Stepper[[https://​github.com/​arthurwolf/​Smoothie/​blob/​edge/​src/​modules/​robot/​Stepper.cpp#​L131|instructs it's StepperMotor objects to move]]. They are instructed to[[https://​github.com/​arthurwolf/​Smoothie/​blob/​edge/​src/​libs/​StepperMotor.cpp#​L110|move a certain number of steps]]. Also, the StepperMotor is[[https://​github.com/​arthurwolf/​Smoothie/​blob/​edge/​src/​libs/​StepperMotor.cpp#​L130|made active]] in the[[https://​github.com/​arthurwolf/​Smoothie/​blob/​edge/​src/​libs/​StepTicker.cpp#​L247|Stepticker'​s list of active motors]].+# Now the very interresting ( for us, don't be sad, planner people ) part begins :​ Stepper [[https://​github.com/​arthurwolf/​Smoothie/​blob/​edge/​src/​modules/​robot/​Stepper.cpp#​L131|instructs it's StepperMotor objects to move]]. They are instructed to [[https://​github.com/​arthurwolf/​Smoothie/​blob/​edge/​src/​libs/​StepperMotor.cpp#​L110|move a certain number of steps]]. Also, the StepperMotor is [[https://​github.com/​arthurwolf/​Smoothie/​blob/​edge/​src/​libs/​StepperMotor.cpp#​L130|made active]] in the [[https://​github.com/​arthurwolf/​Smoothie/​blob/​edge/​src/​libs/​StepTicker.cpp#​L247|Stepticker'​s list of active motors]].
 # Things now stop happening in the normal, main loop context, and start happening elsewhere. # Things now stop happening in the normal, main loop context, and start happening elsewhere.
-# The stepping interrupt is executed by the interrupt thingie,​[[https://​github.com/​arthurwolf/​Smoothie/​blob/​edge/​src/​libs/​StepTicker.cpp#​L54|at a fixed frequency]] ( we used 100khz, the default ). +# The stepping interrupt is executed by the interrupt thingie, [[https://​github.com/​arthurwolf/​Smoothie/​blob/​edge/​src/​libs/​StepTicker.cpp#​L54|at a fixed frequency]] ( we used 100khz, the default ). 
-# When this[[https://​github.com/​arthurwolf/​Smoothie/​blob/​edge/​src/​libs/​StepTicker.cpp#​L151|interrupt occurs]], the main thing to happen is that every active StepperMotor'​s[[https://​github.com/​arthurwolf/​Smoothie/​blob/​edge/​src/​libs/​StepTicker.cpp#​L88|tick() method gets called]]. +# When this [[https://​github.com/​arthurwolf/​Smoothie/​blob/​edge/​src/​libs/​StepTicker.cpp#​L151|interrupt occurs]], the main thing to happen is that every active StepperMotor'​s [[https://​github.com/​arthurwolf/​Smoothie/​blob/​edge/​src/​libs/​StepTicker.cpp#​L88|tick() method gets called]]. 
-# The main job of[[https://​github.com/​arthurwolf/​Smoothie/​blob/​edge/​src/​libs/​StepperMotor.cpp#​L43|this method]] is simply to do what is called[[http://​en.wikipedia.org/​wiki/​Bresenham%27s_line_algorithm|Bresenham'​s_line_algorithm]]. Basically, we increment a counter by a fixed value every tick(), and[[https://​github.com/​arthurwolf/​Smoothie/​blob/​edge/​src/​libs/​StepperMotor.cpp#​L49|when that counter is higher than a given value]] ( determined by[[https://​github.com/​arthurwolf/​Smoothie/​blob/​edge/​src/​libs/​StepperMotor.cpp#​L158|the speed we want to move at]] ), we[[https://​github.com/​arthurwolf/​Smoothie/​blob/​edge/​src/​libs/​StepperMotor.cpp#​L52|generate a step signal to the stepper driver]].+# The main job of [[https://​github.com/​arthurwolf/​Smoothie/​blob/​edge/​src/​libs/​StepperMotor.cpp#​L43|this method]] is simply to do what is called [[http://​en.wikipedia.org/​wiki/​Bresenham%27s_line_algorithm|Bresenham'​s_line_algorithm]]. Basically, we increment a counter by a fixed value every tick(), and [[https://​github.com/​arthurwolf/​Smoothie/​blob/​edge/​src/​libs/​StepperMotor.cpp#​L49|when that counter is higher than a given value]] ( determined by [[https://​github.com/​arthurwolf/​Smoothie/​blob/​edge/​src/​libs/​StepperMotor.cpp#​L158|the speed we want to move at]] ), we [[https://​github.com/​arthurwolf/​Smoothie/​blob/​edge/​src/​libs/​StepperMotor.cpp#​L52|generate a step signal to the stepper driver]].
 (note we do not actually do Bresenham, we do a floating point DDA on three axis). (note we do not actually do Bresenham, we do a floating point DDA on three axis).
  
Line 36: Line 36:
 This happens in a separate ( lower priority ) timer, at regular, but more rare intervals. This happens in a separate ( lower priority ) timer, at regular, but more rare intervals.
  
-#​[[https://​github.com/​arthurwolf/​Smoothie/​blob/​edge/​src/​modules/​robot/​Stepper.cpp#​L176|This method]] gets called periodically,​ and, depending on whether we are accelerating,​ decelerating,​ or cruising +# [[https://​github.com/​arthurwolf/​Smoothie/​blob/​edge/​src/​modules/​robot/​Stepper.cpp#​L176|This method]] gets called periodically,​ and, depending on whether we are accelerating,​ decelerating,​ or cruising 
-# Changes the speed or does not[[https://​github.com/​arthurwolf/​Smoothie/​blob/​edge/​src/​modules/​robot/​Stepper.cpp#​L242|for all movement stepper motors]].+# Changes the speed or does not [[https://​github.com/​arthurwolf/​Smoothie/​blob/​edge/​src/​modules/​robot/​Stepper.cpp#​L242|for all movement stepper motors]].
  
 This is behaviour is inherited from grbl, and is the source of many approximations/​small problems. ​ This is behaviour is inherited from grbl, and is the source of many approximations/​small problems. ​
Line 55: Line 55:
 Basically, we want this to take as little time as possible in order to do it as often as possible. Basically, we want this to take as little time as possible in order to do it as often as possible.
  
-In order to analyse how much various things we do take to execute, their cost, we can simply turn pins high at the beginning of things, low at the end of them, plug in a[[http://​www.bitscope.net/​store/?​p=view&​i=item+4|Logic Analyser]], and look at the graphs.+In order to analyse how much various things we do take to execute, their cost, we can simply turn pins high at the beginning of things, low at the end of them, plug in a [[http://​www.bitscope.net/​store/?​p=view&​i=item+4|Logic Analyser]], and look at the graphs.
  
 This has been extremely useful in the past to figure out where we spent too much times, what needed fixing etc. This has been extremely useful in the past to figure out where we spent too much times, what needed fixing etc.
Line 61: Line 61:
 [[=image flickr:​8491890623 size="​original"​]] [[=image flickr:​8491890623 size="​original"​]]
  
-# In white, is the X axis step signal. It is[[https://​github.com/​arthurwolf/​Smoothie/​blob/​edge/​src/​libs/​StepperMotor.cpp#​L52|turned on here]] and[[https://​github.com/​arthurwolf/​Smoothie/​blob/​edge/​src/​libs/​StepTicker.cpp#​L134|turned off here]]. +# In white, is the X axis step signal. It is [[https://​github.com/​arthurwolf/​Smoothie/​blob/​edge/​src/​libs/​StepperMotor.cpp#​L52|turned on here]] and [[https://​github.com/​arthurwolf/​Smoothie/​blob/​edge/​src/​libs/​StepTicker.cpp#​L134|turned off here]]. 
-# In brown is the[[https://​github.com/​arthurwolf/​Smoothie/​blob/​edge/​src/​libs/​StepTicker.cpp#​L151|duration of this interrupt]]. This is the total time we spend generating steps. It is the time we want to reduce as much as possible. A bit of the rest of the time is spend doing acceleration,​ all the rest in the main loop, mostly doing Planner math. +# In brown is the [[https://​github.com/​arthurwolf/​Smoothie/​blob/​edge/​src/​libs/​StepTicker.cpp#​L151|duration of this interrupt]]. This is the total time we spend generating steps. It is the time we want to reduce as much as possible. A bit of the rest of the time is spend doing acceleration,​ all the rest in the main loop, mostly doing Planner math. 
-# In red, which never turns high here, is the duration of[[https://​github.com/​arthurwolf/​Smoothie/​blob/​edge/​src/​libs/​StepTicker.cpp#​L187|this condition, if it ever becomes true]], not very interesting here. Basically, we make sure if we spent so much time in this interrupt occurence that it overlaps on the next occurance, we skip the next, but make sure we do so without messing any of the rest of the math.+# In red, which never turns high here, is the duration of [[https://​github.com/​arthurwolf/​Smoothie/​blob/​edge/​src/​libs/​StepTicker.cpp#​L187|this condition, if it ever becomes true]], not very interesting here. Basically, we make sure if we spent so much time in this interrupt occurence that it overlaps on the next occurance, we skip the next, but make sure we do so without messing any of the rest of the math.
 # In orange, is the duration of [https://​github.com/​arthurwolf/​Smoothie/​blob/​edge/​src/​libs/​StepperMotor.cpp#​L43 the tick() method of each StepperMotor # In orange, is the duration of [https://​github.com/​arthurwolf/​Smoothie/​blob/​edge/​src/​libs/​StepperMotor.cpp#​L43 the tick() method of each StepperMotor
-# In yellow, is the duration of[[https://​github.com/​arthurwolf/​Smoothie/​blob/​edge/​src/​libs/​StepperMotor.cpp#​L49|this condition]] inside the tick() method, if true. Basically, if we have to generate a step, this turns high.+# In yellow, is the duration of [[https://​github.com/​arthurwolf/​Smoothie/​blob/​edge/​src/​libs/​StepperMotor.cpp#​L49|this condition]] inside the tick() method, if true. Basically, if we have to generate a step, this turns high.
  
 The width of the screen should represent 10 microseconds. The width of the screen should represent 10 microseconds.
Line 180: Line 180:
 // And that's it // And that's it
  
-[[/code]]+</code>
  
 Several optimisations found and applied :  Several optimisations found and applied : 
-*[[https://​github.com/​arthurwolf/​Smoothie/​commit/​12aad2a05e16a813e18f4cd27c9c0ae7cf90685e|Exit]] the interrupt early if no step was generated. +* [[https://​github.com/​arthurwolf/​Smoothie/​commit/​12aad2a05e16a813e18f4cd27c9c0ae7cf90685e|Exit]] the interrupt early if no step was generated. 
-*[[https://​github.com/​arthurwolf/​Smoothie/​commit/​8aea2a3537b7881fee83902e062d23c4a50e0dd0|Disable]] the interrupt when not moving. +* [[https://​github.com/​arthurwolf/​Smoothie/​commit/​8aea2a3537b7881fee83902e062d23c4a50e0dd0|Disable]] the interrupt when not moving. 
-*[[https://​github.com/​arthurwolf/​Smoothie/​commit/​8aea2a3537b7881fee83902e062d23c4a50e0dd0|Inline]] the StepperMotor'​s tick() function.+* [[https://​github.com/​arthurwolf/​Smoothie/​commit/​8aea2a3537b7881fee83902e062d23c4a50e0dd0|Inline]] the StepperMotor'​s tick() function.
  
 These are optimisations that are most useful in the case we don't do anything. Applying them gives us the following signals/​durations :  These are optimisations that are most useful in the case we don't do anything. Applying them gives us the following signals/​durations :