Browse Source

Adjust some commentary

Scott Lahteine 7 years ago
parent
commit
2566342979
1 changed files with 20 additions and 21 deletions
  1. 20
    21
      Marlin/src/module/stepper.cpp

+ 20
- 21
Marlin/src/module/stepper.cpp View File

@@ -320,15 +320,15 @@ void Stepper::set_directions() {
320 320
 
321 321
 #if ENABLED(S_CURVE_ACCELERATION)
322 322
   /**
323
-   *   We are using a quintic (fifth-degree) Bézier polynomial for the velocity curve.
324
-   *  This gives us a "linear pop" velocity curve; with pop being the sixth derivative of position:
323
+   *  This uses a quintic (fifth-degree) Bézier polynomial for the velocity curve, giving
324
+   *  a "linear pop" velocity curve; with pop being the sixth derivative of position:
325 325
    *  velocity - 1st, acceleration - 2nd, jerk - 3rd, snap - 4th, crackle - 5th, pop - 6th
326 326
    *
327 327
    *  The Bézier curve takes the form:
328 328
    *
329 329
    *  V(t) = P_0 * B_0(t) + P_1 * B_1(t) + P_2 * B_2(t) + P_3 * B_3(t) + P_4 * B_4(t) + P_5 * B_5(t)
330 330
    *
331
-   *   Where 0 <= t <= 1, and V(t) is the velocity. P_0 through P_5 are the control points, and B_0(t)
331
+   *  Where 0 <= t <= 1, and V(t) is the velocity. P_0 through P_5 are the control points, and B_0(t)
332 332
    *  through B_5(t) are the Bernstein basis as follows:
333 333
    *
334 334
    *        B_0(t) =   (1-t)^5        =   -t^5 +  5t^4 - 10t^3 + 10t^2 -  5t   +   1
@@ -341,12 +341,12 @@ void Stepper::set_directions() {
341 341
    *                                      |       |       |       |       |       |
342 342
    *                                      A       B       C       D       E       F
343 343
    *
344
-   *   Unfortunately, we cannot use forward-differencing to calculate each position through
344
+   *  Unfortunately, we cannot use forward-differencing to calculate each position through
345 345
    *  the curve, as Marlin uses variable timer periods. So, we require a formula of the form:
346 346
    *
347 347
    *        V_f(t) = A*t^5 + B*t^4 + C*t^3 + D*t^2 + E*t + F
348 348
    *
349
-   *   Looking at the above B_0(t) through B_5(t) expanded forms, if we take the coefficients of t^5
349
+   *  Looking at the above B_0(t) through B_5(t) expanded forms, if we take the coefficients of t^5
350 350
    *  through t of the Bézier form of V(t), we can determine that:
351 351
    *
352 352
    *        A =    -P_0 +  5*P_1 - 10*P_2 + 10*P_3 -  5*P_4 +  P_5
@@ -356,7 +356,7 @@ void Stepper::set_directions() {
356 356
    *        E = - 5*P_0 +  5*P_1
357 357
    *        F =     P_0
358 358
    *
359
-   *   Now, since we will (currently) *always* want the initial acceleration and jerk values to be 0,
359
+   *  Now, since we will (currently) *always* want the initial acceleration and jerk values to be 0,
360 360
    *  We set P_i = P_0 = P_1 = P_2 (initial velocity), and P_t = P_3 = P_4 = P_5 (target velocity),
361 361
    *  which, after simplification, resolves to:
362 362
    *
@@ -367,12 +367,12 @@ void Stepper::set_directions() {
367 367
    *        E = 0
368 368
    *        F = P_i
369 369
    *
370
-   *   As the t is evaluated in non uniform steps here, there is no other way rather than evaluating
370
+   *  As the t is evaluated in non uniform steps here, there is no other way rather than evaluating
371 371
    *  the Bézier curve at each point:
372 372
    *
373 373
    *        V_f(t) = A*t^5 + B*t^4 + C*t^3 + F          [0 <= t <= 1]
374 374
    *
375
-   *   Floating point arithmetic execution time cost is prohibitive, so we will transform the math to
375
+   * Floating point arithmetic execution time cost is prohibitive, so we will transform the math to
376 376
    * use fixed point values to be able to evaluate it in realtime. Assuming a maximum of 250000 steps
377 377
    * per second (driver pulses should at least be 2µS hi/2µS lo), and allocating 2 bits to avoid
378 378
    * overflows on the evaluation of the Bézier curve, means we can use
@@ -383,7 +383,7 @@ void Stepper::set_directions() {
383 383
    *   C:   signed Q24.7 ,            |range = +/- 250000 *10 * 128 = +/- 320000000 = 0x1312D000 | 29 bits + sign
384 384
    *   F:   signed Q24.7 ,            |range = +/- 250000     * 128 =      32000000 = 0x01E84800 | 25 bits + sign
385 385
    *
386
-   *  The trapezoid generator state contains the following information, that we will use to create and evaluate
386
+   * The trapezoid generator state contains the following information, that we will use to create and evaluate
387 387
    * the Bézier curve:
388 388
    *
389 389
    *  blk->step_event_count [TS] = The total count of steps for this movement. (=distance)
@@ -395,7 +395,7 @@ void Stepper::set_directions() {
395 395
    *
396 396
    *  For Any 32bit CPU:
397 397
    *
398
-   *    At the start of each trapezoid, we calculate the coefficients A,B,C,F and Advance [AV], as follows:
398
+   *    At the start of each trapezoid, calculate the coefficients A,B,C,F and Advance [AV], as follows:
399 399
    *
400 400
    *      A =  6*128*(VF - VI) =  768*(VF - VI)
401 401
    *      B = 15*128*(VI - VF) = 1920*(VI - VF)
@@ -403,7 +403,7 @@ void Stepper::set_directions() {
403 403
    *      F =    128*VI        =  128*VI
404 404
    *     AV = (1<<32)/TS      ~= 0xFFFFFFFF / TS (To use ARM UDIV, that is 32 bits) (this is computed at the planner, to offload expensive calculations from the ISR)
405 405
    *
406
-   *   And for each point, we will evaluate the curve with the following sequence:
406
+   *    And for each point, evaluate the curve with the following sequence:
407 407
    *
408 408
    *      void lsrs(uint32_t& d, uint32_t s, int cnt) {
409 409
    *        d = s >> cnt;
@@ -456,10 +456,10 @@ void Stepper::set_directions() {
456 456
    *        return alo;
457 457
    *      }
458 458
    *
459
-   *    This will be rewritten in ARM assembly to get peak performance and will take 43 cycles to execute
459
+   *  This is rewritten in ARM assembly for optimal performance (43 cycles to execute).
460 460
    *
461
-   *  For AVR, we scale precision of coefficients to make it possible to evaluate the Bézier curve in
462
-   *    realtime: Let's reduce precision as much as possible. After some experimentation we found that:
461
+   *  For AVR, the precision of coefficients is scaled so the Bézier curve can be evaluated in real-time:
462
+   *  Let's reduce precision as much as possible. After some experimentation we found that:
463 463
    *
464 464
    *    Assume t and AV with 24 bits is enough
465 465
    *       A =  6*(VF - VI)
@@ -468,9 +468,9 @@ void Stepper::set_directions() {
468 468
    *       F =     VI
469 469
    *      AV = (1<<24)/TS   (this is computed at the planner, to offload expensive calculations from the ISR)
470 470
    *
471
-   *     Instead of storing sign for each coefficient, we will store its absolute value,
471
+   *    Instead of storing sign for each coefficient, we will store its absolute value,
472 472
    *    and flag the sign of the A coefficient, so we can save to store the sign bit.
473
-   *     It always holds that sign(A) = - sign(B) = sign(C)
473
+   *    It always holds that sign(A) = - sign(B) = sign(C)
474 474
    *
475 475
    *     So, the resulting range of the coefficients are:
476 476
    *
@@ -480,7 +480,7 @@ void Stepper::set_directions() {
480 480
    *       C:   signed Q24 , range = 250000 *10 = 2500000 = 0x1312D0 | 21 bits
481 481
    *       F:   signed Q24 , range = 250000     =  250000 = 0x0ED090 | 20 bits
482 482
    *
483
-   *    And for each curve, we estimate its coefficients with:
483
+   *    And for each curve, estimate its coefficients with:
484 484
    *
485 485
    *      void _calc_bezier_curve_coeffs(int32_t v0, int32_t v1, uint32_t av) {
486 486
    *       // Calculate the Bézier coefficients
@@ -499,7 +499,7 @@ void Stepper::set_directions() {
499 499
    *       bezier_F = v0;
500 500
    *      }
501 501
    *
502
-   *    And for each point, we will evaluate the curve with the following sequence:
502
+   *    And for each point, evaluate the curve with the following sequence:
503 503
    *
504 504
    *      // unsigned multiplication of 24 bits x 24bits, return upper 16 bits
505 505
    *      void umul24x24to16hi(uint16_t& r, uint24_t op1, uint24_t op2) {
@@ -549,9 +549,8 @@ void Stepper::set_directions() {
549 549
    *        }
550 550
    *        return acc;
551 551
    *      }
552
-   *    Those functions will be translated into assembler to get peak performance. coefficient calculations takes 70 cycles,
553
-   *    Bezier point evaluation takes 150 cycles
554
-   *
552
+   *    These functions are translated to assembler for optimal performance.
553
+   *    Coefficient calculation takes 70 cycles. Bezier point evaluation takes 150 cycles.
555 554
    */
556 555
 
557 556
   #ifdef __AVR__

Loading…
Cancel
Save