|
12 | 12 | #include "timer.h"
|
13 | 13 | #include "serial.h"
|
14 | 14 | #include "sermsg.h"
|
| 15 | +#include "gcode_parse.h" |
15 | 16 | #include "dda_queue.h"
|
16 | 17 | #include "debug.h"
|
17 | 18 | #include "sersendf.h"
|
@@ -39,6 +40,10 @@ TARGET startpoint __attribute__ ((__section__ (".bss")));
|
39 | 40 | /// \todo make current_position = real_position (from endstops) + offset from G28 and friends
|
40 | 41 | TARGET current_position __attribute__ ((__section__ (".bss")));
|
41 | 42 |
|
| 43 | +/// \var move_state |
| 44 | +/// \brief numbers for tracking the current state of movement |
| 45 | +MOVE_STATE move_state __attribute__ ((__section__ (".bss"))); |
| 46 | + |
42 | 47 | /*
|
43 | 48 | utility functions
|
44 | 49 | */
|
@@ -160,6 +165,17 @@ const uint8_t msbloc (uint32_t v) {
|
160 | 165 | return 0;
|
161 | 166 | }
|
162 | 167 |
|
| 168 | +/*! Inititalise DDA movement structures |
| 169 | +*/ |
| 170 | +void dda_init(void) { |
| 171 | + // set up default feedrate |
| 172 | + current_position.F = startpoint.F = next_target.target.F = SEARCH_FEEDRATE_Z; |
| 173 | + |
| 174 | + #ifdef ACCELERATION_RAMPING |
| 175 | + move_state.n = 1; |
| 176 | + #endif |
| 177 | +} |
| 178 | + |
163 | 179 | /*! CREATE a dda given current_position and a target, save to passed location so we can write directly into the queue
|
164 | 180 | \param *dda pointer to a dda_queue entry to overwrite
|
165 | 181 | \param *target the target position of this move
|
@@ -350,10 +366,6 @@ void dda_create(DDA *dda, TARGET *target) {
|
350 | 366 | if (dda->rampup_steps > dda->total_steps / 2)
|
351 | 367 | dda->rampup_steps = dda->total_steps / 2;
|
352 | 368 | dda->rampdown_steps = dda->total_steps - dda->rampup_steps;
|
353 |
| - if (dda->rampup_steps == 0) |
354 |
| - dda->rampup_steps = 1; |
355 |
| - dda->n = 1; // TODO: this ends exactly where the next move starts, |
356 |
| - // so it should go out of dda->... into some state variable |
357 | 369 | #else
|
358 | 370 | dda->c = (move_duration / target->F) << 8;
|
359 | 371 | if (dda->c < c_limit)
|
@@ -524,31 +536,31 @@ void dda_step(DDA *dda) {
|
524 | 536 |
|
525 | 537 | // debug ramping algorithm
|
526 | 538 | //if (dda->step_no == 0) {
|
527 |
| - // sersendf_P(PSTR("\r\nc %lu c_min %lu n %ld"), dda->c, dda->c_min, dda->n); |
| 539 | + // sersendf_P(PSTR("\r\nc %lu c_min %lu n %ld"), dda->c, dda->c_min, move_state.n); |
528 | 540 | //}
|
529 | 541 |
|
530 | 542 | recalc_speed = 0;
|
531 |
| - if (dda->step_no <= dda->rampup_steps) { |
532 |
| - if (dda->n < 0) // wrong ramp direction |
533 |
| - dda->n = -((int32_t)2) - dda->n; |
| 543 | + if (dda->step_no < dda->rampup_steps) { |
| 544 | + if (move_state.n < 0) // wrong ramp direction |
| 545 | + move_state.n = -((int32_t)2) - move_state.n; |
534 | 546 | recalc_speed = 1;
|
535 | 547 | }
|
536 |
| - else if (dda->step_no >= dda->rampdown_steps) { |
537 |
| - if (dda->n > 0) // wrong ramp direction |
538 |
| - dda->n = -((int32_t)2) - dda->n; |
| 548 | + else if (dda->step_no > dda->rampdown_steps) { |
| 549 | + if (move_state.n > 0) // wrong ramp direction |
| 550 | + move_state.n = -((int32_t)2) - move_state.n; |
539 | 551 | recalc_speed = 1;
|
540 | 552 | }
|
541 | 553 | if (recalc_speed) {
|
542 |
| - dda->n += 4; |
| 554 | + move_state.n += 4; |
543 | 555 | // be careful of signedness!
|
544 |
| - dda->c = (int32_t)dda->c - ((int32_t)(dda->c * 2) / dda->n); |
| 556 | + dda->c = (int32_t)dda->c - ((int32_t)(dda->c * 2) / move_state.n); |
545 | 557 | }
|
546 | 558 | dda->step_no++;
|
547 | 559 |
|
548 | 560 | // debug ramping algorithm
|
549 | 561 | // for very low speeds like 10 mm/min, only
|
550 | 562 | //if (dda->step_no % 10 /* 10, 100, ...*/ == 0)
|
551 |
| - // sersendf_P(PSTR("\r\nc %lu c_min %lu n %ld"), dda->c, dda->c_min, dda->n); |
| 563 | + // sersendf_P(PSTR("\r\nc %lu c_min %lu n %ld"), dda->c, dda->c_min, move_state.n); |
552 | 564 | #endif
|
553 | 565 |
|
554 | 566 | // TODO: did_step is obsolete ...
|
|
0 commit comments