diff --git a/clock.c b/clock.c index 80ee617..f2ae3e4 100644 --- a/clock.c +++ b/clock.c @@ -42,6 +42,7 @@ void clock_250ms() { ifclock(clock_flag_1s) { if (DEBUG_POSITION && (debug_flags & DEBUG_POSITION)) { // current position + update_current_position(); sersendf_P(PSTR("Pos: %ld,%ld,%ld,%ld,%lu\n"), current_position.X, current_position.Y, current_position.Z, current_position.E, current_position.F); // target position @@ -75,7 +76,5 @@ void clock_10ms() { ifclock(clock_flag_250ms) { clock_250ms(); } - - update_position(); } diff --git a/dda.c b/dda.c index 827521b..e012e24 100644 --- a/dda.c +++ b/dda.c @@ -169,7 +169,7 @@ const uint8_t msbloc (uint32_t v) { */ void dda_init(void) { // set up default feedrate - current_position.F = startpoint.F = next_target.target.F = SEARCH_FEEDRATE_Z; + startpoint.F = next_target.target.F = SEARCH_FEEDRATE_Z; #ifdef ACCELERATION_RAMPING move_state.n = 1; @@ -392,12 +392,7 @@ void dda_create(DDA *dda, TARGET *target) { */ void dda_start(DDA *dda) { // called from interrupt context: keep it simple! - if (dda->nullmove) { - // just change speed? - current_position.F = dda->endpoint.F; - // keep dda->live = 0 - } - else { + if ( ! dda->nullmove) { // get ready to go steptimeout = 0; if (dda->z_delta) @@ -435,6 +430,9 @@ void dda_start(DDA *dda) { setTimer(dda->c >> 8); #endif } + // else just a speed change, keep dda->live = 0 + + current_position.F = dda->endpoint.F; } /*! STEP @@ -648,13 +646,6 @@ void dda_step(DDA *dda) { } else if (move_state.x_steps == 0 && move_state.y_steps == 0 && move_state.z_steps == 0 && move_state.e_steps == 0) { dda->live = 0; - // if E is relative reset it - #ifndef E_ABSOLUTE - current_position.E = 0; - #endif - // linear acceleration code doesn't alter F during a move, so we must update it here - // in theory, we *could* update F every step, but that would require a divide in interrupt context which should be avoided if at all possible - current_position.F = dda->endpoint.F; #ifdef DC_EXTRUDER heater_set(DC_EXTRUDER, 0); #endif @@ -683,7 +674,7 @@ void dda_step(DDA *dda) { } /// update global current_position struct -void update_position() { +void update_current_position() { DDA *dda = &movebuffer[mb_tail]; if (dda->live == 0) @@ -712,4 +703,6 @@ void update_position() { else current_position.E = dda->endpoint.E + move_state.e_steps; #endif + + // current_position.F is updated in dda_start() } diff --git a/dda.h b/dda.h index 41adbd4..0e8d056 100644 --- a/dda.h +++ b/dda.h @@ -165,6 +165,6 @@ void dda_start(DDA *dda) __attribute__ ((hot)); void dda_step(DDA *dda) __attribute__ ((hot)); // update current_position -void update_position(void); +void update_current_position(void); #endif /* _DDA_H */ diff --git a/dda_queue.c b/dda_queue.c index dc868ac..4d78bca 100644 --- a/dda_queue.c +++ b/dda_queue.c @@ -191,7 +191,7 @@ void print_queue() { } /// dump queue for emergency stop. -/// \todo effect on startpoint/current_position is undefined! +/// \todo effect on startpoint is undefined! void queue_flush() { // Since the timer interrupt is disabled before this function // is called it is not strictly necessary to write the variables diff --git a/gcode_process.c b/gcode_process.c index 326cedb..550153f 100644 --- a/gcode_process.c +++ b/gcode_process.c @@ -278,28 +278,28 @@ void process_gcode_command() { queue_wait(); if (next_target.seen_X) { - startpoint.X = current_position.X = next_target.target.X; + startpoint.X = next_target.target.X; axisSelected = 1; } if (next_target.seen_Y) { - startpoint.Y = current_position.Y = next_target.target.Y; + startpoint.Y = next_target.target.Y; axisSelected = 1; } if (next_target.seen_Z) { - startpoint.Z = current_position.Z = next_target.target.Z; + startpoint.Z = next_target.target.Z; axisSelected = 1; } if (next_target.seen_E) { #ifdef E_ABSOLUTE - startpoint.E = current_position.E = next_target.target.E; + startpoint.E = next_target.target.E; #endif axisSelected = 1; } if (axisSelected == 0) { - startpoint.X = current_position.X = next_target.target.X = - startpoint.Y = current_position.Y = next_target.target.Y = - startpoint.Z = current_position.Z = next_target.target.Z = 0; + startpoint.X = next_target.target.X = + startpoint.Y = next_target.target.Y = + startpoint.Z = next_target.target.Z = 0; } break; @@ -574,6 +574,7 @@ void process_gcode_command() { // wait for all moves to complete queue_wait(); #endif + update_current_position(); sersendf_P(PSTR("X:%lq,Y:%lq,Z:%lq,E:%lq,F:%ld"), current_position.X * ((int32_t) UM_PER_STEP_X), current_position.Y * ((int32_t) UM_PER_STEP_Y), current_position.Z * ((int32_t) UM_PER_STEP_Z), current_position.E * ((int32_t) UM_PER_STEP_E), current_position.F); // newline is sent from gcode_parse after we return break; @@ -740,6 +741,7 @@ void process_gcode_command() { //? --- M250: return current position, end position, queue --- //? Undocumented //? This command is only available in DEBUG builds. + update_current_position(); sersendf_P(PSTR("{X:%ld,Y:%ld,Z:%ld,E:%ld,F:%lu,c:%lu}\t{X:%ld,Y:%ld,Z:%ld,E:%ld,F:%lu,c:%lu}\t"), current_position.X, current_position.Y, current_position.Z, current_position.E, current_position.F, movebuffer[mb_tail].c, movebuffer[mb_tail].endpoint.X, movebuffer[mb_tail].endpoint.Y, movebuffer[mb_tail].endpoint.Z, movebuffer[mb_tail].endpoint.E, movebuffer[mb_tail].endpoint.F, #ifdef ACCELERATION_REPRAP movebuffer[mb_tail].end_c diff --git a/home.c b/home.c index 2014d11..2f11852 100644 --- a/home.c +++ b/home.c @@ -56,10 +56,9 @@ void home_x_negative() { // set X home queue_wait(); // we have to wait here, see G92 #ifdef X_MIN - startpoint.X = current_position.X = next_target.target.X = - (int32_t)(X_MIN * STEPS_PER_MM_X); + startpoint.X = next_target.target.X = (int32_t)(X_MIN * STEPS_PER_MM_X); #else - startpoint.X = current_position.X = next_target.target.X = 0; + startpoint.X = next_target.target.X = 0; #endif #endif } @@ -92,8 +91,7 @@ void home_x_positive() { // set X home queue_wait(); // set position to MAX - startpoint.X = current_position.X = next_target.target.X = - (int32_t)(X_MAX * STEPS_PER_MM_X); + startpoint.X = next_target.target.X = (int32_t)(X_MAX * STEPS_PER_MM_X); // go to zero t.X = 0; t.F = MAXIMUM_FEEDRATE_X; @@ -126,10 +124,9 @@ void home_y_negative() { // set Y home queue_wait(); #ifdef Y_MIN - startpoint.Y = current_position.Y = next_target.target.Y = - (int32_t)(Y_MIN * STEPS_PER_MM_Y); + startpoint.Y = next_target.target.Y = (int32_t)(Y_MIN * STEPS_PER_MM_Y); #else - startpoint.Y = current_position.Y = next_target.target.Y = 0; + startpoint.Y = next_target.target.Y = 0; #endif #endif } @@ -162,8 +159,7 @@ void home_y_positive() { // set Y home queue_wait(); // set position to MAX - startpoint.Y = current_position.Y = next_target.target.Y = - (int32_t)(Y_MAX * STEPS_PER_MM_Y); + startpoint.Y = next_target.target.Y = (int32_t)(Y_MAX * STEPS_PER_MM_Y); // go to zero t.Y = 0; t.F = MAXIMUM_FEEDRATE_Y; @@ -196,10 +192,9 @@ void home_z_negative() { // set Z home queue_wait(); #ifdef Z_MIN - startpoint.Z = current_position.Z = next_target.target.Z = - (int32_t)(Z_MIN * STEPS_PER_MM_Z); + startpoint.Z = next_target.target.Z = (int32_t)(Z_MIN * STEPS_PER_MM_Z); #else - startpoint.Z = current_position.Z = next_target.target.Z = 0; + startpoint.Z = next_target.target.Z = 0; #endif z_disable(); #endif @@ -233,8 +228,7 @@ void home_z_positive() { // set Z home queue_wait(); // set position to MAX - startpoint.Z = current_position.Z = next_target.target.Z = - (int32_t)(Z_MAX * STEPS_PER_MM_Z); + startpoint.Z = next_target.target.Z = (int32_t)(Z_MAX * STEPS_PER_MM_Z); // go to zero t.Z = 0; t.F = MAXIMUM_FEEDRATE_Z;