From 0773ea752d26a47ce6c1d21c3f2cffc9bfb48126 Mon Sep 17 00:00:00 2001 From: Emanuele Caruso Date: Tue, 17 May 2011 20:30:27 +0200 Subject: [PATCH 01/45] Refactored do_xxx_step() functions in 1 do_step() function. This is the first of a series of commits to refactor Sprinter to use bresenham on all axis. Much of the inspiration comes from ScribbleJ fork. --- Tonokip_Firmware/Tonokip_Firmware.pde | 120 +++++++++++--------------- Tonokip_Firmware/configuration.h | 1 + 2 files changed, 49 insertions(+), 72 deletions(-) diff --git a/Tonokip_Firmware/Tonokip_Firmware.pde b/Tonokip_Firmware/Tonokip_Firmware.pde index e193265..63babc5 100644 --- a/Tonokip_Firmware/Tonokip_Firmware.pde +++ b/Tonokip_Firmware/Tonokip_Firmware.pde @@ -58,7 +58,9 @@ //Stepper Movement Variables bool direction_x, direction_y, direction_z, direction_e; -unsigned long previous_micros = 0, previous_micros_x = 0, previous_micros_y = 0, previous_micros_z = 0, previous_micros_e = 0, previous_millis_heater, previous_millis_bed_heater; +const int STEP_PIN[NUM_AXIS] = {X_STEP_PIN, Y_STEP_PIN, Z_STEP_PIN, E_STEP_PIN}; +long axis_previous_micros[NUM_AXIS]; +unsigned long previous_micros = 0, previous_millis_heater, previous_millis_bed_heater; unsigned long x_steps_to_take, y_steps_to_take, z_steps_to_take, e_steps_to_take; #ifdef RAMP_ACCELERATION unsigned long max_x_interval = 100000000.0 / (min_units_per_second * x_steps_per_unit); @@ -83,7 +85,7 @@ boolean acceleration_enabled = false, accelerating = false; unsigned long interval; float destination_x = 0.0, destination_y = 0.0, destination_z = 0.0, destination_e = 0.0; float current_x = 0.0, current_y = 0.0, current_z = 0.0, current_e = 0.0; -long x_interval, y_interval, z_interval, e_interval; // for speed delay +long axis_interval[NUM_AXIS]; // for speed delay float feedrate = 1500, next_feedrate, z_feedrate, saved_feedrate; float time_for_move; long gcode_N, gcode_LastN; @@ -207,11 +209,9 @@ void setup() for(int i = 0; i < BUFSIZE; i++){ fromsd[i] = false; } + //Initialize Step Pins - if(X_STEP_PIN > -1) pinMode(X_STEP_PIN,OUTPUT); - if(Y_STEP_PIN > -1) pinMode(Y_STEP_PIN,OUTPUT); - if(Z_STEP_PIN > -1) pinMode(Z_STEP_PIN,OUTPUT); - if(E_STEP_PIN > -1) pinMode(E_STEP_PIN,OUTPUT); + for(int i=0; i < NUM_AXIS; i++) if(STEP_PIN[i] > -1) pinMode(STEP_PIN[i],OUTPUT); //Initialize Dir Pins if(X_DIR_PIN > -1) pinMode(X_DIR_PIN,OUTPUT); @@ -900,10 +900,10 @@ inline void prepare_move() time_for_move = max(time_for_move, Z_TIME_FOR_MOVE); if(time_for_move <= 0) time_for_move = max(time_for_move, E_TIME_FOR_MOVE); - if(x_steps_to_take) x_interval = time_for_move / x_steps_to_take * 100; - if(y_steps_to_take) y_interval = time_for_move / y_steps_to_take * 100; - if(z_steps_to_take) z_interval = time_for_move / z_steps_to_take * 100; - if(e_steps_to_take && (x_steps_to_take + y_steps_to_take <= 0) ) e_interval = time_for_move / e_steps_to_take * 100; + if(x_steps_to_take) axis_interval[0] = time_for_move / x_steps_to_take * 100; + if(y_steps_to_take) axis_interval[1] = time_for_move / y_steps_to_take * 100; + if(z_steps_to_take) axis_interval[2] = time_for_move / z_steps_to_take * 100; + if(e_steps_to_take && (x_steps_to_take + y_steps_to_take <= 0) ) axis_interval[3] = time_for_move / e_steps_to_take * 100; //#define DEBUGGING false #if 0 @@ -912,25 +912,25 @@ inline void prepare_move() Serial.print("current_x: "); Serial.println(current_x); Serial.print("x_steps_to_take: "); Serial.println(x_steps_to_take); Serial.print("X_TIME_FOR_MVE: "); Serial.println(X_TIME_FOR_MOVE); - Serial.print("x_interval: "); Serial.println(x_interval); + Serial.print("axis_interval[0]: "); Serial.println(axis_interval[0]); Serial.println(""); Serial.print("destination_y: "); Serial.println(destination_y); Serial.print("current_y: "); Serial.println(current_y); Serial.print("y_steps_to_take: "); Serial.println(y_steps_to_take); Serial.print("Y_TIME_FOR_MVE: "); Serial.println(Y_TIME_FOR_MOVE); - Serial.print("y_interval: "); Serial.println(y_interval); + Serial.print("axis_interval[1]: "); Serial.println(axis_interval[1]); Serial.println(""); Serial.print("destination_z: "); Serial.println(destination_z); Serial.print("current_z: "); Serial.println(current_z); Serial.print("z_steps_to_take: "); Serial.println(z_steps_to_take); Serial.print("Z_TIME_FOR_MVE: "); Serial.println(Z_TIME_FOR_MOVE); - Serial.print("z_interval: "); Serial.println(z_interval); + Serial.print("axis_interval[2]: "); Serial.println(axis_interval[2]); Serial.println(""); Serial.print("destination_e: "); Serial.println(destination_e); Serial.print("current_e: "); Serial.println(current_e); Serial.print("e_steps_to_take: "); Serial.println(e_steps_to_take); Serial.print("E_TIME_FOR_MVE: "); Serial.println(E_TIME_FOR_MOVE); - Serial.print("e_interval: "); Serial.println(e_interval); + Serial.print("axis_interval[3]: "); Serial.println(axis_interval[3]); Serial.println(""); } #endif @@ -961,8 +961,8 @@ void linear_move(unsigned long x_steps_remaining, unsigned long y_steps_remainin //Only enable axis that are moving. If the axis doesn't need to move then it can stay disabled depending on configuration. if(x_steps_remaining) enable_x(); if(y_steps_remaining) enable_y(); - if(z_steps_remaining) { enable_z(); do_z_step(); z_steps_remaining--; } - if(e_steps_remaining) { enable_e(); do_e_step(); e_steps_remaining--; } + if(z_steps_remaining) { enable_z(); do_step(2); z_steps_remaining--; } + if(e_steps_remaining) { enable_e(); do_step(3); e_steps_remaining--; } //Define variables that are needed for the Bresenham algorithm. Please note that Z is not currently included in the Bresenham algorithm. unsigned int delta_x = x_steps_remaining; @@ -991,7 +991,7 @@ void linear_move(unsigned long x_steps_remaining, unsigned long y_steps_remainin //Do some Bresenham calculations depending on which axis will lead it. if(steep_y) { error_x = delta_y / 2; - interval = y_interval; + interval = axis_interval[1]; #ifdef RAMP_ACCELERATION max_interval = max_y_interval; if(e_steps_to_take > 0) steps_per_sqr_second = y_steps_per_sqr_second; @@ -1012,7 +1012,7 @@ void linear_move(unsigned long x_steps_remaining, unsigned long y_steps_remainin steps_to_take = delta_y; } else if (steep_x) { error_y = delta_x / 2; - interval = x_interval; + interval = axis_interval[0]; #ifdef RAMP_ACCELERATION max_interval = max_x_interval; if(e_steps_to_take > 0) steps_per_sqr_second = x_steps_per_sqr_second; @@ -1056,10 +1056,9 @@ void linear_move(unsigned long x_steps_remaining, unsigned long y_steps_remainin #endif unsigned long start_move_micros = micros(); - previous_micros_x = start_move_micros*100; - previous_micros_y = previous_micros_x; - previous_micros_z = previous_micros_x; - previous_micros_e = previous_micros_x; + for(int i = 0; i < NUM_AXIS; i++) { + axis_previous_micros[i] = start_move_micros * 100; + } //move until no more steps remain while(x_steps_remaining + y_steps_remaining + z_steps_remaining + e_steps_remaining > 0) { @@ -1130,15 +1129,15 @@ void linear_move(unsigned long x_steps_remaining, unsigned long y_steps_remainin if(X_MAX_PIN > -1) if(direction_x) if(digitalRead(X_MAX_PIN) != ENDSTOPS_INVERTING) break; if(Y_MAX_PIN > -1) if(direction_y) if(digitalRead(Y_MAX_PIN) != ENDSTOPS_INVERTING) break; if(steep_y) { - timediff = micros() * 100 - previous_micros_y; + timediff = micros() * 100 - axis_previous_micros[1]; while(timediff >= interval && y_steps_remaining > 0) { steps_done++; steps_remaining--; y_steps_remaining--; timediff -= interval; error_x = error_x - delta_x; - do_y_step(); + do_step(1); if(error_x < 0) { - do_x_step(); x_steps_remaining--; + do_step(0); x_steps_remaining--; error_x = error_x + delta_y; } #ifdef RAMP_ACCELERATION @@ -1152,15 +1151,15 @@ void linear_move(unsigned long x_steps_remaining, unsigned long y_steps_remainin #endif } } else if (steep_x) { - timediff=micros() * 100 - previous_micros_x; + timediff=micros() * 100 - axis_previous_micros[0]; while(timediff >= interval && x_steps_remaining>0) { steps_done++; steps_remaining--; x_steps_remaining--; timediff -= interval; error_y = error_y - delta_y; - do_x_step(); + do_step(0); if(error_y < 0) { - do_y_step(); y_steps_remaining--; + do_step(1); y_steps_remaining--; error_y = error_y + delta_x; } #ifdef RAMP_ACCELERATION @@ -1185,39 +1184,39 @@ void linear_move(unsigned long x_steps_remaining, unsigned long y_steps_remainin if(z_steps_remaining) { if(Z_MIN_PIN > -1) if(!direction_z) if(digitalRead(Z_MIN_PIN) != ENDSTOPS_INVERTING) break; if(Z_MAX_PIN > -1) if(direction_z) if(digitalRead(Z_MAX_PIN) != ENDSTOPS_INVERTING) break; - timediff = micros() * 100-previous_micros_z; - while(timediff >= z_interval && z_steps_remaining) { - do_z_step(); + timediff = micros() * 100-axis_previous_micros[2]; + while(timediff >= axis_interval[2] && z_steps_remaining) { + do_step(2); z_steps_remaining--; - timediff -= z_interval; + timediff -= axis_interval[2]; #ifdef STEP_DELAY_RATIO - if(timediff >= z_interval) delayMicroseconds(long_step_delay_ratio * z_interval / 10000); + if(timediff >= axis_interval[2]) delayMicroseconds(long_step_delay_ratio * axis_interval[2] / 10000); #endif #ifdef STEP_DELAY_MICROS - if(timediff >= z_interval) delayMicroseconds(STEP_DELAY_MICROS); + if(timediff >= axis_interval[2]) delayMicroseconds(STEP_DELAY_MICROS); #endif } } //If there are e steps remaining, check if e steps must be taken if(e_steps_remaining){ - if (x_steps_to_take + y_steps_to_take <= 0) timediff = micros()*100 - previous_micros_e; + if (x_steps_to_take + y_steps_to_take <= 0) timediff = micros()*100 - axis_previous_micros[3]; unsigned int final_e_steps_remaining = 0; if (steep_x && x_steps_to_take > 0) final_e_steps_remaining = e_steps_to_take * x_steps_remaining / x_steps_to_take; else if (steep_y && y_steps_to_take > 0) final_e_steps_remaining = e_steps_to_take * y_steps_remaining / y_steps_to_take; //If this move has X or Y steps, let E follow the Bresenham pace - if (final_e_steps_remaining > 0) while(e_steps_remaining > final_e_steps_remaining) { do_e_step(); e_steps_remaining--;} - else if (x_steps_to_take + y_steps_to_take > 0) while(e_steps_remaining) { do_e_step(); e_steps_remaining--;} + if (final_e_steps_remaining > 0) while(e_steps_remaining > final_e_steps_remaining) { do_step(3); e_steps_remaining--;} + else if (x_steps_to_take + y_steps_to_take > 0) while(e_steps_remaining) { do_step(3); e_steps_remaining--;} //Else, normally check if e steps must be taken - else while (timediff >= e_interval && e_steps_remaining) { - do_e_step(); + else while (timediff >= axis_interval[3] && e_steps_remaining) { + do_step(3); e_steps_remaining--; - timediff -= e_interval; + timediff -= axis_interval[3]; #ifdef STEP_DELAY_RATIO - if(timediff >= e_interval) delayMicroseconds(long_step_delay_ratio * e_interval / 10000); + if(timediff >= axis_interval[3]) delayMicroseconds(long_step_delay_ratio * axis_interval[3] / 10000); #endif #ifdef STEP_DELAY_MICROS - if(timediff >= e_interval) delayMicroseconds(STEP_DELAY_MICROS); + if(timediff >= axis_interval[3]) delayMicroseconds(STEP_DELAY_MICROS); #endif } } @@ -1240,36 +1239,13 @@ void linear_move(unsigned long x_steps_remaining, unsigned long y_steps_remainin } -inline void do_x_step() -{ - digitalWrite(X_STEP_PIN, HIGH); - previous_micros_x += interval; - //delayMicroseconds(3); - digitalWrite(X_STEP_PIN, LOW); -} - -inline void do_y_step() -{ - digitalWrite(Y_STEP_PIN, HIGH); - previous_micros_y += interval; - //delayMicroseconds(3); - digitalWrite(Y_STEP_PIN, LOW); -} - -inline void do_z_step() -{ - digitalWrite(Z_STEP_PIN, HIGH); - previous_micros_z += z_interval; - //delayMicroseconds(3); - digitalWrite(Z_STEP_PIN, LOW); -} - -inline void do_e_step() -{ - digitalWrite(E_STEP_PIN, HIGH); - previous_micros_e += e_interval; - //delayMicroseconds(3); - digitalWrite(E_STEP_PIN, LOW); +inline void do_step(int axis) { + digitalWrite(STEP_PIN[axis], HIGH); + //TODO: the following check is ugly and not the best thing to do here, but this will be sorted out more easily when all + // axis will be under Bresenham + if(axis < 2) axis_previous_micros[axis] += interval; + else axis_previous_micros[axis] += axis_interval[axis]; + digitalWrite(STEP_PIN[axis], LOW); } inline void disable_x() { if(X_ENABLE_PIN > -1) digitalWrite(X_ENABLE_PIN,!X_ENABLE_ON); } diff --git a/Tonokip_Firmware/configuration.h b/Tonokip_Firmware/configuration.h index a658412..35c714a 100644 --- a/Tonokip_Firmware/configuration.h +++ b/Tonokip_Firmware/configuration.h @@ -86,6 +86,7 @@ float min_constant_speed_units = 2; // the minimum units of an accelerated move // units are in millimeters or whatever length unit you prefer: inches,football-fields,parsecs etc //Calibration variables +const int NUM_AXIS = 4; // The axis order in all axis related arrays is X, Y, Z, E float x_steps_per_unit = 80.376; float y_steps_per_unit = 80.376; float z_steps_per_unit = 3200/1.25; From ae56481873211746266c2ac93ffa6560f9122efa Mon Sep 17 00:00:00 2001 From: Emanuele Caruso Date: Tue, 17 May 2011 21:39:45 +0200 Subject: [PATCH 02/45] Fixed type of axis_previous_micros array to unsigned long --- Tonokip_Firmware/Tonokip_Firmware.pde | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tonokip_Firmware/Tonokip_Firmware.pde b/Tonokip_Firmware/Tonokip_Firmware.pde index 63babc5..308746a 100644 --- a/Tonokip_Firmware/Tonokip_Firmware.pde +++ b/Tonokip_Firmware/Tonokip_Firmware.pde @@ -59,7 +59,7 @@ //Stepper Movement Variables bool direction_x, direction_y, direction_z, direction_e; const int STEP_PIN[NUM_AXIS] = {X_STEP_PIN, Y_STEP_PIN, Z_STEP_PIN, E_STEP_PIN}; -long axis_previous_micros[NUM_AXIS]; +unsigned long axis_previous_micros[NUM_AXIS]; unsigned long previous_micros = 0, previous_millis_heater, previous_millis_bed_heater; unsigned long x_steps_to_take, y_steps_to_take, z_steps_to_take, e_steps_to_take; #ifdef RAMP_ACCELERATION From 8060d4da56d0dc3928e787537d7b9e0ad4763d6b Mon Sep 17 00:00:00 2001 From: Emanuele Caruso Date: Thu, 19 May 2011 02:33:48 +0200 Subject: [PATCH 03/45] Added possibility to print move time to serial, to help debugging --- Tonokip_Firmware/Tonokip_Firmware.pde | 7 ++++++- Tonokip_Firmware/configuration.h | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Tonokip_Firmware/Tonokip_Firmware.pde b/Tonokip_Firmware/Tonokip_Firmware.pde index 308746a..46a6ca9 100644 --- a/Tonokip_Firmware/Tonokip_Firmware.pde +++ b/Tonokip_Firmware/Tonokip_Firmware.pde @@ -934,8 +934,13 @@ inline void prepare_move() Serial.println(""); } #endif - + #ifdef PRINT_MOVE_TIME + unsigned long startmove = micros(); + #endif linear_move(x_steps_to_take, y_steps_to_take, z_steps_to_take, e_steps_to_take); // make the move + #ifdef PRINT_MOVE_TIME + Serial.println(micros()-startmove); + #endif } void linear_move(unsigned long x_steps_remaining, unsigned long y_steps_remaining, unsigned long z_steps_remaining, unsigned long e_steps_remaining) // make linear move with preset speeds and destinations, see G0 and G1 diff --git a/Tonokip_Firmware/configuration.h b/Tonokip_Firmware/configuration.h index 35c714a..dc6226e 100644 --- a/Tonokip_Firmware/configuration.h +++ b/Tonokip_Firmware/configuration.h @@ -151,6 +151,6 @@ const int Z_MAX_LENGTH = 100; #define BAUDRATE 115200 - +//#define PRINT_MOVE_TIME #endif From 222f2e80820f4e5b8fdc40c3de99008ad2d4649b Mon Sep 17 00:00:00 2001 From: Emanuele Caruso Date: Thu, 19 May 2011 02:56:38 +0200 Subject: [PATCH 04/45] Refactored linear_move() to take an array instead of single axis steps_to_take. This is needed to later integrate N bresenham in --- Tonokip_Firmware/Tonokip_Firmware.pde | 69 ++++++++++++++------------- 1 file changed, 35 insertions(+), 34 deletions(-) diff --git a/Tonokip_Firmware/Tonokip_Firmware.pde b/Tonokip_Firmware/Tonokip_Firmware.pde index 46a6ca9..788db5f 100644 --- a/Tonokip_Firmware/Tonokip_Firmware.pde +++ b/Tonokip_Firmware/Tonokip_Firmware.pde @@ -937,13 +937,14 @@ inline void prepare_move() #ifdef PRINT_MOVE_TIME unsigned long startmove = micros(); #endif - linear_move(x_steps_to_take, y_steps_to_take, z_steps_to_take, e_steps_to_take); // make the move + unsigned long axis_steps_to_take[NUM_AXIS] = {x_steps_to_take, y_steps_to_take, z_steps_to_take, e_steps_to_take}; + linear_move(axis_steps_to_take); // make the move #ifdef PRINT_MOVE_TIME Serial.println(micros()-startmove); #endif } -void linear_move(unsigned long x_steps_remaining, unsigned long y_steps_remaining, unsigned long z_steps_remaining, unsigned long e_steps_remaining) // make linear move with preset speeds and destinations, see G0 and G1 +void linear_move(unsigned long axis_steps_remaining[]) // make linear move with preset speeds and destinations, see G0 and G1 { //Determine direction of movement if (destination_x > current_x) digitalWrite(X_DIR_PIN,!INVERT_X_DIR); @@ -955,26 +956,26 @@ void linear_move(unsigned long x_steps_remaining, unsigned long y_steps_remainin if (destination_e > current_e) digitalWrite(E_DIR_PIN,!INVERT_E_DIR); else digitalWrite(E_DIR_PIN,INVERT_E_DIR); - if(X_MIN_PIN > -1) if(!direction_x) if(digitalRead(X_MIN_PIN) != ENDSTOPS_INVERTING) x_steps_remaining=0; - if(Y_MIN_PIN > -1) if(!direction_y) if(digitalRead(Y_MIN_PIN) != ENDSTOPS_INVERTING) y_steps_remaining=0; - if(Z_MIN_PIN > -1) if(!direction_z) if(digitalRead(Z_MIN_PIN) != ENDSTOPS_INVERTING) z_steps_remaining=0; - if(X_MAX_PIN > -1) if(direction_x) if(digitalRead(X_MAX_PIN) != ENDSTOPS_INVERTING) x_steps_remaining=0; - if(Y_MAX_PIN > -1) if(direction_y) if(digitalRead(Y_MAX_PIN) != ENDSTOPS_INVERTING) y_steps_remaining=0; - if(Z_MAX_PIN > -1) if(direction_z) if(digitalRead(Z_MAX_PIN) != ENDSTOPS_INVERTING) z_steps_remaining=0; + if(X_MIN_PIN > -1) if(!direction_x) if(digitalRead(X_MIN_PIN) != ENDSTOPS_INVERTING) axis_steps_remaining[0]=0; + if(Y_MIN_PIN > -1) if(!direction_y) if(digitalRead(Y_MIN_PIN) != ENDSTOPS_INVERTING) axis_steps_remaining[1]=0; + if(Z_MIN_PIN > -1) if(!direction_z) if(digitalRead(Z_MIN_PIN) != ENDSTOPS_INVERTING) axis_steps_remaining[2]=0; + if(X_MAX_PIN > -1) if(direction_x) if(digitalRead(X_MAX_PIN) != ENDSTOPS_INVERTING) axis_steps_remaining[0]=0; + if(Y_MAX_PIN > -1) if(direction_y) if(digitalRead(Y_MAX_PIN) != ENDSTOPS_INVERTING) axis_steps_remaining[1]=0; + if(Z_MAX_PIN > -1) if(direction_z) if(digitalRead(Z_MAX_PIN) != ENDSTOPS_INVERTING) axis_steps_remaining[2]=0; //Only enable axis that are moving. If the axis doesn't need to move then it can stay disabled depending on configuration. - if(x_steps_remaining) enable_x(); - if(y_steps_remaining) enable_y(); - if(z_steps_remaining) { enable_z(); do_step(2); z_steps_remaining--; } - if(e_steps_remaining) { enable_e(); do_step(3); e_steps_remaining--; } + if(axis_steps_remaining[0]) enable_x(); + if(axis_steps_remaining[1]) enable_y(); + if(axis_steps_remaining[2]) { enable_z(); do_step(2); axis_steps_remaining[2]--; } + if(axis_steps_remaining[3]) { enable_e(); do_step(3); axis_steps_remaining[3]--; } //Define variables that are needed for the Bresenham algorithm. Please note that Z is not currently included in the Bresenham algorithm. - unsigned int delta_x = x_steps_remaining; + unsigned int delta_x = axis_steps_remaining[0]; unsigned long x_interval_nanos; - unsigned int delta_y = y_steps_remaining; + unsigned int delta_y = axis_steps_remaining[1]; unsigned long y_interval_nanos; - unsigned int delta_z = z_steps_remaining; + unsigned int delta_z = axis_steps_remaining[2]; unsigned long z_interval_nanos; boolean steep_y = delta_y > delta_x;// && delta_y > delta_e && delta_y > delta_z; boolean steep_x = delta_x >= delta_y;// && delta_x > delta_e && delta_x > delta_z; @@ -1066,7 +1067,7 @@ void linear_move(unsigned long x_steps_remaining, unsigned long y_steps_remainin } //move until no more steps remain - while(x_steps_remaining + y_steps_remaining + z_steps_remaining + e_steps_remaining > 0) { + while(axis_steps_remaining[0] + axis_steps_remaining[1] + axis_steps_remaining[2] + axis_steps_remaining[3] > 0) { //If more that HEATER_CHECK_INTERVAL ms have passed since previous heating check, adjust temp manage_heater(); manage_inactivity(2); @@ -1128,21 +1129,21 @@ void linear_move(unsigned long x_steps_remaining, unsigned long y_steps_remainin #endif //If there are x or y steps remaining, perform Bresenham algorithm - if(x_steps_remaining || y_steps_remaining) { + if(axis_steps_remaining[0] || axis_steps_remaining[1]) { if(X_MIN_PIN > -1) if(!direction_x) if(digitalRead(X_MIN_PIN) != ENDSTOPS_INVERTING) break; if(Y_MIN_PIN > -1) if(!direction_y) if(digitalRead(Y_MIN_PIN) != ENDSTOPS_INVERTING) break; if(X_MAX_PIN > -1) if(direction_x) if(digitalRead(X_MAX_PIN) != ENDSTOPS_INVERTING) break; if(Y_MAX_PIN > -1) if(direction_y) if(digitalRead(Y_MAX_PIN) != ENDSTOPS_INVERTING) break; if(steep_y) { timediff = micros() * 100 - axis_previous_micros[1]; - while(timediff >= interval && y_steps_remaining > 0) { + while(timediff >= interval && axis_steps_remaining[1] > 0) { steps_done++; steps_remaining--; - y_steps_remaining--; timediff -= interval; + axis_steps_remaining[1]--; timediff -= interval; error_x = error_x - delta_x; do_step(1); if(error_x < 0) { - do_step(0); x_steps_remaining--; + do_step(0); axis_steps_remaining[0]--; error_x = error_x + delta_y; } #ifdef RAMP_ACCELERATION @@ -1157,14 +1158,14 @@ void linear_move(unsigned long x_steps_remaining, unsigned long y_steps_remainin } } else if (steep_x) { timediff=micros() * 100 - axis_previous_micros[0]; - while(timediff >= interval && x_steps_remaining>0) { + while(timediff >= interval && axis_steps_remaining[0]>0) { steps_done++; steps_remaining--; - x_steps_remaining--; timediff -= interval; + axis_steps_remaining[0]--; timediff -= interval; error_y = error_y - delta_y; do_step(0); if(error_y < 0) { - do_step(1); y_steps_remaining--; + do_step(1); axis_steps_remaining[1]--; error_y = error_y + delta_x; } #ifdef RAMP_ACCELERATION @@ -1180,19 +1181,19 @@ void linear_move(unsigned long x_steps_remaining, unsigned long y_steps_remainin } } #ifdef RAMP_ACCELERATION - if((x_steps_remaining>0 || y_steps_remaining>0) && + if((axis_steps_remaining[0]>0 || axis_steps_remaining[1]>0) && steps_to_take > 0 && (steps_remaining == plateau_steps || (steps_done >= steps_to_take / 2 && accelerating && !decelerating))) continue; #endif //If there are z steps remaining, check if z steps must be taken - if(z_steps_remaining) { + if(axis_steps_remaining[2]) { if(Z_MIN_PIN > -1) if(!direction_z) if(digitalRead(Z_MIN_PIN) != ENDSTOPS_INVERTING) break; if(Z_MAX_PIN > -1) if(direction_z) if(digitalRead(Z_MAX_PIN) != ENDSTOPS_INVERTING) break; timediff = micros() * 100-axis_previous_micros[2]; - while(timediff >= axis_interval[2] && z_steps_remaining) { + while(timediff >= axis_interval[2] && axis_steps_remaining[2]) { do_step(2); - z_steps_remaining--; + axis_steps_remaining[2]--; timediff -= axis_interval[2]; #ifdef STEP_DELAY_RATIO if(timediff >= axis_interval[2]) delayMicroseconds(long_step_delay_ratio * axis_interval[2] / 10000); @@ -1204,18 +1205,18 @@ void linear_move(unsigned long x_steps_remaining, unsigned long y_steps_remainin } //If there are e steps remaining, check if e steps must be taken - if(e_steps_remaining){ + if(axis_steps_remaining[3]){ if (x_steps_to_take + y_steps_to_take <= 0) timediff = micros()*100 - axis_previous_micros[3]; unsigned int final_e_steps_remaining = 0; - if (steep_x && x_steps_to_take > 0) final_e_steps_remaining = e_steps_to_take * x_steps_remaining / x_steps_to_take; - else if (steep_y && y_steps_to_take > 0) final_e_steps_remaining = e_steps_to_take * y_steps_remaining / y_steps_to_take; + if (steep_x && x_steps_to_take > 0) final_e_steps_remaining = e_steps_to_take * axis_steps_remaining[0] / x_steps_to_take; + else if (steep_y && y_steps_to_take > 0) final_e_steps_remaining = e_steps_to_take * axis_steps_remaining[1] / y_steps_to_take; //If this move has X or Y steps, let E follow the Bresenham pace - if (final_e_steps_remaining > 0) while(e_steps_remaining > final_e_steps_remaining) { do_step(3); e_steps_remaining--;} - else if (x_steps_to_take + y_steps_to_take > 0) while(e_steps_remaining) { do_step(3); e_steps_remaining--;} + if (final_e_steps_remaining > 0) while(axis_steps_remaining[3] > final_e_steps_remaining) { do_step(3); axis_steps_remaining[3]--;} + else if (x_steps_to_take + y_steps_to_take > 0) while(axis_steps_remaining[3]) { do_step(3); axis_steps_remaining[3]--;} //Else, normally check if e steps must be taken - else while (timediff >= axis_interval[3] && e_steps_remaining) { + else while (timediff >= axis_interval[3] && axis_steps_remaining[3]) { do_step(3); - e_steps_remaining--; + axis_steps_remaining[3]--; timediff -= axis_interval[3]; #ifdef STEP_DELAY_RATIO if(timediff >= axis_interval[3]) delayMicroseconds(long_step_delay_ratio * axis_interval[3] / 10000); From 8b7c5a64c886826146311edc42319807e04b26ab Mon Sep 17 00:00:00 2001 From: Emanuele Caruso Date: Thu, 19 May 2011 03:20:47 +0200 Subject: [PATCH 05/45] Refactored errors and deltas variable into array, needed for N bresenham implementation --- Tonokip_Firmware/Tonokip_Firmware.pde | 45 +++++++++++---------------- 1 file changed, 19 insertions(+), 26 deletions(-) diff --git a/Tonokip_Firmware/Tonokip_Firmware.pde b/Tonokip_Firmware/Tonokip_Firmware.pde index 788db5f..0ac491d 100644 --- a/Tonokip_Firmware/Tonokip_Firmware.pde +++ b/Tonokip_Firmware/Tonokip_Firmware.pde @@ -971,18 +971,11 @@ void linear_move(unsigned long axis_steps_remaining[]) // make linear move with if(axis_steps_remaining[3]) { enable_e(); do_step(3); axis_steps_remaining[3]--; } //Define variables that are needed for the Bresenham algorithm. Please note that Z is not currently included in the Bresenham algorithm. - unsigned int delta_x = axis_steps_remaining[0]; - unsigned long x_interval_nanos; - unsigned int delta_y = axis_steps_remaining[1]; - unsigned long y_interval_nanos; - unsigned int delta_z = axis_steps_remaining[2]; - unsigned long z_interval_nanos; - boolean steep_y = delta_y > delta_x;// && delta_y > delta_e && delta_y > delta_z; - boolean steep_x = delta_x >= delta_y;// && delta_x > delta_e && delta_x > delta_z; - //boolean steep_z = delta_z > delta_x && delta_z > delta_y && delta_z > delta_e; - int error_x; - int error_y; - int error_z; + unsigned int delta[NUM_AXIS] = {axis_steps_remaining[0], axis_steps_remaining[1], axis_steps_remaining[2], axis_steps_remaining[3]}; //TODO: implement a "for" to support N axes + boolean steep_y = delta[1] > delta[0];// && delta[1] > delta[3] && delta[1] > delta[2]; + boolean steep_x = delta[0] >= delta[1];// && delta[0] > delta[3] && delta[0] > delta[2]; + //boolean steep_z = delta[2] > delta[0] && delta[2] > delta[1] && delta[2] > delta[3]; + int axis_error[NUM_AXIS]; #ifdef RAMP_ACCELERATION long max_speed_steps_per_second; long min_speed_steps_per_second; @@ -996,7 +989,7 @@ void linear_move(unsigned long axis_steps_remaining[]) // make linear move with //Do some Bresenham calculations depending on which axis will lead it. if(steep_y) { - error_x = delta_y / 2; + axis_error[0] = delta[1] / 2; interval = axis_interval[1]; #ifdef RAMP_ACCELERATION max_interval = max_y_interval; @@ -1010,14 +1003,14 @@ void linear_move(unsigned long axis_steps_remaining[]) // make linear move with #ifdef EXP_ACCELERATION if(e_steps_to_take > 0) virtual_full_velocity_steps = long_full_velocity_units * y_steps_per_unit /100; else virtual_full_velocity_steps = long_travel_move_full_velocity_units * y_steps_per_unit /100; - full_velocity_steps = min(virtual_full_velocity_steps, (delta_y - y_min_constant_speed_steps) / 2); + full_velocity_steps = min(virtual_full_velocity_steps, (delta[1] - y_min_constant_speed_steps) / 2); max_interval = max_y_interval; min_constant_speed_steps = y_min_constant_speed_steps; #endif - steps_remaining = delta_y; - steps_to_take = delta_y; + steps_remaining = delta[1]; + steps_to_take = delta[1]; } else if (steep_x) { - error_y = delta_x / 2; + axis_error[1] = delta[0] / 2; interval = axis_interval[0]; #ifdef RAMP_ACCELERATION max_interval = max_x_interval; @@ -1031,12 +1024,12 @@ void linear_move(unsigned long axis_steps_remaining[]) // make linear move with #ifdef EXP_ACCELERATION if(e_steps_to_take > 0) virtual_full_velocity_steps = long_full_velocity_units * x_steps_per_unit /100; else virtual_full_velocity_steps = long_travel_move_full_velocity_units * x_steps_per_unit /100; - full_velocity_steps = min(virtual_full_velocity_steps, (delta_x - x_min_constant_speed_steps) / 2); + full_velocity_steps = min(virtual_full_velocity_steps, (delta[0] - x_min_constant_speed_steps) / 2); max_interval = max_x_interval; min_constant_speed_steps = x_min_constant_speed_steps; #endif - steps_remaining = delta_x; - steps_to_take = delta_x; + steps_remaining = delta[0]; + steps_to_take = delta[0]; } unsigned long steps_done = 0; #ifdef RAMP_ACCELERATION @@ -1140,11 +1133,11 @@ void linear_move(unsigned long axis_steps_remaining[]) // make linear move with steps_done++; steps_remaining--; axis_steps_remaining[1]--; timediff -= interval; - error_x = error_x - delta_x; + axis_error[0] = axis_error[0] - delta[0]; do_step(1); - if(error_x < 0) { + if(axis_error[0] < 0) { do_step(0); axis_steps_remaining[0]--; - error_x = error_x + delta_y; + axis_error[0] = axis_error[0] + delta[1]; } #ifdef RAMP_ACCELERATION if (steps_remaining == plateau_steps || (steps_done >= steps_to_take / 2 && accelerating && !decelerating)) break; @@ -1162,11 +1155,11 @@ void linear_move(unsigned long axis_steps_remaining[]) // make linear move with steps_done++; steps_remaining--; axis_steps_remaining[0]--; timediff -= interval; - error_y = error_y - delta_y; + axis_error[1] = axis_error[1] - delta[1]; do_step(0); - if(error_y < 0) { + if(axis_error[1] < 0) { do_step(1); axis_steps_remaining[1]--; - error_y = error_y + delta_x; + axis_error[1] = axis_error[1] + delta[0]; } #ifdef RAMP_ACCELERATION if (steps_remaining == plateau_steps || (steps_done >= steps_to_take / 2 && accelerating && !decelerating)) break; From 6d2fdf16b6f61a9aa7d58509073ce82c8033f65c Mon Sep 17 00:00:00 2001 From: Emanuele Caruso Date: Thu, 19 May 2011 03:50:59 +0200 Subject: [PATCH 06/45] N Bresenham is ready for constant speed, though we still enforce only X and Y use it --- Tonokip_Firmware/Tonokip_Firmware.pde | 81 +++++++++------------------ 1 file changed, 28 insertions(+), 53 deletions(-) diff --git a/Tonokip_Firmware/Tonokip_Firmware.pde b/Tonokip_Firmware/Tonokip_Firmware.pde index 0ac491d..f281e9e 100644 --- a/Tonokip_Firmware/Tonokip_Firmware.pde +++ b/Tonokip_Firmware/Tonokip_Firmware.pde @@ -976,6 +976,9 @@ void linear_move(unsigned long axis_steps_remaining[]) // make linear move with boolean steep_x = delta[0] >= delta[1];// && delta[0] > delta[3] && delta[0] > delta[2]; //boolean steep_z = delta[2] > delta[0] && delta[2] > delta[1] && delta[2] > delta[3]; int axis_error[NUM_AXIS]; + unsigned int primary_axis; + if(steep_x) primary_axis = 0; + else primary_axis = 1; #ifdef RAMP_ACCELERATION long max_speed_steps_per_second; long min_speed_steps_per_second; @@ -984,13 +987,13 @@ void linear_move(unsigned long axis_steps_remaining[]) // make linear move with unsigned long virtual_full_velocity_steps; unsigned long full_velocity_steps; #endif - unsigned long steps_remaining; - unsigned long steps_to_take; - + unsigned long steps_remaining = delta[primary_axis]; + unsigned long steps_to_take = steps_remaining; + for(int i=0; i < NUM_AXIS; i++) if(i != primary_axis) axis_error[i] = delta[primary_axis] / 2; + interval = axis_interval[primary_axis]; + //Do some Bresenham calculations depending on which axis will lead it. if(steep_y) { - axis_error[0] = delta[1] / 2; - interval = axis_interval[1]; #ifdef RAMP_ACCELERATION max_interval = max_y_interval; if(e_steps_to_take > 0) steps_per_sqr_second = y_steps_per_sqr_second; @@ -1007,11 +1010,7 @@ void linear_move(unsigned long axis_steps_remaining[]) // make linear move with max_interval = max_y_interval; min_constant_speed_steps = y_min_constant_speed_steps; #endif - steps_remaining = delta[1]; - steps_to_take = delta[1]; } else if (steep_x) { - axis_error[1] = delta[0] / 2; - interval = axis_interval[0]; #ifdef RAMP_ACCELERATION max_interval = max_x_interval; if(e_steps_to_take > 0) steps_per_sqr_second = x_steps_per_sqr_second; @@ -1028,8 +1027,6 @@ void linear_move(unsigned long axis_steps_remaining[]) // make linear move with max_interval = max_x_interval; min_constant_speed_steps = x_min_constant_speed_steps; #endif - steps_remaining = delta[0]; - steps_to_take = delta[0]; } unsigned long steps_done = 0; #ifdef RAMP_ACCELERATION @@ -1127,50 +1124,28 @@ void linear_move(unsigned long axis_steps_remaining[]) // make linear move with if(Y_MIN_PIN > -1) if(!direction_y) if(digitalRead(Y_MIN_PIN) != ENDSTOPS_INVERTING) break; if(X_MAX_PIN > -1) if(direction_x) if(digitalRead(X_MAX_PIN) != ENDSTOPS_INVERTING) break; if(Y_MAX_PIN > -1) if(direction_y) if(digitalRead(Y_MAX_PIN) != ENDSTOPS_INVERTING) break; - if(steep_y) { - timediff = micros() * 100 - axis_previous_micros[1]; - while(timediff >= interval && axis_steps_remaining[1] > 0) { - steps_done++; - steps_remaining--; - axis_steps_remaining[1]--; timediff -= interval; - axis_error[0] = axis_error[0] - delta[0]; - do_step(1); - if(axis_error[0] < 0) { - do_step(0); axis_steps_remaining[0]--; - axis_error[0] = axis_error[0] + delta[1]; + timediff = micros() * 100 - axis_previous_micros[primary_axis]; + while(timediff >= interval && axis_steps_remaining[primary_axis] > 0) { + steps_done++; + steps_remaining--; + axis_steps_remaining[primary_axis]--; timediff -= interval; + do_step(primary_axis); + for(int i=0; i < 2; i++) if(i != primary_axis) {//TODO change "2" to NUM_AXIS when other axes gets added to bresenham + axis_error[i] = axis_error[i] - delta[i]; + if(axis_error[i] < 0) { + do_step(i); axis_steps_remaining[i]--; + axis_error[i] = axis_error[i] + delta[primary_axis]; } - #ifdef RAMP_ACCELERATION - if (steps_remaining == plateau_steps || (steps_done >= steps_to_take / 2 && accelerating && !decelerating)) break; - #endif - #ifdef STEP_DELAY_RATIO - if(timediff >= interval) delayMicroseconds(long_step_delay_ratio * interval / 10000); - #endif - #ifdef STEP_DELAY_MICROS - if(timediff >= interval) delayMicroseconds(STEP_DELAY_MICROS); - #endif - } - } else if (steep_x) { - timediff=micros() * 100 - axis_previous_micros[0]; - while(timediff >= interval && axis_steps_remaining[0]>0) { - steps_done++; - steps_remaining--; - axis_steps_remaining[0]--; timediff -= interval; - axis_error[1] = axis_error[1] - delta[1]; - do_step(0); - if(axis_error[1] < 0) { - do_step(1); axis_steps_remaining[1]--; - axis_error[1] = axis_error[1] + delta[0]; - } - #ifdef RAMP_ACCELERATION - if (steps_remaining == plateau_steps || (steps_done >= steps_to_take / 2 && accelerating && !decelerating)) break; - #endif - #ifdef STEP_DELAY_RATIO - if(timediff >= interval) delayMicroseconds(long_step_delay_ratio * interval / 10000); - #endif - #ifdef STEP_DELAY_MICROS - if(timediff >= interval) delayMicroseconds(STEP_DELAY_MICROS); - #endif } + #ifdef RAMP_ACCELERATION + if (steps_remaining == plateau_steps || (steps_done >= steps_to_take / 2 && accelerating && !decelerating)) break; + #endif + #ifdef STEP_DELAY_RATIO + if(timediff >= interval) delayMicroseconds(long_step_delay_ratio * interval / 10000); + #endif + #ifdef STEP_DELAY_MICROS + if(timediff >= interval) delayMicroseconds(STEP_DELAY_MICROS); + #endif } } #ifdef RAMP_ACCELERATION From 1b1e060bffc9c79d1783ca6d6d62347fb7230c1b Mon Sep 17 00:00:00 2001 From: Emanuele Caruso Date: Thu, 19 May 2011 04:58:33 +0200 Subject: [PATCH 07/45] Refactored ramp and exp acceleration variables to arrays and changed ramp acceleration math code to be axis generic --- Tonokip_Firmware/Tonokip_Firmware.pde | 66 +++++++++++---------------- 1 file changed, 27 insertions(+), 39 deletions(-) diff --git a/Tonokip_Firmware/Tonokip_Firmware.pde b/Tonokip_Firmware/Tonokip_Firmware.pde index f281e9e..902c0e0 100644 --- a/Tonokip_Firmware/Tonokip_Firmware.pde +++ b/Tonokip_Firmware/Tonokip_Firmware.pde @@ -63,23 +63,19 @@ unsigned long axis_previous_micros[NUM_AXIS]; unsigned long previous_micros = 0, previous_millis_heater, previous_millis_bed_heater; unsigned long x_steps_to_take, y_steps_to_take, z_steps_to_take, e_steps_to_take; #ifdef RAMP_ACCELERATION - unsigned long max_x_interval = 100000000.0 / (min_units_per_second * x_steps_per_unit); - unsigned long max_y_interval = 100000000.0 / (min_units_per_second * y_steps_per_unit); + unsigned long axis_max_interval[] = {100000000.0 / (min_units_per_second * x_steps_per_unit), 100000000.0 / (min_units_per_second * y_steps_per_unit)}; unsigned long max_interval; - unsigned long x_steps_per_sqr_second = max_acceleration_units_per_sq_second * x_steps_per_unit; - unsigned long y_steps_per_sqr_second = max_acceleration_units_per_sq_second * y_steps_per_unit; - unsigned long x_travel_steps_per_sqr_second = max_travel_acceleration_units_per_sq_second * x_steps_per_unit; - unsigned long y_travel_steps_per_sqr_second = max_travel_acceleration_units_per_sq_second * y_steps_per_unit; + unsigned long axis_steps_per_sqr_second[] = {max_acceleration_units_per_sq_second * x_steps_per_unit, max_acceleration_units_per_sq_second * y_steps_per_unit}; + unsigned long axis_travel_steps_per_sqr_second[] = {max_travel_acceleration_units_per_sq_second * x_steps_per_unit, max_travel_acceleration_units_per_sq_second * y_steps_per_unit}; unsigned long steps_per_sqr_second, plateau_steps; #endif #ifdef EXP_ACCELERATION unsigned long long_full_velocity_units = full_velocity_units * 100; unsigned long long_travel_move_full_velocity_units = travel_move_full_velocity_units * 100; - unsigned long max_x_interval = 100000000.0 / (min_units_per_second * x_steps_per_unit); - unsigned long max_y_interval = 100000000.0 / (min_units_per_second * y_steps_per_unit); + unsigned long axis_max_interval[] = {100000000.0 / (min_units_per_second * x_steps_per_unit), 100000000.0 / (min_units_per_second * y_steps_per_unit)}; unsigned long max_interval; - unsigned long x_min_constant_speed_steps = min_constant_speed_units * x_steps_per_unit, - y_min_constant_speed_steps = min_constant_speed_units * y_steps_per_unit, min_constant_speed_steps; + unsigned long axis_min_constant_speed_steps[] = {min_constant_speed_units * x_steps_per_unit, min_constant_speed_units * y_steps_per_unit}; + unsigned long min_constant_speed_steps; #endif boolean acceleration_enabled = false, accelerating = false; unsigned long interval; @@ -778,12 +774,12 @@ inline void process_commands() break; #ifdef RAMP_ACCELERATION case 201: // M201 - if(code_seen('X')) x_steps_per_sqr_second = code_value() * x_steps_per_unit; - if(code_seen('Y')) y_steps_per_sqr_second = code_value() * y_steps_per_unit; + if(code_seen('X')) axis_steps_per_sqr_second[0] = code_value() * x_steps_per_unit; + if(code_seen('Y')) axis_steps_per_sqr_second[1] = code_value() * y_steps_per_unit; break; case 202: // M202 - if(code_seen('X')) x_travel_steps_per_sqr_second = code_value() * x_steps_per_unit; - if(code_seen('Y')) y_travel_steps_per_sqr_second = code_value() * y_steps_per_unit; + if(code_seen('X')) axis_travel_steps_per_sqr_second[0] = code_value() * x_steps_per_unit; + if(code_seen('Y')) axis_travel_steps_per_sqr_second[1] = code_value() * y_steps_per_unit; break; #endif } @@ -971,7 +967,7 @@ void linear_move(unsigned long axis_steps_remaining[]) // make linear move with if(axis_steps_remaining[3]) { enable_e(); do_step(3); axis_steps_remaining[3]--; } //Define variables that are needed for the Bresenham algorithm. Please note that Z is not currently included in the Bresenham algorithm. - unsigned int delta[NUM_AXIS] = {axis_steps_remaining[0], axis_steps_remaining[1], axis_steps_remaining[2], axis_steps_remaining[3]}; //TODO: implement a "for" to support N axes + unsigned int delta[] = {axis_steps_remaining[0], axis_steps_remaining[1], axis_steps_remaining[2], axis_steps_remaining[3]}; //TODO: implement a "for" to support N axes boolean steep_y = delta[1] > delta[0];// && delta[1] > delta[3] && delta[1] > delta[2]; boolean steep_x = delta[0] >= delta[1];// && delta[0] > delta[3] && delta[0] > delta[2]; //boolean steep_z = delta[2] > delta[0] && delta[2] > delta[1] && delta[2] > delta[3]; @@ -992,40 +988,32 @@ void linear_move(unsigned long axis_steps_remaining[]) // make linear move with for(int i=0; i < NUM_AXIS; i++) if(i != primary_axis) axis_error[i] = delta[primary_axis] / 2; interval = axis_interval[primary_axis]; + #ifdef RAMP_ACCELERATION + max_interval = axis_max_interval[primary_axis]; + if(e_steps_to_take > 0) steps_per_sqr_second = axis_steps_per_sqr_second[primary_axis]; + else steps_per_sqr_second = axis_travel_steps_per_sqr_second[primary_axis]; + max_speed_steps_per_second = 100000000 / interval; + min_speed_steps_per_second = 100000000 / max_interval; + float plateau_time = (max_speed_steps_per_second - min_speed_steps_per_second) / (float) steps_per_sqr_second; + plateau_steps = (long) ((steps_per_sqr_second / 2.0 * plateau_time + min_speed_steps_per_second) * plateau_time); + #endif + //Do some Bresenham calculations depending on which axis will lead it. if(steep_y) { - #ifdef RAMP_ACCELERATION - max_interval = max_y_interval; - if(e_steps_to_take > 0) steps_per_sqr_second = y_steps_per_sqr_second; - else steps_per_sqr_second = y_travel_steps_per_sqr_second; - max_speed_steps_per_second = 100000000 / interval; - min_speed_steps_per_second = 100000000 / max_interval; - float plateau_time = (max_speed_steps_per_second - min_speed_steps_per_second) / (float) steps_per_sqr_second; - plateau_steps = (long) ((steps_per_sqr_second / 2.0 * plateau_time + min_speed_steps_per_second) * plateau_time); - #endif #ifdef EXP_ACCELERATION if(e_steps_to_take > 0) virtual_full_velocity_steps = long_full_velocity_units * y_steps_per_unit /100; else virtual_full_velocity_steps = long_travel_move_full_velocity_units * y_steps_per_unit /100; - full_velocity_steps = min(virtual_full_velocity_steps, (delta[1] - y_min_constant_speed_steps) / 2); - max_interval = max_y_interval; - min_constant_speed_steps = y_min_constant_speed_steps; + full_velocity_steps = min(virtual_full_velocity_steps, (delta[1] - axis_min_constant_speed_steps[1]) / 2); + max_interval = axis_max_interval[1]; + min_constant_speed_steps = axis_min_constant_speed_steps[1]; #endif } else if (steep_x) { - #ifdef RAMP_ACCELERATION - max_interval = max_x_interval; - if(e_steps_to_take > 0) steps_per_sqr_second = x_steps_per_sqr_second; - else steps_per_sqr_second = x_travel_steps_per_sqr_second; - max_speed_steps_per_second = 100000000 / interval; - min_speed_steps_per_second = 100000000 / max_interval; - float plateau_time = (max_speed_steps_per_second - min_speed_steps_per_second) / (float) steps_per_sqr_second; - plateau_steps = (long) ((steps_per_sqr_second / 2.0 * plateau_time + min_speed_steps_per_second) * plateau_time); - #endif #ifdef EXP_ACCELERATION if(e_steps_to_take > 0) virtual_full_velocity_steps = long_full_velocity_units * x_steps_per_unit /100; else virtual_full_velocity_steps = long_travel_move_full_velocity_units * x_steps_per_unit /100; - full_velocity_steps = min(virtual_full_velocity_steps, (delta[0] - x_min_constant_speed_steps) / 2); - max_interval = max_x_interval; - min_constant_speed_steps = x_min_constant_speed_steps; + full_velocity_steps = min(virtual_full_velocity_steps, (delta[0] - axis_min_constant_speed_steps[0]) / 2); + max_interval = axis_max_interval[0]; + min_constant_speed_steps = axis_min_constant_speed_steps[0]; #endif } unsigned long steps_done = 0; From 2e6cc78372d0543cce431cb29fe2ac82d89a9cec Mon Sep 17 00:00:00 2001 From: Emanuele Caruso Date: Thu, 19 May 2011 05:36:09 +0200 Subject: [PATCH 08/45] Refactored exp variables to arrays and changed exp acceleration math to be axis generic --- Tonokip_Firmware/Tonokip_Firmware.pde | 36 +++++++++++---------------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/Tonokip_Firmware/Tonokip_Firmware.pde b/Tonokip_Firmware/Tonokip_Firmware.pde index 902c0e0..9d7e0ba 100644 --- a/Tonokip_Firmware/Tonokip_Firmware.pde +++ b/Tonokip_Firmware/Tonokip_Firmware.pde @@ -70,9 +70,11 @@ unsigned long x_steps_to_take, y_steps_to_take, z_steps_to_take, e_steps_to_take unsigned long steps_per_sqr_second, plateau_steps; #endif #ifdef EXP_ACCELERATION - unsigned long long_full_velocity_units = full_velocity_units * 100; - unsigned long long_travel_move_full_velocity_units = travel_move_full_velocity_units * 100; - unsigned long axis_max_interval[] = {100000000.0 / (min_units_per_second * x_steps_per_unit), 100000000.0 / (min_units_per_second * y_steps_per_unit)}; + unsigned long axis_virtual_full_velocity_steps[] = {full_velocity_units * x_steps_per_unit, full_velocity_units * y_steps_per_unit}; + unsigned long axis_travel_virtual_full_velocity_steps[] = {travel_move_full_velocity_units * x_steps_per_unit, + travel_move_full_velocity_units * y_steps_per_unit}; + unsigned long axis_max_interval[] = {100000000.0 / (min_units_per_second * x_steps_per_unit), + 100000000.0 / (min_units_per_second * y_steps_per_unit)}; unsigned long max_interval; unsigned long axis_min_constant_speed_steps[] = {min_constant_speed_units * x_steps_per_unit, min_constant_speed_units * y_steps_per_unit}; unsigned long min_constant_speed_steps; @@ -988,6 +990,7 @@ void linear_move(unsigned long axis_steps_remaining[]) // make linear move with for(int i=0; i < NUM_AXIS; i++) if(i != primary_axis) axis_error[i] = delta[primary_axis] / 2; interval = axis_interval[primary_axis]; + //If acceleration is enabled, do some Bresenham calculations depending on which axis will lead it. #ifdef RAMP_ACCELERATION max_interval = axis_max_interval[primary_axis]; if(e_steps_to_take > 0) steps_per_sqr_second = axis_steps_per_sqr_second[primary_axis]; @@ -997,25 +1000,14 @@ void linear_move(unsigned long axis_steps_remaining[]) // make linear move with float plateau_time = (max_speed_steps_per_second - min_speed_steps_per_second) / (float) steps_per_sqr_second; plateau_steps = (long) ((steps_per_sqr_second / 2.0 * plateau_time + min_speed_steps_per_second) * plateau_time); #endif - - //Do some Bresenham calculations depending on which axis will lead it. - if(steep_y) { - #ifdef EXP_ACCELERATION - if(e_steps_to_take > 0) virtual_full_velocity_steps = long_full_velocity_units * y_steps_per_unit /100; - else virtual_full_velocity_steps = long_travel_move_full_velocity_units * y_steps_per_unit /100; - full_velocity_steps = min(virtual_full_velocity_steps, (delta[1] - axis_min_constant_speed_steps[1]) / 2); - max_interval = axis_max_interval[1]; - min_constant_speed_steps = axis_min_constant_speed_steps[1]; - #endif - } else if (steep_x) { - #ifdef EXP_ACCELERATION - if(e_steps_to_take > 0) virtual_full_velocity_steps = long_full_velocity_units * x_steps_per_unit /100; - else virtual_full_velocity_steps = long_travel_move_full_velocity_units * x_steps_per_unit /100; - full_velocity_steps = min(virtual_full_velocity_steps, (delta[0] - axis_min_constant_speed_steps[0]) / 2); - max_interval = axis_max_interval[0]; - min_constant_speed_steps = axis_min_constant_speed_steps[0]; - #endif - } + #ifdef EXP_ACCELERATION + if(e_steps_to_take > 0) virtual_full_velocity_steps = axis_virtual_full_velocity_steps[primary_axis]; + else virtual_full_velocity_steps = axis_travel_virtual_full_velocity_steps[primary_axis]; + full_velocity_steps = min(virtual_full_velocity_steps, (delta[primary_axis] - axis_min_constant_speed_steps[primary_axis]) / 2); + max_interval = axis_max_interval[primary_axis]; + min_constant_speed_steps = axis_min_constant_speed_steps[primary_axis]; + #endif + unsigned long steps_done = 0; #ifdef RAMP_ACCELERATION plateau_steps *= 1.01; // This is to compensate we use discrete intervals From 7b90a1f0f89f588247051a76d849584aa515cebc Mon Sep 17 00:00:00 2001 From: Emanuele Caruso Date: Thu, 19 May 2011 07:26:51 +0200 Subject: [PATCH 09/45] X and Y axis now have their constant acceleration, and that is taken into account when calculating the leading axis acceleration for the move --- Tonokip_Firmware/Tonokip_Firmware.pde | 18 ++++++++++++------ Tonokip_Firmware/configuration.h | 4 ++-- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/Tonokip_Firmware/Tonokip_Firmware.pde b/Tonokip_Firmware/Tonokip_Firmware.pde index 9d7e0ba..c1e3d17 100644 --- a/Tonokip_Firmware/Tonokip_Firmware.pde +++ b/Tonokip_Firmware/Tonokip_Firmware.pde @@ -65,8 +65,8 @@ unsigned long x_steps_to_take, y_steps_to_take, z_steps_to_take, e_steps_to_take #ifdef RAMP_ACCELERATION unsigned long axis_max_interval[] = {100000000.0 / (min_units_per_second * x_steps_per_unit), 100000000.0 / (min_units_per_second * y_steps_per_unit)}; unsigned long max_interval; - unsigned long axis_steps_per_sqr_second[] = {max_acceleration_units_per_sq_second * x_steps_per_unit, max_acceleration_units_per_sq_second * y_steps_per_unit}; - unsigned long axis_travel_steps_per_sqr_second[] = {max_travel_acceleration_units_per_sq_second * x_steps_per_unit, max_travel_acceleration_units_per_sq_second * y_steps_per_unit}; + unsigned long axis_steps_per_sqr_second[] = {max_acceleration_units_per_sq_second[0] * x_steps_per_unit, max_acceleration_units_per_sq_second[1] * y_steps_per_unit}; + unsigned long axis_travel_steps_per_sqr_second[] = {max_travel_acceleration_units_per_sq_second[0] * x_steps_per_unit, max_travel_acceleration_units_per_sq_second[1] * y_steps_per_unit}; unsigned long steps_per_sqr_second, plateau_steps; #endif #ifdef EXP_ACCELERATION @@ -991,14 +991,20 @@ void linear_move(unsigned long axis_steps_remaining[]) // make linear move with interval = axis_interval[primary_axis]; //If acceleration is enabled, do some Bresenham calculations depending on which axis will lead it. + //NOTE: if later, axis dependent min speed is introduced, we probably must ensure it is respected here... or maybe not #ifdef RAMP_ACCELERATION max_interval = axis_max_interval[primary_axis]; - if(e_steps_to_take > 0) steps_per_sqr_second = axis_steps_per_sqr_second[primary_axis]; - else steps_per_sqr_second = axis_travel_steps_per_sqr_second[primary_axis]; max_speed_steps_per_second = 100000000 / interval; min_speed_steps_per_second = 100000000 / max_interval; - float plateau_time = (max_speed_steps_per_second - min_speed_steps_per_second) / (float) steps_per_sqr_second; - plateau_steps = (long) ((steps_per_sqr_second / 2.0 * plateau_time + min_speed_steps_per_second) * plateau_time); + //Calculate slowest axis plateau time + float slowest_axis_plateau_time = 0; + for(int i=0; i < 2 ; i++) { //TODO: change to NUM_AXIS as axes get added to bresenham + if(e_steps_to_take > 0 && axis_steps_remaining[i] > 0) slowest_axis_plateau_time = max(slowest_axis_plateau_time, (100000000.0 / axis_interval[i] - 100000000.0 / axis_max_interval[i]) / (float) axis_steps_per_sqr_second[i]); + else if(axis_steps_remaining[i] > 0) slowest_axis_plateau_time = max(slowest_axis_plateau_time, (100000000.0 / axis_interval[i] - 100000000.0 / axis_max_interval[i]) / (float) axis_travel_steps_per_sqr_second[i]); + } + //Now we can calculate the new primary axis acceleration, so that the slowest axis max acceleration is not violated + steps_per_sqr_second = (100000000.0 / axis_interval[primary_axis] - 100000000.0 / axis_max_interval[primary_axis]) / slowest_axis_plateau_time; + plateau_steps = (long) ((steps_per_sqr_second / 2.0 * slowest_axis_plateau_time + min_speed_steps_per_second) * slowest_axis_plateau_time); #endif #ifdef EXP_ACCELERATION if(e_steps_to_take > 0) virtual_full_velocity_steps = axis_virtual_full_velocity_steps[primary_axis]; diff --git a/Tonokip_Firmware/configuration.h b/Tonokip_Firmware/configuration.h index dc6226e..004c0d8 100644 --- a/Tonokip_Firmware/configuration.h +++ b/Tonokip_Firmware/configuration.h @@ -25,8 +25,8 @@ //Acceleration settings #ifdef RAMP_ACCELERATION float min_units_per_second = 35.0; // the minimum feedrate -long max_acceleration_units_per_sq_second = 750; // Max acceleration in mm/s^2 for printing moves -long max_travel_acceleration_units_per_sq_second = 1500; // Max acceleration in mm/s^2 for travel moves +long max_acceleration_units_per_sq_second[] = {750,750,100,10000}; // X, Y (Z and E currently not used) max acceleration in mm/s^2 for printing moves +long max_travel_acceleration_units_per_sq_second[] = {1500,1500,100}; // X, Y (Z currently not used) max acceleration in mm/s^2 for travel moves #endif #ifdef EXP_ACCELERATION float full_velocity_units = 10; // the units between minimum and G1 move feedrate From a1e6fe387581b8ad981ecf29f901cc74982762e6 Mon Sep 17 00:00:00 2001 From: Emanuele Caruso Date: Thu, 19 May 2011 15:57:29 +0200 Subject: [PATCH 10/45] Some refactoring in preparation of axis with less start speed constraint check. See next commit for more info. --- Tonokip_Firmware/Tonokip_Firmware.pde | 134 +++++++++++++++++++------- Tonokip_Firmware/configuration.h | 8 +- 2 files changed, 102 insertions(+), 40 deletions(-) diff --git a/Tonokip_Firmware/Tonokip_Firmware.pde b/Tonokip_Firmware/Tonokip_Firmware.pde index c1e3d17..f654ada 100644 --- a/Tonokip_Firmware/Tonokip_Firmware.pde +++ b/Tonokip_Firmware/Tonokip_Firmware.pde @@ -63,20 +63,24 @@ unsigned long axis_previous_micros[NUM_AXIS]; unsigned long previous_micros = 0, previous_millis_heater, previous_millis_bed_heater; unsigned long x_steps_to_take, y_steps_to_take, z_steps_to_take, e_steps_to_take; #ifdef RAMP_ACCELERATION - unsigned long axis_max_interval[] = {100000000.0 / (min_units_per_second * x_steps_per_unit), 100000000.0 / (min_units_per_second * y_steps_per_unit)}; + unsigned int max_start_speed_axis_asc_order[NUM_AXIS]; + unsigned long axis_max_interval[] = {100000000.0 / (max_start_speed_units_per_second[0] * axis_steps_per_unit[0]), + 100000000.0 / (max_start_speed_units_per_second[1] * axis_steps_per_unit[1]), + 100000000.0 / (max_start_speed_units_per_second[2] * axis_steps_per_unit[2]), + 100000000.0 / (max_start_speed_units_per_second[3] * axis_steps_per_unit[3])}; //TODO: refactor all things like this in a function unsigned long max_interval; - unsigned long axis_steps_per_sqr_second[] = {max_acceleration_units_per_sq_second[0] * x_steps_per_unit, max_acceleration_units_per_sq_second[1] * y_steps_per_unit}; - unsigned long axis_travel_steps_per_sqr_second[] = {max_travel_acceleration_units_per_sq_second[0] * x_steps_per_unit, max_travel_acceleration_units_per_sq_second[1] * y_steps_per_unit}; + unsigned long axis_steps_per_sqr_second[] = {max_acceleration_units_per_sq_second[0] * axis_steps_per_unit[0], max_acceleration_units_per_sq_second[1] * axis_steps_per_unit[1]}; + unsigned long axis_travel_steps_per_sqr_second[] = {max_travel_acceleration_units_per_sq_second[0] * axis_steps_per_unit[0], max_travel_acceleration_units_per_sq_second[1] * axis_steps_per_unit[1]}; unsigned long steps_per_sqr_second, plateau_steps; #endif #ifdef EXP_ACCELERATION - unsigned long axis_virtual_full_velocity_steps[] = {full_velocity_units * x_steps_per_unit, full_velocity_units * y_steps_per_unit}; - unsigned long axis_travel_virtual_full_velocity_steps[] = {travel_move_full_velocity_units * x_steps_per_unit, - travel_move_full_velocity_units * y_steps_per_unit}; - unsigned long axis_max_interval[] = {100000000.0 / (min_units_per_second * x_steps_per_unit), - 100000000.0 / (min_units_per_second * y_steps_per_unit)}; + unsigned long axis_virtual_full_velocity_steps[] = {full_velocity_units * axis_steps_per_unit[0], full_velocity_units * axis_steps_per_unit[1]}; + unsigned long axis_travel_virtual_full_velocity_steps[] = {travel_move_full_velocity_units * axis_steps_per_unit[0], + travel_move_full_velocity_units * axis_steps_per_unit[1]}; + unsigned long axis_max_interval[] = {100000000.0 / (max_start_speed_units_per_second[0] * axis_steps_per_unit[0]), + 100000000.0 / (max_start_speed_units_per_second[1] * axis_steps_per_unit[1])}; unsigned long max_interval; - unsigned long axis_min_constant_speed_steps[] = {min_constant_speed_units * x_steps_per_unit, min_constant_speed_units * y_steps_per_unit}; + unsigned long axis_min_constant_speed_steps[] = {min_constant_speed_units * axis_steps_per_unit[0], min_constant_speed_units * axis_steps_per_unit[1]}; unsigned long min_constant_speed_steps; #endif boolean acceleration_enabled = false, accelerating = false; @@ -265,6 +269,36 @@ void setup() initsd(); #endif + + //Sort the axis with ascending max start speed in steps/s. The insertion sort + // algorithm is used, since it's the less expensive in code size. + #ifdef RAMP_ACCELERATION + long temp_max_intervals[NUM_AXIS]; + for(int i=0; i < NUM_AXIS; i++) { + temp_max_intervals[i] = axis_max_interval[i]; + max_start_speed_axis_asc_order[i] = i; + } + for(int i=1; i < NUM_AXIS; i++) { + int j=i-1; + long axis_value = temp_max_intervals[i]; + Serial.print("Axis value: "); Serial.println(axis_value); + while(j >= 0 && temp_max_intervals[j] < axis_value) { + temp_max_intervals[j+1] = temp_max_intervals[j]; + max_start_speed_axis_asc_order[j+1] = max_start_speed_axis_asc_order[j]; + j--; + } + Serial.print("Axis value: "); Serial.println(axis_value); + temp_max_intervals[j+1] = axis_value; + max_start_speed_axis_asc_order[j+1] = i; + } + #ifdef DEBUGGING + Serial.println("New start speed axes order :"); + Serial.println(max_start_speed_axis_asc_order[0]); + Serial.println(max_start_speed_axis_asc_order[1]); + Serial.println(max_start_speed_axis_asc_order[2]); + Serial.println(max_start_speed_axis_asc_order[3]); + #endif + #endif } @@ -480,7 +514,7 @@ inline void process_commands() if((X_MIN_PIN > -1 && X_HOME_DIR==-1) || (X_MAX_PIN > -1 && X_HOME_DIR==1)) { current_x = 0; destination_x = 1.5 * X_MAX_LENGTH * X_HOME_DIR; - feedrate = min_units_per_second * 60; + feedrate = max_start_speed_units_per_second[0] * 60; prepare_move(); current_x = 0; @@ -498,7 +532,7 @@ inline void process_commands() if((Y_MIN_PIN > -1 && Y_HOME_DIR==-1) || (Y_MAX_PIN > -1 && Y_HOME_DIR==1)) { current_y = 0; destination_y = 1.5 * Y_MAX_LENGTH * Y_HOME_DIR; - feedrate = min_units_per_second * 60; + feedrate = max_start_speed_units_per_second[1] * 60; prepare_move(); current_y = 0; @@ -756,10 +790,39 @@ inline void process_commands() max_inactive_time = code_value() * 1000; break; case 92: // M92 - if(code_seen('X')) x_steps_per_unit = code_value(); - if(code_seen('Y')) y_steps_per_unit = code_value(); - if(code_seen('Z')) z_steps_per_unit = code_value(); - if(code_seen('E')) e_steps_per_unit = code_value(); + if(code_seen('X')) axis_steps_per_unit[0] = code_value(); + if(code_seen('Y')) axis_steps_per_unit[1] = code_value(); + if(code_seen('Z')) axis_steps_per_unit[2] = code_value(); + if(code_seen('E')) axis_steps_per_unit[3] = code_value(); + //Update start speed intervals and axis order. TODO: refactor array sorting in + // a function, refactor axis_max_interval[] calculation into a function, as they + // can be used in setup() as well + #ifdef RAMP_ACCELERATION + long temp_max_intervals[NUM_AXIS]; + for(int i=0; i < NUM_AXIS; i++) { + axis_max_interval[i] = 100000000.0 / (max_start_speed_units_per_second[i] * axis_steps_per_unit[i]); + temp_max_intervals[i] = axis_max_interval[i]; + max_start_speed_axis_asc_order[i] = i; + } + for(int i=1; i < NUM_AXIS; i++) { + int j=i-1; + long axis_value = temp_max_intervals[i]; + while(j >= 0 && temp_max_intervals[j] < axis_value) { + temp_max_intervals[j+1] = temp_max_intervals[j]; + max_start_speed_axis_asc_order[j+1] = max_start_speed_axis_asc_order[j]; + j--; + } + temp_max_intervals[j+1] = axis_value; + max_start_speed_axis_asc_order[j+1] = i; + } + #ifdef DEBUGGING + Serial.println("New start speed axes order :"); + Serial.println(max_start_speed_axis_asc_order[0]); + Serial.println(max_start_speed_axis_asc_order[1]); + Serial.println(max_start_speed_axis_asc_order[2]); + Serial.println(max_start_speed_axis_asc_order[3]); + #endif + #endif break; case 115: // M115 Serial.println("FIRMWARE_NAME:Sprinter FIRMWARE_URL:http%%3A/github.com/kliment/Sprinter/ PROTOCOL_VERSION:1.0 MACHINE_TYPE:Mendel EXTRUDER_COUNT:1"); @@ -775,13 +838,14 @@ inline void process_commands() Serial.println(current_e); break; #ifdef RAMP_ACCELERATION + //TODO: update for all axis, use for loop case 201: // M201 - if(code_seen('X')) axis_steps_per_sqr_second[0] = code_value() * x_steps_per_unit; - if(code_seen('Y')) axis_steps_per_sqr_second[1] = code_value() * y_steps_per_unit; + if(code_seen('X')) axis_steps_per_sqr_second[0] = code_value() * axis_steps_per_unit[0]; + if(code_seen('Y')) axis_steps_per_sqr_second[1] = code_value() * axis_steps_per_unit[1]; break; case 202: // M202 - if(code_seen('X')) axis_travel_steps_per_sqr_second[0] = code_value() * x_steps_per_unit; - if(code_seen('Y')) axis_travel_steps_per_sqr_second[1] = code_value() * y_steps_per_unit; + if(code_seen('X')) axis_travel_steps_per_sqr_second[0] = code_value() * axis_steps_per_unit[0]; + if(code_seen('Y')) axis_travel_steps_per_sqr_second[1] = code_value() * axis_steps_per_unit[1]; break; #endif } @@ -865,10 +929,10 @@ inline void prepare_move() ydiff = (destination_y - current_y); zdiff = (destination_z - current_z); ediff = (destination_e - current_e); - x_steps_to_take = abs(xdiff) * x_steps_per_unit; - y_steps_to_take = abs(ydiff) * y_steps_per_unit; - z_steps_to_take = abs(zdiff) * z_steps_per_unit; - e_steps_to_take = abs(ediff) * e_steps_per_unit; + x_steps_to_take = abs(xdiff) * axis_steps_per_unit[0]; + y_steps_to_take = abs(ydiff) * axis_steps_per_unit[1]; + z_steps_to_take = abs(zdiff) * axis_steps_per_unit[2]; + e_steps_to_take = abs(ediff) * axis_steps_per_unit[3]; if(feedrate < 10) feedrate = 10; /* @@ -889,10 +953,10 @@ inline void prepare_move() //int feedz = (60000000 * zdiff) / time_for_move; //if(feedz > maxfeed) */ - #define X_TIME_FOR_MOVE ((float)x_steps_to_take / (x_steps_per_unit*feedrate/60000000)) - #define Y_TIME_FOR_MOVE ((float)y_steps_to_take / (y_steps_per_unit*feedrate/60000000)) - #define Z_TIME_FOR_MOVE ((float)z_steps_to_take / (z_steps_per_unit*z_feedrate/60000000)) - #define E_TIME_FOR_MOVE ((float)e_steps_to_take / (e_steps_per_unit*feedrate/60000000)) + #define X_TIME_FOR_MOVE ((float)x_steps_to_take / (axis_steps_per_unit[0]*feedrate/60000000)) + #define Y_TIME_FOR_MOVE ((float)y_steps_to_take / (axis_steps_per_unit[1]*feedrate/60000000)) + #define Z_TIME_FOR_MOVE ((float)z_steps_to_take / (axis_steps_per_unit[2]*z_feedrate/60000000)) + #define E_TIME_FOR_MOVE ((float)e_steps_to_take / (axis_steps_per_unit[3]*feedrate/60000000)) time_for_move = max(X_TIME_FOR_MOVE, Y_TIME_FOR_MOVE); time_for_move = max(time_for_move, Z_TIME_FOR_MOVE); @@ -1188,14 +1252,14 @@ void linear_move(unsigned long axis_steps_remaining[]) // make linear move with if(DISABLE_E) disable_e(); // Update current position partly based on direction, we probably can combine this with the direction code above... - if (destination_x > current_x) current_x = current_x + x_steps_to_take / x_steps_per_unit; - else current_x = current_x - x_steps_to_take / x_steps_per_unit; - if (destination_y > current_y) current_y = current_y + y_steps_to_take / y_steps_per_unit; - else current_y = current_y - y_steps_to_take / y_steps_per_unit; - if (destination_z > current_z) current_z = current_z + z_steps_to_take / z_steps_per_unit; - else current_z = current_z - z_steps_to_take / z_steps_per_unit; - if (destination_e > current_e) current_e = current_e + e_steps_to_take / e_steps_per_unit; - else current_e = current_e - e_steps_to_take / e_steps_per_unit; + if (destination_x > current_x) current_x = current_x + x_steps_to_take / axis_steps_per_unit[0]; + else current_x = current_x - x_steps_to_take / axis_steps_per_unit[0]; + if (destination_y > current_y) current_y = current_y + y_steps_to_take / axis_steps_per_unit[1]; + else current_y = current_y - y_steps_to_take / axis_steps_per_unit[1]; + if (destination_z > current_z) current_z = current_z + z_steps_to_take / axis_steps_per_unit[2]; + else current_z = current_z - z_steps_to_take / axis_steps_per_unit[2]; + if (destination_e > current_e) current_e = current_e + e_steps_to_take / axis_steps_per_unit[3]; + else current_e = current_e - e_steps_to_take / axis_steps_per_unit[3]; } diff --git a/Tonokip_Firmware/configuration.h b/Tonokip_Firmware/configuration.h index 004c0d8..00bc9a5 100644 --- a/Tonokip_Firmware/configuration.h +++ b/Tonokip_Firmware/configuration.h @@ -24,7 +24,8 @@ //Acceleration settings #ifdef RAMP_ACCELERATION -float min_units_per_second = 35.0; // the minimum feedrate +//X, Y (Z and E currently not used) maximum start speed. E default value is good for skeinforge 40+, for older versions raise it a lot. +float max_start_speed_units_per_second[] = {35.0,35.0,1.0,10.0}; long max_acceleration_units_per_sq_second[] = {750,750,100,10000}; // X, Y (Z and E currently not used) max acceleration in mm/s^2 for printing moves long max_travel_acceleration_units_per_sq_second[] = {1500,1500,100}; // X, Y (Z currently not used) max acceleration in mm/s^2 for travel moves #endif @@ -87,10 +88,7 @@ float min_constant_speed_units = 2; // the minimum units of an accelerated move //Calibration variables const int NUM_AXIS = 4; // The axis order in all axis related arrays is X, Y, Z, E -float x_steps_per_unit = 80.376; -float y_steps_per_unit = 80.376; -float z_steps_per_unit = 3200/1.25; -float e_steps_per_unit = 16; +float axis_steps_per_unit[] = {80.376,80.376,3200/1.25,16}; float max_feedrate = 200000; //mmm, acceleration! float max_z_feedrate = 120; From 05274fd21825f03619711200a95302354b51cf29 Mon Sep 17 00:00:00 2001 From: Emanuele Caruso Date: Thu, 19 May 2011 19:55:27 +0200 Subject: [PATCH 11/45] The start speed of the leading (X or Y) axis is now scaled to the speed of the limiting (X, Y, Z or E) axis in that move based on his start speed --- Tonokip_Firmware/Tonokip_Firmware.pde | 72 +++++++++++++++------------ Tonokip_Firmware/configuration.h | 2 +- 2 files changed, 40 insertions(+), 34 deletions(-) diff --git a/Tonokip_Firmware/Tonokip_Firmware.pde b/Tonokip_Firmware/Tonokip_Firmware.pde index f654ada..767473a 100644 --- a/Tonokip_Firmware/Tonokip_Firmware.pde +++ b/Tonokip_Firmware/Tonokip_Firmware.pde @@ -63,7 +63,6 @@ unsigned long axis_previous_micros[NUM_AXIS]; unsigned long previous_micros = 0, previous_millis_heater, previous_millis_bed_heater; unsigned long x_steps_to_take, y_steps_to_take, z_steps_to_take, e_steps_to_take; #ifdef RAMP_ACCELERATION - unsigned int max_start_speed_axis_asc_order[NUM_AXIS]; unsigned long axis_max_interval[] = {100000000.0 / (max_start_speed_units_per_second[0] * axis_steps_per_unit[0]), 100000000.0 / (max_start_speed_units_per_second[1] * axis_steps_per_unit[1]), 100000000.0 / (max_start_speed_units_per_second[2] * axis_steps_per_unit[2]), @@ -270,6 +269,8 @@ void setup() #endif + +/* //Sort the axis with ascending max start speed in steps/s. The insertion sort // algorithm is used, since it's the less expensive in code size. #ifdef RAMP_ACCELERATION @@ -281,13 +282,11 @@ void setup() for(int i=1; i < NUM_AXIS; i++) { int j=i-1; long axis_value = temp_max_intervals[i]; - Serial.print("Axis value: "); Serial.println(axis_value); while(j >= 0 && temp_max_intervals[j] < axis_value) { temp_max_intervals[j+1] = temp_max_intervals[j]; max_start_speed_axis_asc_order[j+1] = max_start_speed_axis_asc_order[j]; j--; } - Serial.print("Axis value: "); Serial.println(axis_value); temp_max_intervals[j+1] = axis_value; max_start_speed_axis_asc_order[j+1] = i; } @@ -298,7 +297,7 @@ void setup() Serial.println(max_start_speed_axis_asc_order[2]); Serial.println(max_start_speed_axis_asc_order[3]); #endif - #endif + #endif*/ } @@ -794,34 +793,15 @@ inline void process_commands() if(code_seen('Y')) axis_steps_per_unit[1] = code_value(); if(code_seen('Z')) axis_steps_per_unit[2] = code_value(); if(code_seen('E')) axis_steps_per_unit[3] = code_value(); - //Update start speed intervals and axis order. TODO: refactor array sorting in - // a function, refactor axis_max_interval[] calculation into a function, as they - // can be used in setup() as well + + //Update start speed intervals and axis order. TODO: refactor axis_max_interval[] calculation into a function, as it + // should also be used in setup() as well #ifdef RAMP_ACCELERATION long temp_max_intervals[NUM_AXIS]; for(int i=0; i < NUM_AXIS; i++) { - axis_max_interval[i] = 100000000.0 / (max_start_speed_units_per_second[i] * axis_steps_per_unit[i]); - temp_max_intervals[i] = axis_max_interval[i]; - max_start_speed_axis_asc_order[i] = i; + axis_max_interval[i] = 100000000.0 / (max_start_speed_units_per_second[i] * axis_steps_per_unit[i]);//TODO: do this for + // all steps_per_unit related variables } - for(int i=1; i < NUM_AXIS; i++) { - int j=i-1; - long axis_value = temp_max_intervals[i]; - while(j >= 0 && temp_max_intervals[j] < axis_value) { - temp_max_intervals[j+1] = temp_max_intervals[j]; - max_start_speed_axis_asc_order[j+1] = max_start_speed_axis_asc_order[j]; - j--; - } - temp_max_intervals[j+1] = axis_value; - max_start_speed_axis_asc_order[j+1] = i; - } - #ifdef DEBUGGING - Serial.println("New start speed axes order :"); - Serial.println(max_start_speed_axis_asc_order[0]); - Serial.println(max_start_speed_axis_asc_order[1]); - Serial.println(max_start_speed_axis_asc_order[2]); - Serial.println(max_start_speed_axis_asc_order[3]); - #endif #endif break; case 115: // M115 @@ -1027,6 +1007,8 @@ void linear_move(unsigned long axis_steps_remaining[]) // make linear move with //Only enable axis that are moving. If the axis doesn't need to move then it can stay disabled depending on configuration. + // TODO: maybe it's better to refactor into a generic enable(int axis) function, that will probably take more ram, + // but will reduce code size if(axis_steps_remaining[0]) enable_x(); if(axis_steps_remaining[1]) enable_y(); if(axis_steps_remaining[2]) { enable_z(); do_step(2); axis_steps_remaining[2]--; } @@ -1055,19 +1037,43 @@ void linear_move(unsigned long axis_steps_remaining[]) // make linear move with interval = axis_interval[primary_axis]; //If acceleration is enabled, do some Bresenham calculations depending on which axis will lead it. - //NOTE: if later, axis dependent min speed is introduced, we probably must ensure it is respected here... or maybe not #ifdef RAMP_ACCELERATION max_interval = axis_max_interval[primary_axis]; + unsigned long new_axis_max_intervals[NUM_AXIS]; max_speed_steps_per_second = 100000000 / interval; - min_speed_steps_per_second = 100000000 / max_interval; + min_speed_steps_per_second = 100000000 / max_interval; //TODO: can this be deleted? + //Calculate start speeds based on moving axes max start speed constraints. TODO: delete all println + int slowest_start_axis = primary_axis; + unsigned long slowest_start_axis_max_interval = max_interval; + for(int i = 0; i < NUM_AXIS; i++) + if (axis_steps_remaining[i] >0 && i != primary_axis && axis_max_interval[i] * axis_steps_remaining[i] + / axis_steps_remaining[slowest_start_axis] > slowest_start_axis_max_interval) { + slowest_start_axis = i; + slowest_start_axis_max_interval = axis_max_interval[i]; + } + for(int i = 0; i < NUM_AXIS; i++) + if(axis_steps_remaining[i] >0) { + new_axis_max_intervals[i] = slowest_start_axis_max_interval * axis_steps_remaining[i] / axis_steps_remaining[slowest_start_axis]; + //Serial.print("new_axis_max_intervals[i] :"); Serial.println(new_axis_max_intervals[i]); //TODO: delete this println when finished + if(i == primary_axis) { + max_interval = new_axis_max_intervals[i]; + min_speed_steps_per_second = 100000000 / max_interval; + } + } + max_interval = new_axis_max_intervals[primary_axis]; + //Serial.print("Max interval :"); Serial.println(max_interval); //TODO: delete this println when finished //Calculate slowest axis plateau time float slowest_axis_plateau_time = 0; for(int i=0; i < 2 ; i++) { //TODO: change to NUM_AXIS as axes get added to bresenham - if(e_steps_to_take > 0 && axis_steps_remaining[i] > 0) slowest_axis_plateau_time = max(slowest_axis_plateau_time, (100000000.0 / axis_interval[i] - 100000000.0 / axis_max_interval[i]) / (float) axis_steps_per_sqr_second[i]); - else if(axis_steps_remaining[i] > 0) slowest_axis_plateau_time = max(slowest_axis_plateau_time, (100000000.0 / axis_interval[i] - 100000000.0 / axis_max_interval[i]) / (float) axis_travel_steps_per_sqr_second[i]); + if(axis_steps_remaining[i] > 0) { + if(e_steps_to_take > 0 && axis_steps_remaining[i] > 0) slowest_axis_plateau_time = max(slowest_axis_plateau_time, + (100000000.0 / axis_interval[i] - 100000000.0 / new_axis_max_intervals[i]) / (float) axis_steps_per_sqr_second[i]); + else if(axis_steps_remaining[i] > 0) slowest_axis_plateau_time = max(slowest_axis_plateau_time, + (100000000.0 / axis_interval[i] - 100000000.0 / new_axis_max_intervals[i]) / (float) axis_travel_steps_per_sqr_second[i]); + } } //Now we can calculate the new primary axis acceleration, so that the slowest axis max acceleration is not violated - steps_per_sqr_second = (100000000.0 / axis_interval[primary_axis] - 100000000.0 / axis_max_interval[primary_axis]) / slowest_axis_plateau_time; + steps_per_sqr_second = (100000000.0 / axis_interval[primary_axis] - 100000000.0 / new_axis_max_intervals[primary_axis]) / slowest_axis_plateau_time; plateau_steps = (long) ((steps_per_sqr_second / 2.0 * slowest_axis_plateau_time + min_speed_steps_per_second) * slowest_axis_plateau_time); #endif #ifdef EXP_ACCELERATION diff --git a/Tonokip_Firmware/configuration.h b/Tonokip_Firmware/configuration.h index 00bc9a5..81f0e29 100644 --- a/Tonokip_Firmware/configuration.h +++ b/Tonokip_Firmware/configuration.h @@ -24,7 +24,7 @@ //Acceleration settings #ifdef RAMP_ACCELERATION -//X, Y (Z and E currently not used) maximum start speed. E default value is good for skeinforge 40+, for older versions raise it a lot. +//X, Y, Z, E maximum start speed for accelerated moves. E default value is good for skeinforge 40+, for older versions raise it a lot. float max_start_speed_units_per_second[] = {35.0,35.0,1.0,10.0}; long max_acceleration_units_per_sq_second[] = {750,750,100,10000}; // X, Y (Z and E currently not used) max acceleration in mm/s^2 for printing moves long max_travel_acceleration_units_per_sq_second[] = {1500,1500,100}; // X, Y (Z currently not used) max acceleration in mm/s^2 for travel moves From 0cf824857bc05deb36ed0b9b3c52c4b2c9ef673c Mon Sep 17 00:00:00 2001 From: Emanuele Caruso Date: Thu, 19 May 2011 21:52:30 +0200 Subject: [PATCH 12/45] Z now has its own max acceleration, and it is now fully integrated into Bresenham --- Tonokip_Firmware/Tonokip_Firmware.pde | 54 ++++++++++++--------------- Tonokip_Firmware/configuration.h | 14 ++++--- 2 files changed, 31 insertions(+), 37 deletions(-) diff --git a/Tonokip_Firmware/Tonokip_Firmware.pde b/Tonokip_Firmware/Tonokip_Firmware.pde index 767473a..8d14217 100644 --- a/Tonokip_Firmware/Tonokip_Firmware.pde +++ b/Tonokip_Firmware/Tonokip_Firmware.pde @@ -66,10 +66,12 @@ unsigned long x_steps_to_take, y_steps_to_take, z_steps_to_take, e_steps_to_take unsigned long axis_max_interval[] = {100000000.0 / (max_start_speed_units_per_second[0] * axis_steps_per_unit[0]), 100000000.0 / (max_start_speed_units_per_second[1] * axis_steps_per_unit[1]), 100000000.0 / (max_start_speed_units_per_second[2] * axis_steps_per_unit[2]), - 100000000.0 / (max_start_speed_units_per_second[3] * axis_steps_per_unit[3])}; //TODO: refactor all things like this in a function + 100000000.0 / (max_start_speed_units_per_second[3] * axis_steps_per_unit[3])}; //TODO: refactor all things like this in a function, or move to setup() unsigned long max_interval; - unsigned long axis_steps_per_sqr_second[] = {max_acceleration_units_per_sq_second[0] * axis_steps_per_unit[0], max_acceleration_units_per_sq_second[1] * axis_steps_per_unit[1]}; - unsigned long axis_travel_steps_per_sqr_second[] = {max_travel_acceleration_units_per_sq_second[0] * axis_steps_per_unit[0], max_travel_acceleration_units_per_sq_second[1] * axis_steps_per_unit[1]}; + unsigned long axis_steps_per_sqr_second[] = {max_acceleration_units_per_sq_second[0] * axis_steps_per_unit[0], + max_acceleration_units_per_sq_second[1] * axis_steps_per_unit[1], max_acceleration_units_per_sq_second[2] * axis_steps_per_unit[2]}; + unsigned long axis_travel_steps_per_sqr_second[] = {max_travel_acceleration_units_per_sq_second[0] * axis_steps_per_unit[0], + max_travel_acceleration_units_per_sq_second[1] * axis_steps_per_unit[1], max_travel_acceleration_units_per_sq_second[2] * axis_steps_per_unit[2]}; unsigned long steps_per_sqr_second, plateau_steps; #endif #ifdef EXP_ACCELERATION @@ -822,10 +824,12 @@ inline void process_commands() case 201: // M201 if(code_seen('X')) axis_steps_per_sqr_second[0] = code_value() * axis_steps_per_unit[0]; if(code_seen('Y')) axis_steps_per_sqr_second[1] = code_value() * axis_steps_per_unit[1]; + if(code_seen('Z')) axis_steps_per_sqr_second[2] = code_value() * axis_steps_per_unit[2]; break; case 202: // M202 if(code_seen('X')) axis_travel_steps_per_sqr_second[0] = code_value() * axis_steps_per_unit[0]; if(code_seen('Y')) axis_travel_steps_per_sqr_second[1] = code_value() * axis_steps_per_unit[1]; + if(code_seen('Z')) axis_travel_steps_per_sqr_second[2] = code_value() * axis_steps_per_unit[2]; break; #endif } @@ -1011,18 +1015,19 @@ void linear_move(unsigned long axis_steps_remaining[]) // make linear move with // but will reduce code size if(axis_steps_remaining[0]) enable_x(); if(axis_steps_remaining[1]) enable_y(); - if(axis_steps_remaining[2]) { enable_z(); do_step(2); axis_steps_remaining[2]--; } + if(axis_steps_remaining[2]) enable_z(); if(axis_steps_remaining[3]) { enable_e(); do_step(3); axis_steps_remaining[3]--; } //Define variables that are needed for the Bresenham algorithm. Please note that Z is not currently included in the Bresenham algorithm. unsigned int delta[] = {axis_steps_remaining[0], axis_steps_remaining[1], axis_steps_remaining[2], axis_steps_remaining[3]}; //TODO: implement a "for" to support N axes - boolean steep_y = delta[1] > delta[0];// && delta[1] > delta[3] && delta[1] > delta[2]; - boolean steep_x = delta[0] >= delta[1];// && delta[0] > delta[3] && delta[0] > delta[2]; - //boolean steep_z = delta[2] > delta[0] && delta[2] > delta[1] && delta[2] > delta[3]; + boolean steep_y = delta[1] > delta[0] && delta[1] > delta[2];// && delta[1] > delta[3]; + boolean steep_x = delta[0] >= delta[1] && delta[0] > delta[2];// && delta[0] > delta[3]]; + boolean steep_z = delta[2] >= delta[0] && delta[2] >= delta[1]; // && delta[2] > delta[3]; int axis_error[NUM_AXIS]; unsigned int primary_axis; if(steep_x) primary_axis = 0; - else primary_axis = 1; + else if (steep_y) primary_axis = 1; + else primary_axis = 2; #ifdef RAMP_ACCELERATION long max_speed_steps_per_second; long min_speed_steps_per_second; @@ -1064,7 +1069,7 @@ void linear_move(unsigned long axis_steps_remaining[]) // make linear move with //Serial.print("Max interval :"); Serial.println(max_interval); //TODO: delete this println when finished //Calculate slowest axis plateau time float slowest_axis_plateau_time = 0; - for(int i=0; i < 2 ; i++) { //TODO: change to NUM_AXIS as axes get added to bresenham + for(int i=0; i < 3 ; i++) { //TODO: change to NUM_AXIS as axes get added to bresenham if(axis_steps_remaining[i] > 0) { if(e_steps_to_take > 0 && axis_steps_remaining[i] > 0) slowest_axis_plateau_time = max(slowest_axis_plateau_time, (100000000.0 / axis_interval[i] - 100000000.0 / new_axis_max_intervals[i]) / (float) axis_steps_per_sqr_second[i]); @@ -1153,6 +1158,7 @@ void linear_move(unsigned long axis_steps_remaining[]) // make linear move with #endif #ifdef EXP_ACCELERATION //If acceleration is enabled on this move and we are in the acceleration segment, calculate the current interval + // TODO: is this any useful? -> steps_done % steps_acceleration_check == 0 if (acceleration_enabled && steps_done < full_velocity_steps && steps_done / full_velocity_steps < 1 && (steps_done % steps_acceleration_check == 0)) { if(steps_done == 0) { interval = max_interval; @@ -1175,18 +1181,20 @@ void linear_move(unsigned long axis_steps_remaining[]) // make linear move with #endif //If there are x or y steps remaining, perform Bresenham algorithm - if(axis_steps_remaining[0] || axis_steps_remaining[1]) { + if(axis_steps_remaining[0] || axis_steps_remaining[1] || axis_steps_remaining[2]) { if(X_MIN_PIN > -1) if(!direction_x) if(digitalRead(X_MIN_PIN) != ENDSTOPS_INVERTING) break; if(Y_MIN_PIN > -1) if(!direction_y) if(digitalRead(Y_MIN_PIN) != ENDSTOPS_INVERTING) break; if(X_MAX_PIN > -1) if(direction_x) if(digitalRead(X_MAX_PIN) != ENDSTOPS_INVERTING) break; if(Y_MAX_PIN > -1) if(direction_y) if(digitalRead(Y_MAX_PIN) != ENDSTOPS_INVERTING) break; + if(Z_MIN_PIN > -1) if(!direction_z) if(digitalRead(Z_MIN_PIN) != ENDSTOPS_INVERTING) break; + if(Z_MAX_PIN > -1) if(direction_z) if(digitalRead(Z_MAX_PIN) != ENDSTOPS_INVERTING) break; timediff = micros() * 100 - axis_previous_micros[primary_axis]; while(timediff >= interval && axis_steps_remaining[primary_axis] > 0) { steps_done++; steps_remaining--; axis_steps_remaining[primary_axis]--; timediff -= interval; do_step(primary_axis); - for(int i=0; i < 2; i++) if(i != primary_axis) {//TODO change "2" to NUM_AXIS when other axes gets added to bresenham + for(int i=0; i < 3; i++) if(i != primary_axis) {//TODO change "3" to NUM_AXIS when other axes gets added to bresenham axis_error[i] = axis_error[i] - delta[i]; if(axis_error[i] < 0) { do_step(i); axis_steps_remaining[i]--; @@ -1194,6 +1202,7 @@ void linear_move(unsigned long axis_steps_remaining[]) // make linear move with } } #ifdef RAMP_ACCELERATION + //TODO: may this check be dangerous? -> steps_remaining == plateau_steps if (steps_remaining == plateau_steps || (steps_done >= steps_to_take / 2 && accelerating && !decelerating)) break; #endif #ifdef STEP_DELAY_RATIO @@ -1210,33 +1219,16 @@ void linear_move(unsigned long axis_steps_remaining[]) // make linear move with (steps_remaining == plateau_steps || (steps_done >= steps_to_take / 2 && accelerating && !decelerating))) continue; #endif - //If there are z steps remaining, check if z steps must be taken - if(axis_steps_remaining[2]) { - if(Z_MIN_PIN > -1) if(!direction_z) if(digitalRead(Z_MIN_PIN) != ENDSTOPS_INVERTING) break; - if(Z_MAX_PIN > -1) if(direction_z) if(digitalRead(Z_MAX_PIN) != ENDSTOPS_INVERTING) break; - timediff = micros() * 100-axis_previous_micros[2]; - while(timediff >= axis_interval[2] && axis_steps_remaining[2]) { - do_step(2); - axis_steps_remaining[2]--; - timediff -= axis_interval[2]; - #ifdef STEP_DELAY_RATIO - if(timediff >= axis_interval[2]) delayMicroseconds(long_step_delay_ratio * axis_interval[2] / 10000); - #endif - #ifdef STEP_DELAY_MICROS - if(timediff >= axis_interval[2]) delayMicroseconds(STEP_DELAY_MICROS); - #endif - } - } - //If there are e steps remaining, check if e steps must be taken if(axis_steps_remaining[3]){ - if (x_steps_to_take + y_steps_to_take <= 0) timediff = micros()*100 - axis_previous_micros[3]; + if (x_steps_to_take + y_steps_to_take + z_steps_to_take<= 0) timediff = micros()*100 - axis_previous_micros[3]; unsigned int final_e_steps_remaining = 0; if (steep_x && x_steps_to_take > 0) final_e_steps_remaining = e_steps_to_take * axis_steps_remaining[0] / x_steps_to_take; else if (steep_y && y_steps_to_take > 0) final_e_steps_remaining = e_steps_to_take * axis_steps_remaining[1] / y_steps_to_take; + else if (steep_z && z_steps_to_take > 0) final_e_steps_remaining = e_steps_to_take * axis_steps_remaining[2] / z_steps_to_take; //If this move has X or Y steps, let E follow the Bresenham pace if (final_e_steps_remaining > 0) while(axis_steps_remaining[3] > final_e_steps_remaining) { do_step(3); axis_steps_remaining[3]--;} - else if (x_steps_to_take + y_steps_to_take > 0) while(axis_steps_remaining[3]) { do_step(3); axis_steps_remaining[3]--;} + else if (x_steps_to_take + y_steps_to_take + z_steps_to_take > 0) while(axis_steps_remaining[3]) { do_step(3); axis_steps_remaining[3]--;} //Else, normally check if e steps must be taken else while (timediff >= axis_interval[3] && axis_steps_remaining[3]) { do_step(3); diff --git a/Tonokip_Firmware/configuration.h b/Tonokip_Firmware/configuration.h index 81f0e29..f8de2a7 100644 --- a/Tonokip_Firmware/configuration.h +++ b/Tonokip_Firmware/configuration.h @@ -19,15 +19,17 @@ //Comment this to disable ramp acceleration #define RAMP_ACCELERATION 1 -//Uncomment this to enable exponential acceleration +//Uncomment this to enable exponential acceleration. WARNING!! This is not supported in the current version, and will be fixed before +// merging it to the stable branch. +// TODO: fix exp acceleration to correctly perform N bresenham. //#define EXP_ACCELERATION 1 //Acceleration settings #ifdef RAMP_ACCELERATION //X, Y, Z, E maximum start speed for accelerated moves. E default value is good for skeinforge 40+, for older versions raise it a lot. -float max_start_speed_units_per_second[] = {35.0,35.0,1.0,10.0}; -long max_acceleration_units_per_sq_second[] = {750,750,100,10000}; // X, Y (Z and E currently not used) max acceleration in mm/s^2 for printing moves -long max_travel_acceleration_units_per_sq_second[] = {1500,1500,100}; // X, Y (Z currently not used) max acceleration in mm/s^2 for travel moves +float max_start_speed_units_per_second[] = {35.0,35.0,0.2,10.0}; +long max_acceleration_units_per_sq_second[] = {750,750,50,4000}; // X, Y, Z (E currently not used) max acceleration in mm/s^2 for printing moves +long max_travel_acceleration_units_per_sq_second[] = {1500,1500,50}; // X, Y, Z max acceleration in mm/s^2 for travel moves #endif #ifdef EXP_ACCELERATION float full_velocity_units = 10; // the units between minimum and G1 move feedrate @@ -89,8 +91,8 @@ float min_constant_speed_units = 2; // the minimum units of an accelerated move //Calibration variables const int NUM_AXIS = 4; // The axis order in all axis related arrays is X, Y, Z, E float axis_steps_per_unit[] = {80.376,80.376,3200/1.25,16}; -float max_feedrate = 200000; //mmm, acceleration! -float max_z_feedrate = 120; +float max_feedrate = 200000; // mm/min, acceleration! +float max_z_feedrate = 180; // mm/min, acceleration! //float x_steps_per_unit = 10.047; //float y_steps_per_unit = 10.047; From 181df1fe733aca5264c0f63425779c767b37e54e Mon Sep 17 00:00:00 2001 From: Emanuele Caruso Date: Fri, 20 May 2011 10:25:34 +0200 Subject: [PATCH 13/45] All axes are now controlled in Bresenham. Now, also E has its own max acceleration and start speed. Also added some function useful for debugging. --- Tonokip_Firmware/Tonokip_Firmware.pde | 217 ++++++++++++++------------ Tonokip_Firmware/configuration.h | 13 +- 2 files changed, 125 insertions(+), 105 deletions(-) diff --git a/Tonokip_Firmware/Tonokip_Firmware.pde b/Tonokip_Firmware/Tonokip_Firmware.pde index 8d14217..bc65755 100644 --- a/Tonokip_Firmware/Tonokip_Firmware.pde +++ b/Tonokip_Firmware/Tonokip_Firmware.pde @@ -67,11 +67,14 @@ unsigned long x_steps_to_take, y_steps_to_take, z_steps_to_take, e_steps_to_take 100000000.0 / (max_start_speed_units_per_second[1] * axis_steps_per_unit[1]), 100000000.0 / (max_start_speed_units_per_second[2] * axis_steps_per_unit[2]), 100000000.0 / (max_start_speed_units_per_second[3] * axis_steps_per_unit[3])}; //TODO: refactor all things like this in a function, or move to setup() + // in a for loop unsigned long max_interval; unsigned long axis_steps_per_sqr_second[] = {max_acceleration_units_per_sq_second[0] * axis_steps_per_unit[0], - max_acceleration_units_per_sq_second[1] * axis_steps_per_unit[1], max_acceleration_units_per_sq_second[2] * axis_steps_per_unit[2]}; + max_acceleration_units_per_sq_second[1] * axis_steps_per_unit[1], max_acceleration_units_per_sq_second[2] * axis_steps_per_unit[2], + max_acceleration_units_per_sq_second[3] * axis_steps_per_unit[3]}; unsigned long axis_travel_steps_per_sqr_second[] = {max_travel_acceleration_units_per_sq_second[0] * axis_steps_per_unit[0], - max_travel_acceleration_units_per_sq_second[1] * axis_steps_per_unit[1], max_travel_acceleration_units_per_sq_second[2] * axis_steps_per_unit[2]}; + max_travel_acceleration_units_per_sq_second[1] * axis_steps_per_unit[1], max_travel_acceleration_units_per_sq_second[2] * axis_steps_per_unit[2], + max_travel_acceleration_units_per_sq_second[3] * axis_steps_per_unit[3]}; unsigned long steps_per_sqr_second, plateau_steps; #endif #ifdef EXP_ACCELERATION @@ -270,36 +273,6 @@ void setup() initsd(); #endif - - -/* - //Sort the axis with ascending max start speed in steps/s. The insertion sort - // algorithm is used, since it's the less expensive in code size. - #ifdef RAMP_ACCELERATION - long temp_max_intervals[NUM_AXIS]; - for(int i=0; i < NUM_AXIS; i++) { - temp_max_intervals[i] = axis_max_interval[i]; - max_start_speed_axis_asc_order[i] = i; - } - for(int i=1; i < NUM_AXIS; i++) { - int j=i-1; - long axis_value = temp_max_intervals[i]; - while(j >= 0 && temp_max_intervals[j] < axis_value) { - temp_max_intervals[j+1] = temp_max_intervals[j]; - max_start_speed_axis_asc_order[j+1] = max_start_speed_axis_asc_order[j]; - j--; - } - temp_max_intervals[j+1] = axis_value; - max_start_speed_axis_asc_order[j+1] = i; - } - #ifdef DEBUGGING - Serial.println("New start speed axes order :"); - Serial.println(max_start_speed_axis_asc_order[0]); - Serial.println(max_start_speed_axis_asc_order[1]); - Serial.println(max_start_speed_axis_asc_order[2]); - Serial.println(max_start_speed_axis_asc_order[3]); - #endif - #endif*/ } @@ -825,11 +798,13 @@ inline void process_commands() if(code_seen('X')) axis_steps_per_sqr_second[0] = code_value() * axis_steps_per_unit[0]; if(code_seen('Y')) axis_steps_per_sqr_second[1] = code_value() * axis_steps_per_unit[1]; if(code_seen('Z')) axis_steps_per_sqr_second[2] = code_value() * axis_steps_per_unit[2]; + if(code_seen('E')) axis_steps_per_sqr_second[3] = code_value() * axis_steps_per_unit[3]; break; case 202: // M202 if(code_seen('X')) axis_travel_steps_per_sqr_second[0] = code_value() * axis_steps_per_unit[0]; if(code_seen('Y')) axis_travel_steps_per_sqr_second[1] = code_value() * axis_steps_per_unit[1]; if(code_seen('Z')) axis_travel_steps_per_sqr_second[2] = code_value() * axis_steps_per_unit[2]; + if(code_seen('E')) axis_travel_steps_per_sqr_second[3] = code_value() * axis_steps_per_unit[3]; break; #endif } @@ -951,9 +926,7 @@ inline void prepare_move() if(z_steps_to_take) axis_interval[2] = time_for_move / z_steps_to_take * 100; if(e_steps_to_take && (x_steps_to_take + y_steps_to_take <= 0) ) axis_interval[3] = time_for_move / e_steps_to_take * 100; - //#define DEBUGGING false - #if 0 - if(0) { + #ifdef DEBUG_PREPARE_MOVE Serial.print("destination_x: "); Serial.println(destination_x); Serial.print("current_x: "); Serial.println(current_x); Serial.print("x_steps_to_take: "); Serial.println(x_steps_to_take); @@ -978,16 +951,9 @@ inline void prepare_move() Serial.print("E_TIME_FOR_MVE: "); Serial.println(E_TIME_FOR_MOVE); Serial.print("axis_interval[3]: "); Serial.println(axis_interval[3]); Serial.println(""); - } - #endif - #ifdef PRINT_MOVE_TIME - unsigned long startmove = micros(); #endif unsigned long axis_steps_to_take[NUM_AXIS] = {x_steps_to_take, y_steps_to_take, z_steps_to_take, e_steps_to_take}; linear_move(axis_steps_to_take); // make the move - #ifdef PRINT_MOVE_TIME - Serial.println(micros()-startmove); - #endif } void linear_move(unsigned long axis_steps_remaining[]) // make linear move with preset speeds and destinations, see G0 and G1 @@ -1016,38 +982,37 @@ void linear_move(unsigned long axis_steps_remaining[]) // make linear move with if(axis_steps_remaining[0]) enable_x(); if(axis_steps_remaining[1]) enable_y(); if(axis_steps_remaining[2]) enable_z(); - if(axis_steps_remaining[3]) { enable_e(); do_step(3); axis_steps_remaining[3]--; } + if(axis_steps_remaining[3]) enable_e(); //Define variables that are needed for the Bresenham algorithm. Please note that Z is not currently included in the Bresenham algorithm. unsigned int delta[] = {axis_steps_remaining[0], axis_steps_remaining[1], axis_steps_remaining[2], axis_steps_remaining[3]}; //TODO: implement a "for" to support N axes - boolean steep_y = delta[1] > delta[0] && delta[1] > delta[2];// && delta[1] > delta[3]; - boolean steep_x = delta[0] >= delta[1] && delta[0] > delta[2];// && delta[0] > delta[3]]; - boolean steep_z = delta[2] >= delta[0] && delta[2] >= delta[1]; // && delta[2] > delta[3]; int axis_error[NUM_AXIS]; unsigned int primary_axis; - if(steep_x) primary_axis = 0; - else if (steep_y) primary_axis = 1; - else primary_axis = 2; - #ifdef RAMP_ACCELERATION - long max_speed_steps_per_second; - long min_speed_steps_per_second; - #endif - #ifdef EXP_ACCELERATION - unsigned long virtual_full_velocity_steps; - unsigned long full_velocity_steps; - #endif + if(delta[1] > delta[0] && delta[1] > delta[2] && delta[1] > delta[3]) primary_axis = 1; + else if (delta[0] >= delta[1] && delta[0] > delta[2] && delta[0] > delta[3]) primary_axis = 0; + else if (delta[2] >= delta[0] && delta[2] >= delta[1] && delta[2] > delta[3]) primary_axis = 2; + else primary_axis = 3; unsigned long steps_remaining = delta[primary_axis]; unsigned long steps_to_take = steps_remaining; for(int i=0; i < NUM_AXIS; i++) if(i != primary_axis) axis_error[i] = delta[primary_axis] / 2; interval = axis_interval[primary_axis]; + #ifdef DEBUG_BRESENHAM + log_int("_BRESENHAM - Primary axis", primary_axis); + log_int("_BRESENHAM - Primary axis full speed interval", interval); + #endif //If acceleration is enabled, do some Bresenham calculations depending on which axis will lead it. #ifdef RAMP_ACCELERATION + long max_speed_steps_per_second; + long min_speed_steps_per_second; max_interval = axis_max_interval[primary_axis]; + #ifdef DEBUG_RAMP_ACCELERATION + log_ulong_array("_RAMP_ACCELERATION - Teoric step intervals at move start", axis_max_interval, NUM_AXIS); + #endif unsigned long new_axis_max_intervals[NUM_AXIS]; max_speed_steps_per_second = 100000000 / interval; min_speed_steps_per_second = 100000000 / max_interval; //TODO: can this be deleted? - //Calculate start speeds based on moving axes max start speed constraints. TODO: delete all println + //Calculate start speeds based on moving axes max start speed constraints. int slowest_start_axis = primary_axis; unsigned long slowest_start_axis_max_interval = max_interval; for(int i = 0; i < NUM_AXIS; i++) @@ -1059,17 +1024,17 @@ void linear_move(unsigned long axis_steps_remaining[]) // make linear move with for(int i = 0; i < NUM_AXIS; i++) if(axis_steps_remaining[i] >0) { new_axis_max_intervals[i] = slowest_start_axis_max_interval * axis_steps_remaining[i] / axis_steps_remaining[slowest_start_axis]; - //Serial.print("new_axis_max_intervals[i] :"); Serial.println(new_axis_max_intervals[i]); //TODO: delete this println when finished if(i == primary_axis) { max_interval = new_axis_max_intervals[i]; min_speed_steps_per_second = 100000000 / max_interval; } } - max_interval = new_axis_max_intervals[primary_axis]; - //Serial.print("Max interval :"); Serial.println(max_interval); //TODO: delete this println when finished + #ifdef DEBUG_RAMP_ACCELERATION + log_ulong_array("_RAMP_ACCELERATION - Actual step intervals at move start", new_axis_max_intervals, NUM_AXIS); + #endif //Calculate slowest axis plateau time float slowest_axis_plateau_time = 0; - for(int i=0; i < 3 ; i++) { //TODO: change to NUM_AXIS as axes get added to bresenham + for(int i=0; i < NUM_AXIS ; i++) { if(axis_steps_remaining[i] > 0) { if(e_steps_to_take > 0 && axis_steps_remaining[i] > 0) slowest_axis_plateau_time = max(slowest_axis_plateau_time, (100000000.0 / axis_interval[i] - 100000000.0 / new_axis_max_intervals[i]) / (float) axis_steps_per_sqr_second[i]); @@ -1082,6 +1047,8 @@ void linear_move(unsigned long axis_steps_remaining[]) // make linear move with plateau_steps = (long) ((steps_per_sqr_second / 2.0 * slowest_axis_plateau_time + min_speed_steps_per_second) * slowest_axis_plateau_time); #endif #ifdef EXP_ACCELERATION + unsigned long virtual_full_velocity_steps; + unsigned long full_velocity_steps; if(e_steps_to_take > 0) virtual_full_velocity_steps = axis_virtual_full_velocity_steps[primary_axis]; else virtual_full_velocity_steps = axis_travel_virtual_full_velocity_steps[primary_axis]; full_velocity_steps = min(virtual_full_velocity_steps, (delta[primary_axis] - axis_min_constant_speed_steps[primary_axis]) / 2); @@ -1116,6 +1083,10 @@ void linear_move(unsigned long axis_steps_remaining[]) // make linear move with for(int i = 0; i < NUM_AXIS; i++) { axis_previous_micros[i] = start_move_micros * 100; } + + #ifdef DEBUG_MOVE_TIME + unsigned long startmove = micros(); + #endif //move until no more steps remain while(axis_steps_remaining[0] + axis_steps_remaining[1] + axis_steps_remaining[2] + axis_steps_remaining[3] > 0) { @@ -1181,7 +1152,7 @@ void linear_move(unsigned long axis_steps_remaining[]) // make linear move with #endif //If there are x or y steps remaining, perform Bresenham algorithm - if(axis_steps_remaining[0] || axis_steps_remaining[1] || axis_steps_remaining[2]) { + if(axis_steps_remaining[primary_axis]) { if(X_MIN_PIN > -1) if(!direction_x) if(digitalRead(X_MIN_PIN) != ENDSTOPS_INVERTING) break; if(Y_MIN_PIN > -1) if(!direction_y) if(digitalRead(Y_MIN_PIN) != ENDSTOPS_INVERTING) break; if(X_MAX_PIN > -1) if(direction_x) if(digitalRead(X_MAX_PIN) != ENDSTOPS_INVERTING) break; @@ -1193,18 +1164,14 @@ void linear_move(unsigned long axis_steps_remaining[]) // make linear move with steps_done++; steps_remaining--; axis_steps_remaining[primary_axis]--; timediff -= interval; - do_step(primary_axis); - for(int i=0; i < 3; i++) if(i != primary_axis) {//TODO change "3" to NUM_AXIS when other axes gets added to bresenham + do_step_update_micros(primary_axis); + for(int i=0; i < NUM_AXIS; i++) if(i != primary_axis && axis_steps_remaining[i] > 0) { axis_error[i] = axis_error[i] - delta[i]; if(axis_error[i] < 0) { do_step(i); axis_steps_remaining[i]--; axis_error[i] = axis_error[i] + delta[primary_axis]; } } - #ifdef RAMP_ACCELERATION - //TODO: may this check be dangerous? -> steps_remaining == plateau_steps - if (steps_remaining == plateau_steps || (steps_done >= steps_to_take / 2 && accelerating && !decelerating)) break; - #endif #ifdef STEP_DELAY_RATIO if(timediff >= interval) delayMicroseconds(long_step_delay_ratio * interval / 10000); #endif @@ -1213,36 +1180,10 @@ void linear_move(unsigned long axis_steps_remaining[]) // make linear move with #endif } } - #ifdef RAMP_ACCELERATION - if((axis_steps_remaining[0]>0 || axis_steps_remaining[1]>0) && - steps_to_take > 0 && - (steps_remaining == plateau_steps || (steps_done >= steps_to_take / 2 && accelerating && !decelerating))) continue; - #endif - - //If there are e steps remaining, check if e steps must be taken - if(axis_steps_remaining[3]){ - if (x_steps_to_take + y_steps_to_take + z_steps_to_take<= 0) timediff = micros()*100 - axis_previous_micros[3]; - unsigned int final_e_steps_remaining = 0; - if (steep_x && x_steps_to_take > 0) final_e_steps_remaining = e_steps_to_take * axis_steps_remaining[0] / x_steps_to_take; - else if (steep_y && y_steps_to_take > 0) final_e_steps_remaining = e_steps_to_take * axis_steps_remaining[1] / y_steps_to_take; - else if (steep_z && z_steps_to_take > 0) final_e_steps_remaining = e_steps_to_take * axis_steps_remaining[2] / z_steps_to_take; - //If this move has X or Y steps, let E follow the Bresenham pace - if (final_e_steps_remaining > 0) while(axis_steps_remaining[3] > final_e_steps_remaining) { do_step(3); axis_steps_remaining[3]--;} - else if (x_steps_to_take + y_steps_to_take + z_steps_to_take > 0) while(axis_steps_remaining[3]) { do_step(3); axis_steps_remaining[3]--;} - //Else, normally check if e steps must be taken - else while (timediff >= axis_interval[3] && axis_steps_remaining[3]) { - do_step(3); - axis_steps_remaining[3]--; - timediff -= axis_interval[3]; - #ifdef STEP_DELAY_RATIO - if(timediff >= axis_interval[3]) delayMicroseconds(long_step_delay_ratio * axis_interval[3] / 10000); - #endif - #ifdef STEP_DELAY_MICROS - if(timediff >= axis_interval[3]) delayMicroseconds(STEP_DELAY_MICROS); - #endif - } - } } + #ifdef DEBUG_MOVE_TIME + log_ulong("_MOVE_TIME - This move took", micros()-startmove); + #endif if(DISABLE_X) disable_x(); if(DISABLE_Y) disable_y(); @@ -1260,13 +1201,14 @@ void linear_move(unsigned long axis_steps_remaining[]) // make linear move with else current_e = current_e - e_steps_to_take / axis_steps_per_unit[3]; } +inline void do_step_update_micros(int axis) { + digitalWrite(STEP_PIN[axis], HIGH); + axis_previous_micros[axis] += interval; + digitalWrite(STEP_PIN[axis], LOW); +} inline void do_step(int axis) { digitalWrite(STEP_PIN[axis], HIGH); - //TODO: the following check is ugly and not the best thing to do here, but this will be sorted out more easily when all - // axis will be under Bresenham - if(axis < 2) axis_previous_micros[axis] += interval; - else axis_previous_micros[axis] += axis_interval[axis]; digitalWrite(STEP_PIN[axis], LOW); } @@ -1581,3 +1523,74 @@ inline void manage_inactivity(byte debug) { if( (millis()-previous_millis_cmd) > max_inactive_time ) if(max_inactive_time) kill(); if( (millis()-previous_millis_cmd) > stepper_inactive_time ) if(stepper_inactive_time) { disable_x(); disable_y(); disable_z(); disable_e(); } } + +#ifdef DEBUG +void log_message(char* message) { + Serial.println(message); +} + +void log_int(char* message, int value) { + Serial.print("DEBUG"); Serial.print(message); Serial.print(": "); Serial.println(value); +} + +void log_long(char* message, long value) { + Serial.print("DEBUG"); Serial.print(message); Serial.print(": "); Serial.println(value); +} + +void log_float(char* message, float value) { + Serial.print("DEBUG"); Serial.print(message); Serial.print(": "); Serial.println(value); +} + +void log_uint(char* message, unsigned int value) { + Serial.print("DEBUG"); Serial.print(message); Serial.print(": "); Serial.println(value); +} + +void log_ulong(char* message, unsigned long value) { + Serial.print("DEBUG"); Serial.print(message); Serial.print(": "); Serial.println(value); +} + +void log_int_array(char* message, int value[], int array_lenght) { + Serial.print("DEBUG"); Serial.print(message); Serial.print(": {"); + for(int i=0; i < array_lenght; i++){ + Serial.print(value[i]); + if(i != array_lenght-1) Serial.print(", "); + } + Serial.println("}"); +} + +void log_long_array(char* message, long value[], int array_lenght) { + Serial.print("DEBUG"); Serial.print(message); Serial.print(": {"); + for(int i=0; i < array_lenght; i++){ + Serial.print(value[i]); + if(i != array_lenght-1) Serial.print(", "); + } + Serial.println("}"); +} + +void log_float_array(char* message, float value[], int array_lenght) { + Serial.print("DEBUG"); Serial.print(message); Serial.print(": {"); + for(int i=0; i < array_lenght; i++){ + Serial.print(value[i]); + if(i != array_lenght-1) Serial.print(", "); + } + Serial.println("}"); +} + +void log_uint_array(char* message, unsigned int value[], int array_lenght) { + Serial.print("DEBUG"); Serial.print(message); Serial.print(": {"); + for(int i=0; i < array_lenght; i++){ + Serial.print(value[i]); + if(i != array_lenght-1) Serial.print(", "); + } + Serial.println("}"); +} + +void log_ulong_array(char* message, unsigned long value[], int array_lenght) { + Serial.print("DEBUG"); Serial.print(message); Serial.print(": {"); + for(int i=0; i < array_lenght; i++){ + Serial.print(value[i]); + if(i != array_lenght-1) Serial.print(", "); + } + Serial.println("}"); +} +#endif diff --git a/Tonokip_Firmware/configuration.h b/Tonokip_Firmware/configuration.h index f8de2a7..cea0740 100644 --- a/Tonokip_Firmware/configuration.h +++ b/Tonokip_Firmware/configuration.h @@ -26,9 +26,9 @@ //Acceleration settings #ifdef RAMP_ACCELERATION -//X, Y, Z, E maximum start speed for accelerated moves. E default value is good for skeinforge 40+, for older versions raise it a lot. +//X, Y, Z, E maximum start speed for accelerated moves. E default values are good for skeinforge 40+, for older versions raise them a lot. float max_start_speed_units_per_second[] = {35.0,35.0,0.2,10.0}; -long max_acceleration_units_per_sq_second[] = {750,750,50,4000}; // X, Y, Z (E currently not used) max acceleration in mm/s^2 for printing moves +long max_acceleration_units_per_sq_second[] = {750,750,50,4000}; // X, Y, Z and E max acceleration in mm/s^2 for printing moves or retracts long max_travel_acceleration_units_per_sq_second[] = {1500,1500,50}; // X, Y, Z max acceleration in mm/s^2 for travel moves #endif #ifdef EXP_ACCELERATION @@ -151,6 +151,13 @@ const int Z_MAX_LENGTH = 100; #define BAUDRATE 115200 -//#define PRINT_MOVE_TIME +//Uncomment the following line to enable debugging. You can better control debugging below the following line +//#define DEBUG +#ifdef DEBUG + #define DEBUG_PREPARE_MOVE //Enable this to debug prepare_move() function + #define DEBUG_BRESENHAM //Enable this to debug the Bresenham algorithm + #define DEBUG_RAMP_ACCELERATION //Enable this to debug all constant acceleration info + #define DEBUG_MOVE_TIME //Enable this to time each move and print the result +#endif #endif From a89f443eb2b635d67daaa01962561f452f7d8a80 Mon Sep 17 00:00:00 2001 From: Emanuele Caruso Date: Sat, 21 May 2011 01:51:29 +0200 Subject: [PATCH 14/45] Added options that allow to disable heating management during acceleration or during the whole move --- Tonokip_Firmware/Tonokip_Firmware.pde | 16 +++++++++++++--- Tonokip_Firmware/configuration.h | 6 ++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/Tonokip_Firmware/Tonokip_Firmware.pde b/Tonokip_Firmware/Tonokip_Firmware.pde index bc65755..e708910 100644 --- a/Tonokip_Firmware/Tonokip_Firmware.pde +++ b/Tonokip_Firmware/Tonokip_Firmware.pde @@ -1090,9 +1090,19 @@ void linear_move(unsigned long axis_steps_remaining[]) // make linear move with //move until no more steps remain while(axis_steps_remaining[0] + axis_steps_remaining[1] + axis_steps_remaining[2] + axis_steps_remaining[3] > 0) { - //If more that HEATER_CHECK_INTERVAL ms have passed since previous heating check, adjust temp - manage_heater(); - manage_inactivity(2); + #ifdef DISABLE_CHECK_DURING_ACC + if(!accelerating && !decelerating) { + //If more that HEATER_CHECK_INTERVAL ms have passed since previous heating check, adjust temp + manage_heater(); + } + #else + #ifdef DISABLE_CHECK_DURING_MOVE + {} //Do nothing + #else + //If more that HEATER_CHECK_INTERVAL ms have passed since previous heating check, adjust temp + manage_heater(); + #endif + #endif #ifdef RAMP_ACCELERATION //If acceleration is enabled on this move and we are in the acceleration segment, calculate the current interval if (acceleration_enabled && steps_done == 0) { diff --git a/Tonokip_Firmware/configuration.h b/Tonokip_Firmware/configuration.h index cea0740..55e9872 100644 --- a/Tonokip_Firmware/configuration.h +++ b/Tonokip_Firmware/configuration.h @@ -56,6 +56,12 @@ float min_constant_speed_units = 2; // the minimum units of an accelerated move //How often should the heater check for new temp readings, in milliseconds #define HEATER_CHECK_INTERVAL 50 #define BED_CHECK_INTERVAL 5000 +//Uncomment the following line to disable heat management during acceleration +//#define DISABLE_CHECK_DURING_ACC +#ifndef DISABLE_CHECK_DURING_ACC + //Uncomment the following line to disable heat management during the move + //#define DISABLE_CHECK_DURING_MOVE +#endif //Experimental temperature smoothing - only uncomment this if your temp readings are noisy //#define SMOOTHING 1 From 1bbdc1970601efe630db4afc6445886bb942abe3 Mon Sep 17 00:00:00 2001 From: Emanuele Caruso Date: Sun, 22 May 2011 19:52:00 +0200 Subject: [PATCH 15/45] Time for move is now correctly calculated in the XYZ space. Fixed a safety bug that caused heating management not to be performed in case DISABLE_CHECK_DURING_MOVE was enabled. Fixed a bug in the moving axis start speed checking. --- Tonokip_Firmware/Tonokip_Firmware.pde | 328 +++++++++++--------------- Tonokip_Firmware/configuration.h | 6 +- 2 files changed, 147 insertions(+), 187 deletions(-) diff --git a/Tonokip_Firmware/Tonokip_Firmware.pde b/Tonokip_Firmware/Tonokip_Firmware.pde index e708910..f71d6d9 100644 --- a/Tonokip_Firmware/Tonokip_Firmware.pde +++ b/Tonokip_Firmware/Tonokip_Firmware.pde @@ -57,11 +57,12 @@ //Stepper Movement Variables -bool direction_x, direction_y, direction_z, direction_e; +char axis_codes[NUM_AXIS] = {'X', 'Y', 'Z', 'E'}; +bool move_direction[NUM_AXIS]; const int STEP_PIN[NUM_AXIS] = {X_STEP_PIN, Y_STEP_PIN, Z_STEP_PIN, E_STEP_PIN}; unsigned long axis_previous_micros[NUM_AXIS]; unsigned long previous_micros = 0, previous_millis_heater, previous_millis_bed_heater; -unsigned long x_steps_to_take, y_steps_to_take, z_steps_to_take, e_steps_to_take; +unsigned long move_steps_to_take[NUM_AXIS]; #ifdef RAMP_ACCELERATION unsigned long axis_max_interval[] = {100000000.0 / (max_start_speed_units_per_second[0] * axis_steps_per_unit[0]), 100000000.0 / (max_start_speed_units_per_second[1] * axis_steps_per_unit[1]), @@ -89,15 +90,18 @@ unsigned long x_steps_to_take, y_steps_to_take, z_steps_to_take, e_steps_to_take #endif boolean acceleration_enabled = false, accelerating = false; unsigned long interval; -float destination_x = 0.0, destination_y = 0.0, destination_z = 0.0, destination_e = 0.0; -float current_x = 0.0, current_y = 0.0, current_z = 0.0, current_e = 0.0; +float destination[NUM_AXIS] = {0.0, 0.0, 0.0, 0.0}; +float current_position[NUM_AXIS] = {0.0, 0.0, 0.0, 0.0}; long axis_interval[NUM_AXIS]; // for speed delay -float feedrate = 1500, next_feedrate, z_feedrate, saved_feedrate; +float feedrate = 1500, next_feedrate, saved_feedrate; float time_for_move; long gcode_N, gcode_LastN; bool relative_mode = false; //Determines Absolute or Relative Coordinates bool relative_mode_e = false; //Determines Absolute or Relative E Codes while in Absolute Coordinates mode. E is always relative in Relative Coordinates mode. long timediff = 0; +//experimental feedrate calc +float d = 0; +float axis_diff[NUM_AXIS] = {0, 0, 0, 0}; #ifdef STEP_DELAY_RATIO long long_step_delay_ratio = STEP_DELAY_RATIO * 100; #endif @@ -442,9 +446,6 @@ inline bool code_seen(char code) strchr_pointer = strchr(cmdbuffer[bufindr], code); return (strchr_pointer != NULL); //Return True if a character was found } - //experimental feedrate calc -float d = 0; -float xdiff = 0, ydiff = 0, zdiff = 0, ediff = 0; inline void process_commands() { @@ -457,6 +458,9 @@ inline void process_commands() { case 0: // G0 -> G1 case 1: // G1 + #ifdef DISABLE_CHECK_DURING_ACC || DISABLE_CHECK_DURING_MOVE + manage_heater(); + #endif get_coordinates(); // For X Y Z E F prepare_move(); previous_millis_cmd = millis(); @@ -474,68 +478,64 @@ inline void process_commands() break; case 28: //G28 Home all Axis one at a time saved_feedrate = feedrate; - destination_x = 0; - current_x = 0; - destination_y = 0; - current_y = 0; - destination_z = 0; - current_z = 0; - destination_e = 0; - current_e = 0; + for(int i=0; i < NUM_AXIS; i++) { + destination[i] = 0; + current_position[i] = 0; + } feedrate = 0; if((X_MIN_PIN > -1 && X_HOME_DIR==-1) || (X_MAX_PIN > -1 && X_HOME_DIR==1)) { - current_x = 0; - destination_x = 1.5 * X_MAX_LENGTH * X_HOME_DIR; + current_position[0] = 0; + destination[0] = 1.5 * X_MAX_LENGTH * X_HOME_DIR; feedrate = max_start_speed_units_per_second[0] * 60; prepare_move(); - current_x = 0; - destination_x = -1 * X_HOME_DIR; + current_position[0] = 0; + destination[0] = -1 * X_HOME_DIR; prepare_move(); - destination_x = 10 * X_HOME_DIR; + destination[0] = 10 * X_HOME_DIR; prepare_move(); - current_x = 0; - destination_x = 0; + current_position[0] = 0; + destination[0] = 0; feedrate = 0; } if((Y_MIN_PIN > -1 && Y_HOME_DIR==-1) || (Y_MAX_PIN > -1 && Y_HOME_DIR==1)) { - current_y = 0; - destination_y = 1.5 * Y_MAX_LENGTH * Y_HOME_DIR; + current_position[1] = 0; + destination[1] = 1.5 * Y_MAX_LENGTH * Y_HOME_DIR; feedrate = max_start_speed_units_per_second[1] * 60; prepare_move(); - current_y = 0; - destination_y = -1 * Y_HOME_DIR; + current_position[1] = 0; + destination[1] = -1 * Y_HOME_DIR; prepare_move(); - destination_y = 10 * Y_HOME_DIR; + destination[1] = 10 * Y_HOME_DIR; prepare_move(); - current_y = 0; - destination_y = 0; + current_position[1] = 0; + destination[1] = 0; feedrate = 0; } if((Z_MIN_PIN > -1 && Z_HOME_DIR==-1) || (Z_MAX_PIN > -1 && Z_HOME_DIR==1)) { - current_z = 0; - destination_z = 1.5 * Z_MAX_LENGTH * Z_HOME_DIR; - feedrate = max_z_feedrate/2; + current_position[2] = 0; + destination[2] = 1.5 * Z_MAX_LENGTH * Z_HOME_DIR; + feedrate = max_feedrate[2]/2; prepare_move(); - current_z = 0; - destination_z = -1 * Z_HOME_DIR; + current_position[2] = 0; + destination[2] = -1 * Z_HOME_DIR; prepare_move(); - destination_z = 10 * Z_HOME_DIR; + destination[2] = 10 * Z_HOME_DIR; prepare_move(); - current_z = 0; - destination_z = 0; + current_position[2] = 0; + destination[2] = 0; feedrate = 0; } @@ -549,10 +549,9 @@ inline void process_commands() relative_mode = true; break; case 92: // G92 - if(code_seen('X')) current_x = code_value(); - if(code_seen('Y')) current_y = code_value(); - if(code_seen('Z')) current_z = code_value(); - if(code_seen('E')) current_e = code_value(); + for(int i=0; i < NUM_AXIS; i++) { + if(code_seen(axis_codes[i])) current_position[i] = code_value(); + } break; } @@ -750,10 +749,10 @@ inline void process_commands() if(PS_ON_PIN > -1) pinMode(PS_ON_PIN,INPUT); //Floating break; case 82: - relative_mode_e = false; + axis_relative_modes[3] = false; break; case 83: - relative_mode_e = true; + axis_relative_modes[3] = true; break; case 84: if(code_seen('S')){ stepper_inactive_time = code_value() * 1000; } @@ -764,10 +763,9 @@ inline void process_commands() max_inactive_time = code_value() * 1000; break; case 92: // M92 - if(code_seen('X')) axis_steps_per_unit[0] = code_value(); - if(code_seen('Y')) axis_steps_per_unit[1] = code_value(); - if(code_seen('Z')) axis_steps_per_unit[2] = code_value(); - if(code_seen('E')) axis_steps_per_unit[3] = code_value(); + for(int i=0; i < NUM_AXIS; i++) { + if(code_seen(axis_codes[i])) axis_steps_per_unit[i] = code_value(); + } //Update start speed intervals and axis order. TODO: refactor axis_max_interval[] calculation into a function, as it // should also be used in setup() as well @@ -784,27 +782,25 @@ inline void process_commands() break; case 114: // M114 Serial.print("X:"); - Serial.print(current_x); + Serial.print(current_position[0]); Serial.print("Y:"); - Serial.print(current_y); + Serial.print(current_position[1]); Serial.print("Z:"); - Serial.print(current_z); + Serial.print(current_position[2]); Serial.print("E:"); - Serial.println(current_e); + Serial.println(current_position[3]); break; #ifdef RAMP_ACCELERATION //TODO: update for all axis, use for loop case 201: // M201 - if(code_seen('X')) axis_steps_per_sqr_second[0] = code_value() * axis_steps_per_unit[0]; - if(code_seen('Y')) axis_steps_per_sqr_second[1] = code_value() * axis_steps_per_unit[1]; - if(code_seen('Z')) axis_steps_per_sqr_second[2] = code_value() * axis_steps_per_unit[2]; - if(code_seen('E')) axis_steps_per_sqr_second[3] = code_value() * axis_steps_per_unit[3]; + for(int i=0; i < NUM_AXIS; i++) { + if(code_seen(axis_codes[i])) axis_steps_per_sqr_second[i] = code_value() * axis_steps_per_unit[i]; + } break; case 202: // M202 - if(code_seen('X')) axis_travel_steps_per_sqr_second[0] = code_value() * axis_steps_per_unit[0]; - if(code_seen('Y')) axis_travel_steps_per_sqr_second[1] = code_value() * axis_steps_per_unit[1]; - if(code_seen('Z')) axis_travel_steps_per_sqr_second[2] = code_value() * axis_steps_per_unit[2]; - if(code_seen('E')) axis_travel_steps_per_sqr_second[3] = code_value() * axis_steps_per_unit[3]; + for(int i=0; i < NUM_AXIS; i++) { + if(code_seen(axis_codes[i])) axis_travel_steps_per_sqr_second[i] = code_value() * axis_steps_per_unit[i]; + } break; #endif } @@ -840,14 +836,10 @@ inline void ClearToSend() inline void get_coordinates() { - if(code_seen('X')) destination_x = (float)code_value() + relative_mode*current_x; - else destination_x = current_x; //Are these else lines really needed? - if(code_seen('Y')) destination_y = (float)code_value() + relative_mode*current_y; - else destination_y = current_y; - if(code_seen('Z')) destination_z = (float)code_value() + relative_mode*current_z; - else destination_z = current_z; - if(code_seen('E')) destination_e = (float)code_value() + (relative_mode_e || relative_mode)*current_e; - else destination_e = current_e; + for(int i=0; i < NUM_AXIS; i++) { + if(code_seen(axis_codes[i])) destination[i] = (float)code_value() + (axis_relative_modes[i] || relative_mode)*current_position[i]; + else destination[i] = current_position[i]; //Are these else lines really needed? + } if(code_seen('F')) { next_feedrate = code_value(); if(next_feedrate > 0.0) feedrate = next_feedrate; @@ -857,123 +849,91 @@ inline void get_coordinates() inline void prepare_move() { //Find direction - if(destination_x >= current_x) direction_x = 1; - else direction_x = 0; - if(destination_y >= current_y) direction_y = 1; - else direction_y = 0; - if(destination_z >= current_z) direction_z = 1; - else direction_z = 0; - if(destination_e >= current_e) direction_e = 1; - else direction_e = 0; + for(int i=0; i < NUM_AXIS; i++) { + if(destination[i] >= current_position[i]) move_direction[i] = 1; + else move_direction[i] = 0; + } if (min_software_endstops) { - if (destination_x < 0) destination_x = 0.0; - if (destination_y < 0) destination_y = 0.0; - if (destination_z < 0) destination_z = 0.0; + if (destination[0] < 0) destination[0] = 0.0; + if (destination[1] < 0) destination[1] = 0.0; + if (destination[2] < 0) destination[2] = 0.0; } if (max_software_endstops) { - if (destination_x > X_MAX_LENGTH) destination_x = X_MAX_LENGTH; - if (destination_y > Y_MAX_LENGTH) destination_y = Y_MAX_LENGTH; - if (destination_z > Z_MAX_LENGTH) destination_z = Z_MAX_LENGTH; + if (destination[0] > X_MAX_LENGTH) destination[0] = X_MAX_LENGTH; + if (destination[1] > Y_MAX_LENGTH) destination[1] = Y_MAX_LENGTH; + if (destination[2] > Z_MAX_LENGTH) destination[2] = Z_MAX_LENGTH; } - - if(feedrate > max_feedrate) feedrate = max_feedrate; - if(feedrate > max_z_feedrate) z_feedrate = max_z_feedrate; - else z_feedrate = feedrate; - - xdiff = (destination_x - current_x); - ydiff = (destination_y - current_y); - zdiff = (destination_z - current_z); - ediff = (destination_e - current_e); - x_steps_to_take = abs(xdiff) * axis_steps_per_unit[0]; - y_steps_to_take = abs(ydiff) * axis_steps_per_unit[1]; - z_steps_to_take = abs(zdiff) * axis_steps_per_unit[2]; - e_steps_to_take = abs(ediff) * axis_steps_per_unit[3]; + for(int i=0; i < NUM_AXIS; i++) { + axis_diff[i] = destination[i] - current_position[i]; + move_steps_to_take[i] = abs(axis_diff[i]) * axis_steps_per_unit[i]; + } if(feedrate < 10) feedrate = 10; - /* - //experimental feedrate calc - if(abs(xdiff) > 0.1 && abs(ydiff) > 0.1) - d = sqrt(xdiff * xdiff + ydiff * ydiff); - else if(abs(xdiff) > 0.1) - d = abs(xdiff); - else if(abs(ydiff) > 0.1) - d = abs(ydiff); - else if(abs(zdiff) > 0.05) - d = abs(zdiff); - else if(abs(ediff) > 0.1) - d = abs(ediff); - else d = 1; //extremely slow move, should be okay for moves under 0.1mm - time_for_move = (xdiff / (feedrate / 60000000) ); - //time = 60000000 * dist / feedrate - //int feedz = (60000000 * zdiff) / time_for_move; - //if(feedz > maxfeed) - */ - #define X_TIME_FOR_MOVE ((float)x_steps_to_take / (axis_steps_per_unit[0]*feedrate/60000000)) - #define Y_TIME_FOR_MOVE ((float)y_steps_to_take / (axis_steps_per_unit[1]*feedrate/60000000)) - #define Z_TIME_FOR_MOVE ((float)z_steps_to_take / (axis_steps_per_unit[2]*z_feedrate/60000000)) - #define E_TIME_FOR_MOVE ((float)e_steps_to_take / (axis_steps_per_unit[3]*feedrate/60000000)) - time_for_move = max(X_TIME_FOR_MOVE, Y_TIME_FOR_MOVE); - time_for_move = max(time_for_move, Z_TIME_FOR_MOVE); - if(time_for_move <= 0) time_for_move = max(time_for_move, E_TIME_FOR_MOVE); - - if(x_steps_to_take) axis_interval[0] = time_for_move / x_steps_to_take * 100; - if(y_steps_to_take) axis_interval[1] = time_for_move / y_steps_to_take * 100; - if(z_steps_to_take) axis_interval[2] = time_for_move / z_steps_to_take * 100; - if(e_steps_to_take && (x_steps_to_take + y_steps_to_take <= 0) ) axis_interval[3] = time_for_move / e_steps_to_take * 100; - - #ifdef DEBUG_PREPARE_MOVE - Serial.print("destination_x: "); Serial.println(destination_x); - Serial.print("current_x: "); Serial.println(current_x); - Serial.print("x_steps_to_take: "); Serial.println(x_steps_to_take); - Serial.print("X_TIME_FOR_MVE: "); Serial.println(X_TIME_FOR_MOVE); - Serial.print("axis_interval[0]: "); Serial.println(axis_interval[0]); - Serial.println(""); - Serial.print("destination_y: "); Serial.println(destination_y); - Serial.print("current_y: "); Serial.println(current_y); - Serial.print("y_steps_to_take: "); Serial.println(y_steps_to_take); - Serial.print("Y_TIME_FOR_MVE: "); Serial.println(Y_TIME_FOR_MOVE); - Serial.print("axis_interval[1]: "); Serial.println(axis_interval[1]); - Serial.println(""); - Serial.print("destination_z: "); Serial.println(destination_z); - Serial.print("current_z: "); Serial.println(current_z); - Serial.print("z_steps_to_take: "); Serial.println(z_steps_to_take); - Serial.print("Z_TIME_FOR_MVE: "); Serial.println(Z_TIME_FOR_MOVE); - Serial.print("axis_interval[2]: "); Serial.println(axis_interval[2]); - Serial.println(""); - Serial.print("destination_e: "); Serial.println(destination_e); - Serial.print("current_e: "); Serial.println(current_e); - Serial.print("e_steps_to_take: "); Serial.println(e_steps_to_take); - Serial.print("E_TIME_FOR_MVE: "); Serial.println(E_TIME_FOR_MOVE); - Serial.print("axis_interval[3]: "); Serial.println(axis_interval[3]); - Serial.println(""); + //Feedrate calc based on XYZ travel distance + float xy_d; + if(abs(axis_diff[0]) > 0 || abs(axis_diff[1]) > 0 || abs(axis_diff[2])) { + xy_d = sqrt(axis_diff[0] * axis_diff[0] + axis_diff[1] * axis_diff[1]); + d = sqrt(xy_d * xy_d + axis_diff[2] * axis_diff[2]); + } + else if(abs(axis_diff[3]) > 0) + d = abs(axis_diff[3]); + #ifdef DEBUG_PREPARE_MOVE + else { + log_message("_PREPARE_MOVE - No steps to take!"); + } #endif - unsigned long axis_steps_to_take[NUM_AXIS] = {x_steps_to_take, y_steps_to_take, z_steps_to_take, e_steps_to_take}; - linear_move(axis_steps_to_take); // make the move + time_for_move = (d / (feedrate / 60000000.0) ); + //Check max feedrate for each axis is not violated, update time_for_move if necessary + for(int i = 0; i < NUM_AXIS; i++) { + if(move_steps_to_take[i] && abs(axis_diff[i]) / (time_for_move / 60000000.0) > max_feedrate[i]) { + time_for_move = time_for_move / max_feedrate[i] * (abs(axis_diff[i]) / (time_for_move / 60000000.0)); + } + } + //Calculate the full speed stepper interval for each axis + for(int i=0; i < NUM_AXIS; i++) { + if(move_steps_to_take[i]) axis_interval[i] = time_for_move / move_steps_to_take[i] * 100; + } + + #ifdef DEBUG_PREPARE_MOVE + log_float("_PREPARE_MOVE - Move distance on the XY plane", xy_d); + log_float("_PREPARE_MOVE - Move distance on the XYZ space", d); + log_float("_PREPARE_MOVE - Commanded feedrate", feedrate); + log_float("_PREPARE_MOVE - Constant full speed move time", time_for_move); + log_float_array("_PREPARE_MOVE - Destination", destination, NUM_AXIS); + log_float_array("_PREPARE_MOVE - Current position", current_position, NUM_AXIS); + log_ulong_array("_PREPARE_MOVE - Steps to take", move_steps_to_take, NUM_AXIS); + log_long_array("_PREPARE_MOVE - Axes full speed intervals", axis_interval, NUM_AXIS); + #endif + + unsigned long move_steps[NUM_AXIS]; + for(int i=0; i < NUM_AXIS; i++) + move_steps[i] = move_steps_to_take[i]; + linear_move(move_steps); // make the move } void linear_move(unsigned long axis_steps_remaining[]) // make linear move with preset speeds and destinations, see G0 and G1 { //Determine direction of movement - if (destination_x > current_x) digitalWrite(X_DIR_PIN,!INVERT_X_DIR); + if (destination[0] > current_position[0]) digitalWrite(X_DIR_PIN,!INVERT_X_DIR); else digitalWrite(X_DIR_PIN,INVERT_X_DIR); - if (destination_y > current_y) digitalWrite(Y_DIR_PIN,!INVERT_Y_DIR); + if (destination[1] > current_position[1]) digitalWrite(Y_DIR_PIN,!INVERT_Y_DIR); else digitalWrite(Y_DIR_PIN,INVERT_Y_DIR); - if (destination_z > current_z) digitalWrite(Z_DIR_PIN,!INVERT_Z_DIR); + if (destination[2] > current_position[2]) digitalWrite(Z_DIR_PIN,!INVERT_Z_DIR); else digitalWrite(Z_DIR_PIN,INVERT_Z_DIR); - if (destination_e > current_e) digitalWrite(E_DIR_PIN,!INVERT_E_DIR); + if (destination[3] > current_position[3]) digitalWrite(E_DIR_PIN,!INVERT_E_DIR); else digitalWrite(E_DIR_PIN,INVERT_E_DIR); - if(X_MIN_PIN > -1) if(!direction_x) if(digitalRead(X_MIN_PIN) != ENDSTOPS_INVERTING) axis_steps_remaining[0]=0; - if(Y_MIN_PIN > -1) if(!direction_y) if(digitalRead(Y_MIN_PIN) != ENDSTOPS_INVERTING) axis_steps_remaining[1]=0; - if(Z_MIN_PIN > -1) if(!direction_z) if(digitalRead(Z_MIN_PIN) != ENDSTOPS_INVERTING) axis_steps_remaining[2]=0; - if(X_MAX_PIN > -1) if(direction_x) if(digitalRead(X_MAX_PIN) != ENDSTOPS_INVERTING) axis_steps_remaining[0]=0; - if(Y_MAX_PIN > -1) if(direction_y) if(digitalRead(Y_MAX_PIN) != ENDSTOPS_INVERTING) axis_steps_remaining[1]=0; - if(Z_MAX_PIN > -1) if(direction_z) if(digitalRead(Z_MAX_PIN) != ENDSTOPS_INVERTING) axis_steps_remaining[2]=0; + if(X_MIN_PIN > -1) if(!move_direction[0]) if(digitalRead(X_MIN_PIN) != ENDSTOPS_INVERTING) axis_steps_remaining[0]=0; + if(Y_MIN_PIN > -1) if(!move_direction[1]) if(digitalRead(Y_MIN_PIN) != ENDSTOPS_INVERTING) axis_steps_remaining[1]=0; + if(Z_MIN_PIN > -1) if(!move_direction[2]) if(digitalRead(Z_MIN_PIN) != ENDSTOPS_INVERTING) axis_steps_remaining[2]=0; + if(X_MAX_PIN > -1) if(move_direction[0]) if(digitalRead(X_MAX_PIN) != ENDSTOPS_INVERTING) axis_steps_remaining[0]=0; + if(Y_MAX_PIN > -1) if(move_direction[1]) if(digitalRead(Y_MAX_PIN) != ENDSTOPS_INVERTING) axis_steps_remaining[1]=0; + if(Z_MAX_PIN > -1) if(move_direction[2]) if(digitalRead(Z_MAX_PIN) != ENDSTOPS_INVERTING) axis_steps_remaining[2]=0; //Only enable axis that are moving. If the axis doesn't need to move then it can stay disabled depending on configuration. @@ -999,6 +959,8 @@ void linear_move(unsigned long axis_steps_remaining[]) // make linear move with #ifdef DEBUG_BRESENHAM log_int("_BRESENHAM - Primary axis", primary_axis); log_int("_BRESENHAM - Primary axis full speed interval", interval); + log_uint_array("_BRESENHAM - Deltas", delta, NUM_AXIS); + log_int_array("_BRESENHAM - Errors", axis_error, NUM_AXIS); #endif //If acceleration is enabled, do some Bresenham calculations depending on which axis will lead it. @@ -1023,20 +985,17 @@ void linear_move(unsigned long axis_steps_remaining[]) // make linear move with } for(int i = 0; i < NUM_AXIS; i++) if(axis_steps_remaining[i] >0) { - new_axis_max_intervals[i] = slowest_start_axis_max_interval * axis_steps_remaining[i] / axis_steps_remaining[slowest_start_axis]; + new_axis_max_intervals[i] = slowest_start_axis_max_interval * axis_steps_remaining[slowest_start_axis] / axis_steps_remaining[i]; if(i == primary_axis) { max_interval = new_axis_max_intervals[i]; min_speed_steps_per_second = 100000000 / max_interval; } } - #ifdef DEBUG_RAMP_ACCELERATION - log_ulong_array("_RAMP_ACCELERATION - Actual step intervals at move start", new_axis_max_intervals, NUM_AXIS); - #endif //Calculate slowest axis plateau time float slowest_axis_plateau_time = 0; for(int i=0; i < NUM_AXIS ; i++) { if(axis_steps_remaining[i] > 0) { - if(e_steps_to_take > 0 && axis_steps_remaining[i] > 0) slowest_axis_plateau_time = max(slowest_axis_plateau_time, + if(move_steps_to_take[3] > 0 && axis_steps_remaining[i] > 0) slowest_axis_plateau_time = max(slowest_axis_plateau_time, (100000000.0 / axis_interval[i] - 100000000.0 / new_axis_max_intervals[i]) / (float) axis_steps_per_sqr_second[i]); else if(axis_steps_remaining[i] > 0) slowest_axis_plateau_time = max(slowest_axis_plateau_time, (100000000.0 / axis_interval[i] - 100000000.0 / new_axis_max_intervals[i]) / (float) axis_travel_steps_per_sqr_second[i]); @@ -1045,11 +1004,16 @@ void linear_move(unsigned long axis_steps_remaining[]) // make linear move with //Now we can calculate the new primary axis acceleration, so that the slowest axis max acceleration is not violated steps_per_sqr_second = (100000000.0 / axis_interval[primary_axis] - 100000000.0 / new_axis_max_intervals[primary_axis]) / slowest_axis_plateau_time; plateau_steps = (long) ((steps_per_sqr_second / 2.0 * slowest_axis_plateau_time + min_speed_steps_per_second) * slowest_axis_plateau_time); + #ifdef DEBUG_RAMP_ACCELERATION + log_int("_RAMP_ACCELERATION - Start speed limiting axis", slowest_start_axis); + log_ulong("_RAMP_ACCELERATION - Limiting axis start interval", slowest_start_axis_max_interval); + log_ulong_array("_RAMP_ACCELERATION - Actual step intervals at move start", new_axis_max_intervals, NUM_AXIS); + #endif #endif #ifdef EXP_ACCELERATION unsigned long virtual_full_velocity_steps; unsigned long full_velocity_steps; - if(e_steps_to_take > 0) virtual_full_velocity_steps = axis_virtual_full_velocity_steps[primary_axis]; + if(move_steps_to_take[3] > 0) virtual_full_velocity_steps = axis_virtual_full_velocity_steps[primary_axis]; else virtual_full_velocity_steps = axis_travel_virtual_full_velocity_steps[primary_axis]; full_velocity_steps = min(virtual_full_velocity_steps, (delta[primary_axis] - axis_min_constant_speed_steps[primary_axis]) / 2); max_interval = axis_max_interval[primary_axis]; @@ -1163,12 +1127,12 @@ void linear_move(unsigned long axis_steps_remaining[]) // make linear move with //If there are x or y steps remaining, perform Bresenham algorithm if(axis_steps_remaining[primary_axis]) { - if(X_MIN_PIN > -1) if(!direction_x) if(digitalRead(X_MIN_PIN) != ENDSTOPS_INVERTING) break; - if(Y_MIN_PIN > -1) if(!direction_y) if(digitalRead(Y_MIN_PIN) != ENDSTOPS_INVERTING) break; - if(X_MAX_PIN > -1) if(direction_x) if(digitalRead(X_MAX_PIN) != ENDSTOPS_INVERTING) break; - if(Y_MAX_PIN > -1) if(direction_y) if(digitalRead(Y_MAX_PIN) != ENDSTOPS_INVERTING) break; - if(Z_MIN_PIN > -1) if(!direction_z) if(digitalRead(Z_MIN_PIN) != ENDSTOPS_INVERTING) break; - if(Z_MAX_PIN > -1) if(direction_z) if(digitalRead(Z_MAX_PIN) != ENDSTOPS_INVERTING) break; + if(X_MIN_PIN > -1) if(!move_direction[0]) if(digitalRead(X_MIN_PIN) != ENDSTOPS_INVERTING) break; + if(Y_MIN_PIN > -1) if(!move_direction[1]) if(digitalRead(Y_MIN_PIN) != ENDSTOPS_INVERTING) break; + if(X_MAX_PIN > -1) if(move_direction[0]) if(digitalRead(X_MAX_PIN) != ENDSTOPS_INVERTING) break; + if(Y_MAX_PIN > -1) if(move_direction[1]) if(digitalRead(Y_MAX_PIN) != ENDSTOPS_INVERTING) break; + if(Z_MIN_PIN > -1) if(!move_direction[2]) if(digitalRead(Z_MIN_PIN) != ENDSTOPS_INVERTING) break; + if(Z_MAX_PIN > -1) if(move_direction[2]) if(digitalRead(Z_MAX_PIN) != ENDSTOPS_INVERTING) break; timediff = micros() * 100 - axis_previous_micros[primary_axis]; while(timediff >= interval && axis_steps_remaining[primary_axis] > 0) { steps_done++; @@ -1201,14 +1165,10 @@ void linear_move(unsigned long axis_steps_remaining[]) // make linear move with if(DISABLE_E) disable_e(); // Update current position partly based on direction, we probably can combine this with the direction code above... - if (destination_x > current_x) current_x = current_x + x_steps_to_take / axis_steps_per_unit[0]; - else current_x = current_x - x_steps_to_take / axis_steps_per_unit[0]; - if (destination_y > current_y) current_y = current_y + y_steps_to_take / axis_steps_per_unit[1]; - else current_y = current_y - y_steps_to_take / axis_steps_per_unit[1]; - if (destination_z > current_z) current_z = current_z + z_steps_to_take / axis_steps_per_unit[2]; - else current_z = current_z - z_steps_to_take / axis_steps_per_unit[2]; - if (destination_e > current_e) current_e = current_e + e_steps_to_take / axis_steps_per_unit[3]; - else current_e = current_e - e_steps_to_take / axis_steps_per_unit[3]; + for(int i=0; i < NUM_AXIS; i++) { + if (destination[i] > current_position[i]) current_position[i] = current_position[i] + move_steps_to_take[i] / axis_steps_per_unit[i]; + else current_position[i] = current_position[i] - move_steps_to_take[i] / axis_steps_per_unit[i]; + } } inline void do_step_update_micros(int axis) { @@ -1536,7 +1496,7 @@ if( (millis()-previous_millis_cmd) > stepper_inactive_time ) if(stepper_inactiv #ifdef DEBUG void log_message(char* message) { - Serial.println(message); + Serial.print("DEBUG"); Serial.println(message); } void log_int(char* message, int value) { diff --git a/Tonokip_Firmware/configuration.h b/Tonokip_Firmware/configuration.h index 55e9872..61072dc 100644 --- a/Tonokip_Firmware/configuration.h +++ b/Tonokip_Firmware/configuration.h @@ -10,7 +10,7 @@ //Min step delay in microseconds. If you are experiencing missing steps, try to raise the delay microseconds, but be aware this // If you enable this, make sure STEP_DELAY_RATIO is disabled. -#define STEP_DELAY_MICROS 1 +//#define STEP_DELAY_MICROS 1 //Step delay over interval ratio. If you are still experiencing missing steps, try to uncomment the following line, but be aware this //If you enable this, make sure STEP_DELAY_MICROS is disabled. @@ -96,9 +96,9 @@ float min_constant_speed_units = 2; // the minimum units of an accelerated move //Calibration variables const int NUM_AXIS = 4; // The axis order in all axis related arrays is X, Y, Z, E +bool axis_relative_modes[] = {false, false, false, true}; float axis_steps_per_unit[] = {80.376,80.376,3200/1.25,16}; -float max_feedrate = 200000; // mm/min, acceleration! -float max_z_feedrate = 180; // mm/min, acceleration! +float max_feedrate[] = {200000, 200000, 240, 500000}; //mmm, acceleration! //float x_steps_per_unit = 10.047; //float y_steps_per_unit = 10.047; From 2433b0459a2f8b9767d401773ca3992f7efcc253 Mon Sep 17 00:00:00 2001 From: Emanuele Caruso Date: Sun, 22 May 2011 20:19:56 +0200 Subject: [PATCH 16/45] Fixed bug that caused deltas in Bresenham to be cut and axis intervals to be negative in such case --- Tonokip_Firmware/Tonokip_Firmware.pde | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Tonokip_Firmware/Tonokip_Firmware.pde b/Tonokip_Firmware/Tonokip_Firmware.pde index f71d6d9..bf82ae3 100644 --- a/Tonokip_Firmware/Tonokip_Firmware.pde +++ b/Tonokip_Firmware/Tonokip_Firmware.pde @@ -945,8 +945,8 @@ void linear_move(unsigned long axis_steps_remaining[]) // make linear move with if(axis_steps_remaining[3]) enable_e(); //Define variables that are needed for the Bresenham algorithm. Please note that Z is not currently included in the Bresenham algorithm. - unsigned int delta[] = {axis_steps_remaining[0], axis_steps_remaining[1], axis_steps_remaining[2], axis_steps_remaining[3]}; //TODO: implement a "for" to support N axes - int axis_error[NUM_AXIS]; + unsigned long delta[] = {axis_steps_remaining[0], axis_steps_remaining[1], axis_steps_remaining[2], axis_steps_remaining[3]}; //TODO: implement a "for" to support N axes + long axis_error[NUM_AXIS]; unsigned int primary_axis; if(delta[1] > delta[0] && delta[1] > delta[2] && delta[1] > delta[3]) primary_axis = 1; else if (delta[0] >= delta[1] && delta[0] > delta[2] && delta[0] > delta[3]) primary_axis = 0; @@ -959,8 +959,8 @@ void linear_move(unsigned long axis_steps_remaining[]) // make linear move with #ifdef DEBUG_BRESENHAM log_int("_BRESENHAM - Primary axis", primary_axis); log_int("_BRESENHAM - Primary axis full speed interval", interval); - log_uint_array("_BRESENHAM - Deltas", delta, NUM_AXIS); - log_int_array("_BRESENHAM - Errors", axis_error, NUM_AXIS); + log_ulong_array("_BRESENHAM - Deltas", delta, NUM_AXIS); + log_long_array("_BRESENHAM - Errors", axis_error, NUM_AXIS); #endif //If acceleration is enabled, do some Bresenham calculations depending on which axis will lead it. From 8a2c2233cb0a8c14a60bc3539ca9ffd7971baa3c Mon Sep 17 00:00:00 2001 From: Emanuele Caruso Date: Sun, 22 May 2011 20:38:10 +0200 Subject: [PATCH 17/45] Fixed bad default configuration value that forced relative E. Changed back to default --- Tonokip_Firmware/configuration.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tonokip_Firmware/configuration.h b/Tonokip_Firmware/configuration.h index 61072dc..2643338 100644 --- a/Tonokip_Firmware/configuration.h +++ b/Tonokip_Firmware/configuration.h @@ -96,7 +96,7 @@ float min_constant_speed_units = 2; // the minimum units of an accelerated move //Calibration variables const int NUM_AXIS = 4; // The axis order in all axis related arrays is X, Y, Z, E -bool axis_relative_modes[] = {false, false, false, true}; +bool axis_relative_modes[] = {false, false, false, false}; float axis_steps_per_unit[] = {80.376,80.376,3200/1.25,16}; float max_feedrate[] = {200000, 200000, 240, 500000}; //mmm, acceleration! From 1139131f72f97ac5d6de72ada5030d82fc98eb9f Mon Sep 17 00:00:00 2001 From: Emanuele Caruso Date: Mon, 23 May 2011 20:03:47 +0200 Subject: [PATCH 18/45] Changed configuration values to better ones, according to my experience, which should also help avoid missing steps --- Tonokip_Firmware/configuration.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Tonokip_Firmware/configuration.h b/Tonokip_Firmware/configuration.h index 2643338..f2d23f0 100644 --- a/Tonokip_Firmware/configuration.h +++ b/Tonokip_Firmware/configuration.h @@ -27,8 +27,8 @@ //Acceleration settings #ifdef RAMP_ACCELERATION //X, Y, Z, E maximum start speed for accelerated moves. E default values are good for skeinforge 40+, for older versions raise them a lot. -float max_start_speed_units_per_second[] = {35.0,35.0,0.2,10.0}; -long max_acceleration_units_per_sq_second[] = {750,750,50,4000}; // X, Y, Z and E max acceleration in mm/s^2 for printing moves or retracts +float max_start_speed_units_per_second[] = {25.0,25.0,0.2,10.0}; +long max_acceleration_units_per_sq_second[] = {3000,3000,50,10000}; // X, Y, Z and E max acceleration in mm/s^2 for printing moves or retracts long max_travel_acceleration_units_per_sq_second[] = {1500,1500,50}; // X, Y, Z max acceleration in mm/s^2 for travel moves #endif #ifdef EXP_ACCELERATION @@ -54,10 +54,10 @@ float min_constant_speed_units = 2; // the minimum units of an accelerated move #endif //How often should the heater check for new temp readings, in milliseconds -#define HEATER_CHECK_INTERVAL 50 +#define HEATER_CHECK_INTERVAL 500 #define BED_CHECK_INTERVAL 5000 -//Uncomment the following line to disable heat management during acceleration -//#define DISABLE_CHECK_DURING_ACC +//Comment the following line to enable heat management during acceleration +#define DISABLE_CHECK_DURING_ACC #ifndef DISABLE_CHECK_DURING_ACC //Uncomment the following line to disable heat management during the move //#define DISABLE_CHECK_DURING_MOVE From 08e61b287f5cddce693a722a467bceeaadb60d2d Mon Sep 17 00:00:00 2001 From: Emanuele Caruso Date: Sun, 5 Jun 2011 04:22:57 +0200 Subject: [PATCH 19/45] Added debugging code for heat management. Changed acceleration values to more reliable ones --- Tonokip_Firmware/Tonokip_Firmware.pde | 11 ++++++++++- Tonokip_Firmware/configuration.h | 13 +++++++------ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/Tonokip_Firmware/Tonokip_Firmware.pde b/Tonokip_Firmware/Tonokip_Firmware.pde index bf82ae3..ced29d9 100644 --- a/Tonokip_Firmware/Tonokip_Firmware.pde +++ b/Tonokip_Firmware/Tonokip_Firmware.pde @@ -277,6 +277,7 @@ void setup() initsd(); #endif + } @@ -1255,6 +1256,10 @@ inline void manage_heater() previous_millis_heater = millis(); #ifdef HEATER_USES_THERMISTOR current_raw = analogRead(TEMP_0_PIN); + #ifdef DEBUG_HEAT_MGMT + log_int("_HEAT_MGMT - analogRead(TEMP_0_PIN)", current_raw); + log_int("_HEAT_MGMT - NUMTEMPS", NUMTEMPS); + #endif // When using thermistor, when the heater is colder than targer temp, we get a higher analog reading than target, // this switches it up so that the reading appears lower than target for the control logic. current_raw = 1023 - current_raw; @@ -1317,7 +1322,11 @@ inline void manage_heater() #ifdef BED_USES_THERMISTOR - current_bed_raw = analogRead(TEMP_1_PIN); + current_bed_raw = analogRead(TEMP_1_PIN); + #ifdef DEBUG_HEAT_MGMT + log_int("_HEAT_MGMT - analogRead(TEMP_1_PIN)", current_bed_raw); + log_int("_HEAT_MGMT - BNUMTEMPS", BNUMTEMPS); + #endif // If using thermistor, when the heater is colder than targer temp, we get a higher analog reading than target, // this switches it up so that the reading appears lower than target for the control logic. diff --git a/Tonokip_Firmware/configuration.h b/Tonokip_Firmware/configuration.h index f2d23f0..d77b974 100644 --- a/Tonokip_Firmware/configuration.h +++ b/Tonokip_Firmware/configuration.h @@ -28,8 +28,8 @@ #ifdef RAMP_ACCELERATION //X, Y, Z, E maximum start speed for accelerated moves. E default values are good for skeinforge 40+, for older versions raise them a lot. float max_start_speed_units_per_second[] = {25.0,25.0,0.2,10.0}; -long max_acceleration_units_per_sq_second[] = {3000,3000,50,10000}; // X, Y, Z and E max acceleration in mm/s^2 for printing moves or retracts -long max_travel_acceleration_units_per_sq_second[] = {1500,1500,50}; // X, Y, Z max acceleration in mm/s^2 for travel moves +long max_acceleration_units_per_sq_second[] = {1000,1000,50,10000}; // X, Y, Z and E max acceleration in mm/s^2 for printing moves or retracts +long max_travel_acceleration_units_per_sq_second[] = {500,500,50}; // X, Y, Z max acceleration in mm/s^2 for travel moves #endif #ifdef EXP_ACCELERATION float full_velocity_units = 10; // the units between minimum and G1 move feedrate @@ -160,10 +160,11 @@ const int Z_MAX_LENGTH = 100; //Uncomment the following line to enable debugging. You can better control debugging below the following line //#define DEBUG #ifdef DEBUG - #define DEBUG_PREPARE_MOVE //Enable this to debug prepare_move() function - #define DEBUG_BRESENHAM //Enable this to debug the Bresenham algorithm - #define DEBUG_RAMP_ACCELERATION //Enable this to debug all constant acceleration info - #define DEBUG_MOVE_TIME //Enable this to time each move and print the result + //#define DEBUG_PREPARE_MOVE //Enable this to debug prepare_move() function + //#define DEBUG_BRESENHAM //Enable this to debug the Bresenham algorithm + //#define DEBUG_RAMP_ACCELERATION //Enable this to debug all constant acceleration info + //#define DEBUG_MOVE_TIME //Enable this to time each move and print the result + //#define DEBUG_HEAT_MGMT #endif #endif From 4689ab10ef12951a20efb1713478056d17332421 Mon Sep 17 00:00:00 2001 From: Emanuele Caruso Date: Sun, 5 Jun 2011 06:24:20 +0200 Subject: [PATCH 20/45] Added option to disable heat management during travel moves, on by default. This helps a lot in avoiding missing steps, hence increasing reliability --- Tonokip_Firmware/Tonokip_Firmware.pde | 10 ++++++++-- Tonokip_Firmware/configuration.h | 2 ++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Tonokip_Firmware/Tonokip_Firmware.pde b/Tonokip_Firmware/Tonokip_Firmware.pde index ced29d9..535716e 100644 --- a/Tonokip_Firmware/Tonokip_Firmware.pde +++ b/Tonokip_Firmware/Tonokip_Firmware.pde @@ -1058,14 +1058,20 @@ void linear_move(unsigned long axis_steps_remaining[]) // make linear move with #ifdef DISABLE_CHECK_DURING_ACC if(!accelerating && !decelerating) { //If more that HEATER_CHECK_INTERVAL ms have passed since previous heating check, adjust temp - manage_heater(); + #ifdef DISABLE_CHECK_DURING_TRAVEL + if(delta[3] > 0) + #endif + manage_heater(); } #else #ifdef DISABLE_CHECK_DURING_MOVE {} //Do nothing #else //If more that HEATER_CHECK_INTERVAL ms have passed since previous heating check, adjust temp - manage_heater(); + #ifdef DISABLE_CHECK_DURING_TRAVEL + if(delta[3] > 0) + #endif + manage_heater(); #endif #endif #ifdef RAMP_ACCELERATION diff --git a/Tonokip_Firmware/configuration.h b/Tonokip_Firmware/configuration.h index d77b974..7710f82 100644 --- a/Tonokip_Firmware/configuration.h +++ b/Tonokip_Firmware/configuration.h @@ -62,6 +62,8 @@ float min_constant_speed_units = 2; // the minimum units of an accelerated move //Uncomment the following line to disable heat management during the move //#define DISABLE_CHECK_DURING_MOVE #endif +//Comment the following line to disable heat management during travel moves. Probably this should be commented if using PID. +#define DISABLE_CHECK_DURING_TRAVEL //Experimental temperature smoothing - only uncomment this if your temp readings are noisy //#define SMOOTHING 1 From a7ed8f90215ed948a5cba8e9f78b5d00c7b5c488 Mon Sep 17 00:00:00 2001 From: Emanuele Caruso Date: Sun, 5 Jun 2011 06:27:31 +0200 Subject: [PATCH 21/45] Exponential acceleration discontinued. Deleted all related code --- Tonokip_Firmware/Tonokip_Firmware.pde | 56 --------------------------- Tonokip_Firmware/configuration.h | 13 ------- 2 files changed, 69 deletions(-) diff --git a/Tonokip_Firmware/Tonokip_Firmware.pde b/Tonokip_Firmware/Tonokip_Firmware.pde index 535716e..933b6d2 100644 --- a/Tonokip_Firmware/Tonokip_Firmware.pde +++ b/Tonokip_Firmware/Tonokip_Firmware.pde @@ -78,16 +78,6 @@ unsigned long move_steps_to_take[NUM_AXIS]; max_travel_acceleration_units_per_sq_second[3] * axis_steps_per_unit[3]}; unsigned long steps_per_sqr_second, plateau_steps; #endif -#ifdef EXP_ACCELERATION - unsigned long axis_virtual_full_velocity_steps[] = {full_velocity_units * axis_steps_per_unit[0], full_velocity_units * axis_steps_per_unit[1]}; - unsigned long axis_travel_virtual_full_velocity_steps[] = {travel_move_full_velocity_units * axis_steps_per_unit[0], - travel_move_full_velocity_units * axis_steps_per_unit[1]}; - unsigned long axis_max_interval[] = {100000000.0 / (max_start_speed_units_per_second[0] * axis_steps_per_unit[0]), - 100000000.0 / (max_start_speed_units_per_second[1] * axis_steps_per_unit[1])}; - unsigned long max_interval; - unsigned long axis_min_constant_speed_steps[] = {min_constant_speed_units * axis_steps_per_unit[0], min_constant_speed_units * axis_steps_per_unit[1]}; - unsigned long min_constant_speed_steps; -#endif boolean acceleration_enabled = false, accelerating = false; unsigned long interval; float destination[NUM_AXIS] = {0.0, 0.0, 0.0, 0.0}; @@ -1011,15 +1001,6 @@ void linear_move(unsigned long axis_steps_remaining[]) // make linear move with log_ulong_array("_RAMP_ACCELERATION - Actual step intervals at move start", new_axis_max_intervals, NUM_AXIS); #endif #endif - #ifdef EXP_ACCELERATION - unsigned long virtual_full_velocity_steps; - unsigned long full_velocity_steps; - if(move_steps_to_take[3] > 0) virtual_full_velocity_steps = axis_virtual_full_velocity_steps[primary_axis]; - else virtual_full_velocity_steps = axis_travel_virtual_full_velocity_steps[primary_axis]; - full_velocity_steps = min(virtual_full_velocity_steps, (delta[primary_axis] - axis_min_constant_speed_steps[primary_axis]) / 2); - max_interval = axis_max_interval[primary_axis]; - min_constant_speed_steps = axis_min_constant_speed_steps[primary_axis]; - #endif unsigned long steps_done = 0; #ifdef RAMP_ACCELERATION @@ -1029,20 +1010,6 @@ void linear_move(unsigned long axis_steps_remaining[]) // make linear move with if(interval > max_interval) acceleration_enabled = false; boolean decelerating = false; #endif - #ifdef EXP_ACCELERATION - acceleration_enabled = true; - if(full_velocity_steps == 0) full_velocity_steps++; - if(interval > max_interval) acceleration_enabled = false; - unsigned long full_interval = interval; - if(min_constant_speed_steps >= steps_to_take) { - acceleration_enabled = false; - full_interval = max(max_interval, interval); // choose the min speed between feedrate and acceleration start speed - } - if(full_velocity_steps < virtual_full_velocity_steps && acceleration_enabled) full_interval = max(interval, - max_interval - ((max_interval - full_interval) * full_velocity_steps / virtual_full_velocity_steps)); // choose the min speed between feedrate and speed at full steps - unsigned int steps_acceleration_check = 1; - accelerating = acceleration_enabled; - #endif unsigned long start_move_micros = micros(); for(int i = 0; i < NUM_AXIS; i++) { @@ -1108,29 +1075,6 @@ void linear_move(unsigned long axis_steps_remaining[]) // make linear move with accelerating = false; } #endif - #ifdef EXP_ACCELERATION - //If acceleration is enabled on this move and we are in the acceleration segment, calculate the current interval - // TODO: is this any useful? -> steps_done % steps_acceleration_check == 0 - if (acceleration_enabled && steps_done < full_velocity_steps && steps_done / full_velocity_steps < 1 && (steps_done % steps_acceleration_check == 0)) { - if(steps_done == 0) { - interval = max_interval; - } else { - interval = max_interval - ((max_interval - full_interval) * steps_done / virtual_full_velocity_steps); - } - } else if (acceleration_enabled && steps_remaining < full_velocity_steps) { - //Else, if acceleration is enabled on this move and we are in the deceleration segment, calculate the current interval - if(steps_remaining == 0) { - interval = max_interval; - } else { - interval = max_interval - ((max_interval - full_interval) * steps_remaining / virtual_full_velocity_steps); - } - accelerating = true; - } else if (steps_done - full_velocity_steps >= 1 || !acceleration_enabled){ - //Else, we are just use the full speed interval as current interval - interval = full_interval; - accelerating = false; - } - #endif //If there are x or y steps remaining, perform Bresenham algorithm if(axis_steps_remaining[primary_axis]) { diff --git a/Tonokip_Firmware/configuration.h b/Tonokip_Firmware/configuration.h index 7710f82..5370977 100644 --- a/Tonokip_Firmware/configuration.h +++ b/Tonokip_Firmware/configuration.h @@ -19,11 +19,6 @@ //Comment this to disable ramp acceleration #define RAMP_ACCELERATION 1 -//Uncomment this to enable exponential acceleration. WARNING!! This is not supported in the current version, and will be fixed before -// merging it to the stable branch. -// TODO: fix exp acceleration to correctly perform N bresenham. -//#define EXP_ACCELERATION 1 - //Acceleration settings #ifdef RAMP_ACCELERATION //X, Y, Z, E maximum start speed for accelerated moves. E default values are good for skeinforge 40+, for older versions raise them a lot. @@ -31,14 +26,6 @@ float max_start_speed_units_per_second[] = {25.0,25.0,0.2,10.0}; long max_acceleration_units_per_sq_second[] = {1000,1000,50,10000}; // X, Y, Z and E max acceleration in mm/s^2 for printing moves or retracts long max_travel_acceleration_units_per_sq_second[] = {500,500,50}; // X, Y, Z max acceleration in mm/s^2 for travel moves #endif -#ifdef EXP_ACCELERATION -float full_velocity_units = 10; // the units between minimum and G1 move feedrate -float travel_move_full_velocity_units = 10; // used for travel moves -float min_units_per_second = 35.0; // the minimum feedrate -float min_constant_speed_units = 2; // the minimum units of an accelerated move that must be done at constant speed - // Note that if the move is shorter than this value, acceleration won't be perfomed, - // but will be done at the minimum between min_units_per_seconds and move feedrate speeds. -#endif // AD595 THERMOCOUPLE SUPPORT UNTESTED... USE WITH CAUTION!!!! From 2649509633397a9d97b998089ead76b2ae2741c8 Mon Sep 17 00:00:00 2001 From: Emanuele Caruso Date: Sun, 5 Jun 2011 06:29:41 +0200 Subject: [PATCH 22/45] Fixed comment in configuration.h --- Tonokip_Firmware/configuration.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tonokip_Firmware/configuration.h b/Tonokip_Firmware/configuration.h index 5370977..3a9dc0c 100644 --- a/Tonokip_Firmware/configuration.h +++ b/Tonokip_Firmware/configuration.h @@ -49,7 +49,7 @@ long max_travel_acceleration_units_per_sq_second[] = {500,500,50}; // X, Y, Z ma //Uncomment the following line to disable heat management during the move //#define DISABLE_CHECK_DURING_MOVE #endif -//Comment the following line to disable heat management during travel moves. Probably this should be commented if using PID. +//Comment the following line to enable heat management during travel moves. Probably this should be commented if using PID. #define DISABLE_CHECK_DURING_TRAVEL //Experimental temperature smoothing - only uncomment this if your temp readings are noisy From df7e8feffa8218d4ad83d1174802bae637c98530 Mon Sep 17 00:00:00 2001 From: Emanuele Caruso Date: Sun, 5 Jun 2011 06:44:17 +0200 Subject: [PATCH 23/45] Fixed automatic merge of spacexula fix --- Tonokip_Firmware/configuration.h | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/Tonokip_Firmware/configuration.h b/Tonokip_Firmware/configuration.h index 62d2031..9ba0198 100644 --- a/Tonokip_Firmware/configuration.h +++ b/Tonokip_Firmware/configuration.h @@ -87,14 +87,9 @@ long max_travel_acceleration_units_per_sq_second[] = {500,500,50}; // X, Y, Z ma const int NUM_AXIS = 4; // The axis order in all axis related arrays is X, Y, Z, E bool axis_relative_modes[] = {false, false, false, false}; float axis_steps_per_unit[] = {80.376,80.376,3200/1.25,16}; -float max_feedrate[] = {200000, 200000, 240, 500000}; //mmm, acceleration! - //For SAE Prusa mendeel float z_steps_per_unit = should be 3200/1.411 for 5/16-18 rod and 3200/1.058 for 5/16-24 -//float x_steps_per_unit = 10.047; -//float y_steps_per_unit = 10.047; -//float z_steps_per_unit = 833.398; -//float e_steps_per_unit = 0.706; -//float max_feedrate = 3000; +//float axis_steps_per_unit[] = {10.047,10.047,833.398,0.706}; +float max_feedrate[] = {200000, 200000, 240, 500000}; //mmm, acceleration! //For Inverting Stepper Enable Pins (Active Low) use 0, Non Inverting (Active High) use 1 const bool X_ENABLE_ON = 0; From 6e246d4ead55f27d8e2942d7fa6b75726badae3b Mon Sep 17 00:00:00 2001 From: Emanuele Caruso Date: Sun, 5 Jun 2011 07:35:35 +0200 Subject: [PATCH 24/45] Heat management now performed between moves if DISABLE_CHECK_DURING_TRAVEL is enabled --- Tonokip_Firmware/Tonokip_Firmware.pde | 2 +- Tonokip_Firmware/configuration.h | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Tonokip_Firmware/Tonokip_Firmware.pde b/Tonokip_Firmware/Tonokip_Firmware.pde index 933b6d2..2530eda 100644 --- a/Tonokip_Firmware/Tonokip_Firmware.pde +++ b/Tonokip_Firmware/Tonokip_Firmware.pde @@ -449,7 +449,7 @@ inline void process_commands() { case 0: // G0 -> G1 case 1: // G1 - #ifdef DISABLE_CHECK_DURING_ACC || DISABLE_CHECK_DURING_MOVE + #ifdef DISABLE_CHECK_DURING_ACC || DISABLE_CHECK_DURING_MOVE || DISABLE_CHECK_DURING_TRAVEL manage_heater(); #endif get_coordinates(); // For X Y Z E F diff --git a/Tonokip_Firmware/configuration.h b/Tonokip_Firmware/configuration.h index 9ba0198..cabfdb3 100644 --- a/Tonokip_Firmware/configuration.h +++ b/Tonokip_Firmware/configuration.h @@ -49,7 +49,8 @@ long max_travel_acceleration_units_per_sq_second[] = {500,500,50}; // X, Y, Z ma //Uncomment the following line to disable heat management during the move //#define DISABLE_CHECK_DURING_MOVE #endif -//Comment the following line to enable heat management during travel moves. Probably this should be commented if using PID. +//Uncomment the following line to disable heat management during travel moves, strongly recommended if you are missing steps mid print. +//Probably this should remain commented if are using PID. #define DISABLE_CHECK_DURING_TRAVEL //Experimental temperature smoothing - only uncomment this if your temp readings are noisy From 62ccc7fec878d9286b3006dc718d6011f4c04a84 Mon Sep 17 00:00:00 2001 From: Emanuele Caruso Date: Mon, 6 Jun 2011 18:29:04 +0200 Subject: [PATCH 25/45] Added comment to configuration.h --- Tonokip_Firmware/configuration.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tonokip_Firmware/configuration.h b/Tonokip_Firmware/configuration.h index cabfdb3..0d4556e 100644 --- a/Tonokip_Firmware/configuration.h +++ b/Tonokip_Firmware/configuration.h @@ -150,7 +150,7 @@ const int Z_MAX_LENGTH = 100; //#define DEBUG_BRESENHAM //Enable this to debug the Bresenham algorithm //#define DEBUG_RAMP_ACCELERATION //Enable this to debug all constant acceleration info //#define DEBUG_MOVE_TIME //Enable this to time each move and print the result - //#define DEBUG_HEAT_MGMT + //#define DEBUG_HEAT_MGMT //Enable this to debug heat management. WARNING, this will cause axes to jitter! #endif #endif From c475cc2062969380e15358e8c0cd3f7654a64878 Mon Sep 17 00:00:00 2001 From: Emanuele Caruso Date: Mon, 6 Jun 2011 18:49:34 +0200 Subject: [PATCH 26/45] Optimized print/travel move check, as it is performed in the bresenham loop --- Tonokip_Firmware/Tonokip_Firmware.pde | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Tonokip_Firmware/Tonokip_Firmware.pde b/Tonokip_Firmware/Tonokip_Firmware.pde index 2530eda..c68fc29 100644 --- a/Tonokip_Firmware/Tonokip_Firmware.pde +++ b/Tonokip_Firmware/Tonokip_Firmware.pde @@ -947,6 +947,7 @@ void linear_move(unsigned long axis_steps_remaining[]) // make linear move with unsigned long steps_to_take = steps_remaining; for(int i=0; i < NUM_AXIS; i++) if(i != primary_axis) axis_error[i] = delta[primary_axis] / 2; interval = axis_interval[primary_axis]; + bool is_print_move = delta[3] > 0; #ifdef DEBUG_BRESENHAM log_int("_BRESENHAM - Primary axis", primary_axis); log_int("_BRESENHAM - Primary axis full speed interval", interval); @@ -986,7 +987,7 @@ void linear_move(unsigned long axis_steps_remaining[]) // make linear move with float slowest_axis_plateau_time = 0; for(int i=0; i < NUM_AXIS ; i++) { if(axis_steps_remaining[i] > 0) { - if(move_steps_to_take[3] > 0 && axis_steps_remaining[i] > 0) slowest_axis_plateau_time = max(slowest_axis_plateau_time, + if(is_print_move && axis_steps_remaining[i] > 0) slowest_axis_plateau_time = max(slowest_axis_plateau_time, (100000000.0 / axis_interval[i] - 100000000.0 / new_axis_max_intervals[i]) / (float) axis_steps_per_sqr_second[i]); else if(axis_steps_remaining[i] > 0) slowest_axis_plateau_time = max(slowest_axis_plateau_time, (100000000.0 / axis_interval[i] - 100000000.0 / new_axis_max_intervals[i]) / (float) axis_travel_steps_per_sqr_second[i]); @@ -1026,7 +1027,7 @@ void linear_move(unsigned long axis_steps_remaining[]) // make linear move with if(!accelerating && !decelerating) { //If more that HEATER_CHECK_INTERVAL ms have passed since previous heating check, adjust temp #ifdef DISABLE_CHECK_DURING_TRAVEL - if(delta[3] > 0) + if(is_print_move) #endif manage_heater(); } @@ -1036,7 +1037,7 @@ void linear_move(unsigned long axis_steps_remaining[]) // make linear move with #else //If more that HEATER_CHECK_INTERVAL ms have passed since previous heating check, adjust temp #ifdef DISABLE_CHECK_DURING_TRAVEL - if(delta[3] > 0) + if(is_print_move) #endif manage_heater(); #endif From 8c4f65709535b76e322516d6d7506eb430ca6d0b Mon Sep 17 00:00:00 2001 From: Emanuele Caruso Date: Mon, 6 Jun 2011 19:59:47 +0200 Subject: [PATCH 27/45] Added safety feature to DISABLE_CHECK_DURING_TRAVEL feature, which allows to define a max time in milliseconds after which the travel move is not considered so --- Tonokip_Firmware/Tonokip_Firmware.pde | 13 +++++++++++++ Tonokip_Firmware/configuration.h | 4 +++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/Tonokip_Firmware/Tonokip_Firmware.pde b/Tonokip_Firmware/Tonokip_Firmware.pde index c68fc29..a5630a8 100644 --- a/Tonokip_Firmware/Tonokip_Firmware.pde +++ b/Tonokip_Firmware/Tonokip_Firmware.pde @@ -1017,6 +1017,15 @@ void linear_move(unsigned long axis_steps_remaining[]) // make linear move with axis_previous_micros[i] = start_move_micros * 100; } + #ifdef DISABLE_CHECK_DURING_TRAVEL + //If the move time is more than allowed in DISABLE_CHECK_DURING_TRAVEL, let's + // consider this a print move and perform heat management during it + if(time_for_move / 1000 > DISABLE_CHECK_DURING_TRAVEL) is_print_move = true; + #ifdef DEBUG_DISABLE_CHECK_DURING_TRAVEL + log_bool("_DISABLE_CHECK_DURING_TRAVEL - is_print_move", is_print_move); + #endif + #endif + #ifdef DEBUG_MOVE_TIME unsigned long startmove = micros(); #endif @@ -1459,6 +1468,10 @@ void log_message(char* message) { Serial.print("DEBUG"); Serial.println(message); } +void log_bool(char* message, bool value) { + Serial.print("DEBUG"); Serial.print(message); Serial.print(": "); Serial.println(value); +} + void log_int(char* message, int value) { Serial.print("DEBUG"); Serial.print(message); Serial.print(": "); Serial.println(value); } diff --git a/Tonokip_Firmware/configuration.h b/Tonokip_Firmware/configuration.h index 0d4556e..86c9f39 100644 --- a/Tonokip_Firmware/configuration.h +++ b/Tonokip_Firmware/configuration.h @@ -51,7 +51,8 @@ long max_travel_acceleration_units_per_sq_second[] = {500,500,50}; // X, Y, Z ma #endif //Uncomment the following line to disable heat management during travel moves, strongly recommended if you are missing steps mid print. //Probably this should remain commented if are using PID. -#define DISABLE_CHECK_DURING_TRAVEL +//It also defines the max milliseconds interval after which a travel move is not considered so for the sake of this feature. +#define DISABLE_CHECK_DURING_TRAVEL 1000 //Experimental temperature smoothing - only uncomment this if your temp readings are noisy //#define SMOOTHING 1 @@ -151,6 +152,7 @@ const int Z_MAX_LENGTH = 100; //#define DEBUG_RAMP_ACCELERATION //Enable this to debug all constant acceleration info //#define DEBUG_MOVE_TIME //Enable this to time each move and print the result //#define DEBUG_HEAT_MGMT //Enable this to debug heat management. WARNING, this will cause axes to jitter! + //#define DEBUG_DISABLE_CHECK_DURING_TRAVEL //Debug the namesake feature, see above in this file #endif #endif From 57c05dde4219454c9d3a21bfc31a824141674cd5 Mon Sep 17 00:00:00 2001 From: Emanuele Caruso Date: Wed, 22 Jun 2011 02:03:11 +0200 Subject: [PATCH 28/45] Now heat check is also disabled during retract moves, if DISABLE_CHECK_DURING_TRAVEL is enabled --- Tonokip_Firmware/Tonokip_Firmware.pde | 2 ++ Tonokip_Firmware/configuration.h | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Tonokip_Firmware/Tonokip_Firmware.pde b/Tonokip_Firmware/Tonokip_Firmware.pde index a5630a8..1957cf9 100644 --- a/Tonokip_Firmware/Tonokip_Firmware.pde +++ b/Tonokip_Firmware/Tonokip_Firmware.pde @@ -1021,6 +1021,8 @@ void linear_move(unsigned long axis_steps_remaining[]) // make linear move with //If the move time is more than allowed in DISABLE_CHECK_DURING_TRAVEL, let's // consider this a print move and perform heat management during it if(time_for_move / 1000 > DISABLE_CHECK_DURING_TRAVEL) is_print_move = true; + //else, if the move is a retract, consider it as a travel move for the sake of this feature + else if(delta[3]>0 && delta[0] + delta[1] + delta[2] == 0) is_print_move = false; #ifdef DEBUG_DISABLE_CHECK_DURING_TRAVEL log_bool("_DISABLE_CHECK_DURING_TRAVEL - is_print_move", is_print_move); #endif diff --git a/Tonokip_Firmware/configuration.h b/Tonokip_Firmware/configuration.h index 86c9f39..2716de2 100644 --- a/Tonokip_Firmware/configuration.h +++ b/Tonokip_Firmware/configuration.h @@ -49,7 +49,7 @@ long max_travel_acceleration_units_per_sq_second[] = {500,500,50}; // X, Y, Z ma //Uncomment the following line to disable heat management during the move //#define DISABLE_CHECK_DURING_MOVE #endif -//Uncomment the following line to disable heat management during travel moves, strongly recommended if you are missing steps mid print. +//Uncomment the following line to disable heat management during travel moves (and extruder-only moves, eg: retracts), strongly recommended if you are missing steps mid print. //Probably this should remain commented if are using PID. //It also defines the max milliseconds interval after which a travel move is not considered so for the sake of this feature. #define DISABLE_CHECK_DURING_TRAVEL 1000 From 4642d041d5daf0f59d588c8b2d6c0696a5ad64d0 Mon Sep 17 00:00:00 2001 From: Emanuele Caruso Date: Wed, 22 Jun 2011 02:21:34 +0200 Subject: [PATCH 29/45] Fixed merge bug, I forgot to declare the new variable home_all_axis --- Tonokip_Firmware/Tonokip_Firmware.pde | 1 + 1 file changed, 1 insertion(+) diff --git a/Tonokip_Firmware/Tonokip_Firmware.pde b/Tonokip_Firmware/Tonokip_Firmware.pde index cb8e552..4528324 100644 --- a/Tonokip_Firmware/Tonokip_Firmware.pde +++ b/Tonokip_Firmware/Tonokip_Firmware.pde @@ -83,6 +83,7 @@ unsigned long interval; float destination[NUM_AXIS] = {0.0, 0.0, 0.0, 0.0}; float current_position[NUM_AXIS] = {0.0, 0.0, 0.0, 0.0}; long axis_interval[NUM_AXIS]; // for speed delay +bool home_all_axis = true; float feedrate = 1500, next_feedrate, saved_feedrate; float time_for_move; long gcode_N, gcode_LastN; From ae9e6f61529b7d49e752a88994bc93bbbb089820 Mon Sep 17 00:00:00 2001 From: Emanuele Caruso Date: Fri, 24 Jun 2011 02:34:48 +0200 Subject: [PATCH 30/45] Added comment in configuration.h explaining how to set axes steps per unit --- Tonokip_Firmware/configuration.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tonokip_Firmware/configuration.h b/Tonokip_Firmware/configuration.h index 2716de2..0a38a6a 100644 --- a/Tonokip_Firmware/configuration.h +++ b/Tonokip_Firmware/configuration.h @@ -88,7 +88,7 @@ long max_travel_acceleration_units_per_sq_second[] = {500,500,50}; // X, Y, Z ma //Calibration variables const int NUM_AXIS = 4; // The axis order in all axis related arrays is X, Y, Z, E bool axis_relative_modes[] = {false, false, false, false}; -float axis_steps_per_unit[] = {80.376,80.376,3200/1.25,16}; +float axis_steps_per_unit[] = {80.376,80.376,3200/1.25,16}; // {X steps per unit, Y steps per unit, Z steps per unit, E steps per unit} //For SAE Prusa mendeel float z_steps_per_unit = should be 3200/1.411 for 5/16-18 rod and 3200/1.058 for 5/16-24 //float axis_steps_per_unit[] = {10.047,10.047,833.398,0.706}; float max_feedrate[] = {200000, 200000, 240, 500000}; //mmm, acceleration! From e4af5e82f26fab59bb2bda540e1673317f48ce8a Mon Sep 17 00:00:00 2001 From: kliment Date: Mon, 4 Jul 2011 16:17:19 +0200 Subject: [PATCH 31/45] Rename to Sprinter --- {Tonokip_Firmware => Sprinter}/BedThermistorTable_100k.h | 0 {Tonokip_Firmware => Sprinter}/BedThermistorTable_200k.h | 0 {Tonokip_Firmware => Sprinter}/FatStructs.h | 0 {Tonokip_Firmware => Sprinter}/Makefile | 0 {Tonokip_Firmware => Sprinter}/Sd2Card.cpp | 0 {Tonokip_Firmware => Sprinter}/Sd2Card.h | 0 {Tonokip_Firmware => Sprinter}/Sd2PinMap.h | 0 {Tonokip_Firmware => Sprinter}/SdFat.h | 0 {Tonokip_Firmware => Sprinter}/SdFatUtil.h | 0 {Tonokip_Firmware => Sprinter}/SdFatmainpage.h | 0 {Tonokip_Firmware => Sprinter}/SdFile.cpp | 0 {Tonokip_Firmware => Sprinter}/SdInfo.h | 0 {Tonokip_Firmware => Sprinter}/SdVolume.cpp | 0 Tonokip_Firmware/Tonokip_Firmware.h => Sprinter/Sprinter.h | 0 Tonokip_Firmware/Tonokip_Firmware.pde => Sprinter/Sprinter.pde | 0 {Tonokip_Firmware => Sprinter}/ThermistorTable_100k.h | 0 {Tonokip_Firmware => Sprinter}/ThermistorTable_200k.h | 0 {Tonokip_Firmware => Sprinter}/ThermistorTable_mendelparts.h | 0 {Tonokip_Firmware => Sprinter}/configuration.h | 0 {Tonokip_Firmware => Sprinter}/createTemperatureLookup.py | 0 {Tonokip_Firmware => Sprinter}/pins.h | 0 21 files changed, 0 insertions(+), 0 deletions(-) rename {Tonokip_Firmware => Sprinter}/BedThermistorTable_100k.h (100%) rename {Tonokip_Firmware => Sprinter}/BedThermistorTable_200k.h (100%) rename {Tonokip_Firmware => Sprinter}/FatStructs.h (100%) rename {Tonokip_Firmware => Sprinter}/Makefile (100%) rename {Tonokip_Firmware => Sprinter}/Sd2Card.cpp (100%) rename {Tonokip_Firmware => Sprinter}/Sd2Card.h (100%) rename {Tonokip_Firmware => Sprinter}/Sd2PinMap.h (100%) rename {Tonokip_Firmware => Sprinter}/SdFat.h (100%) rename {Tonokip_Firmware => Sprinter}/SdFatUtil.h (100%) rename {Tonokip_Firmware => Sprinter}/SdFatmainpage.h (100%) rename {Tonokip_Firmware => Sprinter}/SdFile.cpp (100%) rename {Tonokip_Firmware => Sprinter}/SdInfo.h (100%) rename {Tonokip_Firmware => Sprinter}/SdVolume.cpp (100%) rename Tonokip_Firmware/Tonokip_Firmware.h => Sprinter/Sprinter.h (100%) rename Tonokip_Firmware/Tonokip_Firmware.pde => Sprinter/Sprinter.pde (100%) rename {Tonokip_Firmware => Sprinter}/ThermistorTable_100k.h (100%) rename {Tonokip_Firmware => Sprinter}/ThermistorTable_200k.h (100%) rename {Tonokip_Firmware => Sprinter}/ThermistorTable_mendelparts.h (100%) rename {Tonokip_Firmware => Sprinter}/configuration.h (100%) rename {Tonokip_Firmware => Sprinter}/createTemperatureLookup.py (100%) rename {Tonokip_Firmware => Sprinter}/pins.h (100%) diff --git a/Tonokip_Firmware/BedThermistorTable_100k.h b/Sprinter/BedThermistorTable_100k.h similarity index 100% rename from Tonokip_Firmware/BedThermistorTable_100k.h rename to Sprinter/BedThermistorTable_100k.h diff --git a/Tonokip_Firmware/BedThermistorTable_200k.h b/Sprinter/BedThermistorTable_200k.h similarity index 100% rename from Tonokip_Firmware/BedThermistorTable_200k.h rename to Sprinter/BedThermistorTable_200k.h diff --git a/Tonokip_Firmware/FatStructs.h b/Sprinter/FatStructs.h similarity index 100% rename from Tonokip_Firmware/FatStructs.h rename to Sprinter/FatStructs.h diff --git a/Tonokip_Firmware/Makefile b/Sprinter/Makefile similarity index 100% rename from Tonokip_Firmware/Makefile rename to Sprinter/Makefile diff --git a/Tonokip_Firmware/Sd2Card.cpp b/Sprinter/Sd2Card.cpp similarity index 100% rename from Tonokip_Firmware/Sd2Card.cpp rename to Sprinter/Sd2Card.cpp diff --git a/Tonokip_Firmware/Sd2Card.h b/Sprinter/Sd2Card.h similarity index 100% rename from Tonokip_Firmware/Sd2Card.h rename to Sprinter/Sd2Card.h diff --git a/Tonokip_Firmware/Sd2PinMap.h b/Sprinter/Sd2PinMap.h similarity index 100% rename from Tonokip_Firmware/Sd2PinMap.h rename to Sprinter/Sd2PinMap.h diff --git a/Tonokip_Firmware/SdFat.h b/Sprinter/SdFat.h similarity index 100% rename from Tonokip_Firmware/SdFat.h rename to Sprinter/SdFat.h diff --git a/Tonokip_Firmware/SdFatUtil.h b/Sprinter/SdFatUtil.h similarity index 100% rename from Tonokip_Firmware/SdFatUtil.h rename to Sprinter/SdFatUtil.h diff --git a/Tonokip_Firmware/SdFatmainpage.h b/Sprinter/SdFatmainpage.h similarity index 100% rename from Tonokip_Firmware/SdFatmainpage.h rename to Sprinter/SdFatmainpage.h diff --git a/Tonokip_Firmware/SdFile.cpp b/Sprinter/SdFile.cpp similarity index 100% rename from Tonokip_Firmware/SdFile.cpp rename to Sprinter/SdFile.cpp diff --git a/Tonokip_Firmware/SdInfo.h b/Sprinter/SdInfo.h similarity index 100% rename from Tonokip_Firmware/SdInfo.h rename to Sprinter/SdInfo.h diff --git a/Tonokip_Firmware/SdVolume.cpp b/Sprinter/SdVolume.cpp similarity index 100% rename from Tonokip_Firmware/SdVolume.cpp rename to Sprinter/SdVolume.cpp diff --git a/Tonokip_Firmware/Tonokip_Firmware.h b/Sprinter/Sprinter.h similarity index 100% rename from Tonokip_Firmware/Tonokip_Firmware.h rename to Sprinter/Sprinter.h diff --git a/Tonokip_Firmware/Tonokip_Firmware.pde b/Sprinter/Sprinter.pde similarity index 100% rename from Tonokip_Firmware/Tonokip_Firmware.pde rename to Sprinter/Sprinter.pde diff --git a/Tonokip_Firmware/ThermistorTable_100k.h b/Sprinter/ThermistorTable_100k.h similarity index 100% rename from Tonokip_Firmware/ThermistorTable_100k.h rename to Sprinter/ThermistorTable_100k.h diff --git a/Tonokip_Firmware/ThermistorTable_200k.h b/Sprinter/ThermistorTable_200k.h similarity index 100% rename from Tonokip_Firmware/ThermistorTable_200k.h rename to Sprinter/ThermistorTable_200k.h diff --git a/Tonokip_Firmware/ThermistorTable_mendelparts.h b/Sprinter/ThermistorTable_mendelparts.h similarity index 100% rename from Tonokip_Firmware/ThermistorTable_mendelparts.h rename to Sprinter/ThermistorTable_mendelparts.h diff --git a/Tonokip_Firmware/configuration.h b/Sprinter/configuration.h similarity index 100% rename from Tonokip_Firmware/configuration.h rename to Sprinter/configuration.h diff --git a/Tonokip_Firmware/createTemperatureLookup.py b/Sprinter/createTemperatureLookup.py similarity index 100% rename from Tonokip_Firmware/createTemperatureLookup.py rename to Sprinter/createTemperatureLookup.py diff --git a/Tonokip_Firmware/pins.h b/Sprinter/pins.h similarity index 100% rename from Tonokip_Firmware/pins.h rename to Sprinter/pins.h From 873e85b3bb5240eaaba6491c38284e2d6d3fba2e Mon Sep 17 00:00:00 2001 From: kliment Date: Mon, 4 Jul 2011 22:24:14 +0200 Subject: [PATCH 32/45] Rename to sprinter --- Sprinter/Sprinter.pde | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprinter/Sprinter.pde b/Sprinter/Sprinter.pde index 4528324..e697231 100644 --- a/Sprinter/Sprinter.pde +++ b/Sprinter/Sprinter.pde @@ -1,7 +1,7 @@ // Tonokip RepRap firmware rewrite based off of Hydra-mmm firmware. // Licence: GPL -#include "Tonokip_Firmware.h" +#include "Sprinter.h" #include "configuration.h" #include "pins.h" From 0ff215446b7321d5b5f502e3347a9af4dca057e5 Mon Sep 17 00:00:00 2001 From: Joem Date: Mon, 4 Jul 2011 18:26:37 -0600 Subject: [PATCH 33/45] fixed sanguinololu pins.h --- Tonokip_Firmware/pins.h | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/Tonokip_Firmware/pins.h b/Tonokip_Firmware/pins.h index eee78e8..0b44e9d 100644 --- a/Tonokip_Firmware/pins.h +++ b/Tonokip_Firmware/pins.h @@ -416,50 +416,52 @@ #error Oops! Make sure you have 'Sanguino' selected from the 'Tools -> Boards' menu. #endif -// uncomment the following line for Sanguinololu v1.2, comment for 1.1 or earlier. -// #define SANGUINOLOLU_V_1_2 +// comment the following line for Sanguinololu v1.1 or earlier. +#define SANGUINOLOLU_V_1_2 #define X_STEP_PIN 15 #define X_DIR_PIN 21 -#define X_ENABLE_PIN -1 #define X_MIN_PIN 18 -#define X_MAX_PIN -2 //2 +#define X_MAX_PIN -2 #define Y_STEP_PIN 22 #define Y_DIR_PIN 23 -#define Y_ENABLE_PIN -1 #define Y_MIN_PIN 19 -#define Y_MAX_PIN -1 //17 +#define Y_MAX_PIN -1 #define Z_STEP_PIN 3 #define Z_DIR_PIN 2 -// zenable defined by platform below #define Z_MIN_PIN 20 -#define Z_MAX_PIN -1 //19 +#define Z_MAX_PIN -1 #define E_STEP_PIN 1 #define E_DIR_PIN 0 -#define E_ENABLE_PIN -1 #define LED_PIN -1 -#define FAN_PIN -1 // THIS LINE FOR V1.0 +#define FAN_PIN -1 #define PS_ON_PIN -1 #define KILL_PIN -1 -#define HEATER_0_PIN 13 // THIS LINE FOR V1.0+ (extruder) +#define HEATER_0_PIN 13 // (extruder) #ifdef SANGUINOLOLU_V_1_2 #define HEATER_1_PIN 12 // (bed) +#define X_ENABLE_PIN 14 +#define Y_ENABLE_PIN 14 #define Z_ENABLE_PIN 26 +#define E_ENABLE_PIN 14 #else #define HEATER_1_PIN 14 // (bed) +#define X_ENABLE_PIN -1 +#define Y_ENABLE_PIN -1 #define Z_ENABLE_PIN -1 +#define E_ENABLE_PIN -1 #endif From d1cfd12190a0810bb6a623a5e674d9339e723b8e Mon Sep 17 00:00:00 2001 From: kliment Date: Tue, 5 Jul 2011 20:20:15 +0200 Subject: [PATCH 34/45] Cleaned up configuration. Made a hack so that board versions can be set from configuration.h. Combined thermistor tables. Enabled maxtemp and mintemp by default. Changed case of configuration.h to make it appear first in Arduino IDE --- Sprinter/BedThermistorTable_100k.h | 85 ------ Sprinter/BedThermistorTable_200k.h | 42 --- Sprinter/{configuration.h => Configuration.h} | 152 +++++----- Sprinter/Sprinter.pde | 2 +- Sprinter/ThermistorTable_100k.h | 85 ------ Sprinter/ThermistorTable_200k.h | 42 --- Sprinter/ThermistorTable_mendelparts.h | 45 --- Sprinter/pins.h | 51 +++- Sprinter/thermistortables.h | 274 ++++++++++++++++++ 9 files changed, 392 insertions(+), 386 deletions(-) delete mode 100644 Sprinter/BedThermistorTable_100k.h delete mode 100644 Sprinter/BedThermistorTable_200k.h rename Sprinter/{configuration.h => Configuration.h} (75%) delete mode 100644 Sprinter/ThermistorTable_100k.h delete mode 100644 Sprinter/ThermistorTable_200k.h delete mode 100644 Sprinter/ThermistorTable_mendelparts.h create mode 100644 Sprinter/thermistortables.h diff --git a/Sprinter/BedThermistorTable_100k.h b/Sprinter/BedThermistorTable_100k.h deleted file mode 100644 index 84bc607..0000000 --- a/Sprinter/BedThermistorTable_100k.h +++ /dev/null @@ -1,85 +0,0 @@ -#ifndef THERMISTORTABLE_H_ -#define THERMISTORTABLE_H_ - -// Thermistor lookup table for RepRap Temperature Sensor Boards (http://make.rrrf.org/ts) -// See this page: -// http://dev.www.reprap.org/bin/view/Main/Thermistor -// for details of what goes in this table. -// Made with createTemperatureLookup.py (http://svn.reprap.org/trunk/reprap/firmware/Arduino/utilities/createTemperatureLookup.py) -// ./createTemperatureLookup.py --r0=100000 --t0=25 --r1=0 --r2=4700 --beta=4066 --max-adc=1023 -// r0: 100000 -// t0: 25 -// r1: 0 -// r2: 4700 -// beta: 4066 -// max adc: 1023 - -#define BNUMTEMPS 61 -const short bedtemptable[BNUMTEMPS][2] = { -{ 23 , 300 }, -{ 25 , 295 }, -{ 27 , 290 }, -{ 28 , 285 }, -{ 31 , 280 }, -{ 33 , 275 }, -{ 35 , 270 }, -{ 38 , 265 }, -{ 41 , 260 }, -{ 44 , 255 }, -{ 48 , 250 }, -{ 52 , 245 }, -{ 56 , 240 }, -{ 61 , 235 }, -{ 66 , 230 }, -{ 71 , 225 }, -{ 78 , 220 }, -{ 84 , 215 }, -{ 92 , 210 }, -{ 100 , 205 }, -{ 109 , 200 }, -{ 120 , 195 }, -{ 131 , 190 }, -{ 143 , 185 }, -{ 156 , 180 }, -{ 171 , 175 }, -{ 187 , 170 }, -{ 205 , 165 }, -{ 224 , 160 }, -{ 245 , 155 }, -{ 268 , 150 }, -{ 293 , 145 }, -{ 320 , 140 }, -{ 348 , 135 }, -{ 379 , 130 }, -{ 411 , 125 }, -{ 445 , 120 }, -{ 480 , 115 }, -{ 516 , 110 }, -{ 553 , 105 }, -{ 591 , 100 }, -{ 628 , 95 }, -{ 665 , 90 }, -{ 702 , 85 }, -{ 737 , 80 }, -{ 770 , 75 }, -{ 801 , 70 }, -{ 830 , 65 }, -{ 857 , 60 }, -{ 881 , 55 }, -{ 903 , 50 }, -{ 922 , 45 }, -{ 939 , 40 }, -{ 954 , 35 }, -{ 966 , 30 }, -{ 977 , 25 }, -{ 985 , 20 }, -{ 993 , 15 }, -{ 999 , 10 }, -{ 1004 , 5 }, -{ 1008 , 0 }, - -}; - - -#endif - diff --git a/Sprinter/BedThermistorTable_200k.h b/Sprinter/BedThermistorTable_200k.h deleted file mode 100644 index 3d96aa3..0000000 --- a/Sprinter/BedThermistorTable_200k.h +++ /dev/null @@ -1,42 +0,0 @@ -#ifndef THERMISTORTABLE_H_ -#define THERMISTORTABLE_H_ - -// Thermistor lookup table for RepRap Temperature Sensor Boards (http://make.rrrf.org/ts) -// See this page: -// http://dev.www.reprap.org/bin/view/Main/Thermistor -// for details of what goes in this table. -// Made with createTemperatureLookup.py (http://svn.reprap.org/trunk/reprap/firmware/Arduino/utilities/createTemperatureLookup.py) -// ./createTemperatureLookup.py --r0=100000 --t0=25 --r1=0 --r2=4700 --beta=4066 --max-adc=1023 -// r0: 100000 -// t0: 25 -// r1: 0 -// r2: 4700 -// beta: 4066 -// max adc: 1023 - -#define BNUMTEMPS 20 -const short bedtemptable[BNUMTEMPS][2] = { - {1, 848}, - {54, 275}, - {107, 228}, - {160, 202}, - {213, 185}, - {266, 171}, - {319, 160}, - {372, 150}, - {425, 141}, - {478, 133}, - {531, 125}, - {584, 118}, - {637, 110}, - {690, 103}, - {743, 95}, - {796, 86}, - {849, 77}, - {902, 65}, - {955, 49}, - {1008, 17} -}; - - -#endif diff --git a/Sprinter/configuration.h b/Sprinter/Configuration.h similarity index 75% rename from Sprinter/configuration.h rename to Sprinter/Configuration.h index 0a38a6a..54ea8ea 100644 --- a/Sprinter/configuration.h +++ b/Sprinter/Configuration.h @@ -1,13 +1,87 @@ -#ifndef PARAMETERS_H -#define PARAMETERS_H +#ifndef CONFIGURATION_H +#define CONFIGURATION_H -// NO RS485/EXTRUDER CONTROLLER SUPPORT -// PLEASE VERIFY PIN ASSIGNMENTS FOR YOUR CONFIGURATION!!!!!!! -#define MOTHERBOARD 3 // ATMEGA168 = 0, SANGUINO = 1, MOTHERBOARD = 2, MEGA/RAMPS = 3, ATMEGA328 = 4, Gen6 = 5, Sanguinololu = 6 -//Comment out to disable SD support +//BASIC SETTINGS: select your board type, thermistor type, axis scaling, and endstop configuration + +// The following define selects which electronics board you have. Please choose the one that matches your setup +// MEGA/RAMPS up to 1.2 = 3, +// RAMPS 1.3 = 63 +// Gen6 = 5, +// Sanguinololu up to 1.1 = 6 +// Sanguinololu 1.2 and above = 62 +#define MOTHERBOARD 3 + +//Thermistor settings: +// 1 is 100k thermistor +// 2 is 200k thermistor +// 3 is mendel-parts thermistor +#define THERMISTORHEATER 1 +#define THERMISTORBED 1 + + +//Calibration variables +//X, Y, Z, E steps per unit - Metric Prusa Mendel with Wade extruder: +float axis_steps_per_unit[] = {80, 80, 3200/1.25,700}; +//Metric Prusa Mendel with Makergear geared stepper extruder: +//float axis_steps_per_unit[] = {80,80,3200/1.25,1380}; + + +////Endstop Settings +#define ENDSTOPPULLUPS 1 // Comment this out (using // at the start of the line) to disable the endstop pullup resistors +//The pullups are needed if you directly connect a mechanical endswitch between the signal and ground pins. +const bool ENDSTOPS_INVERTING = false; //set to true to invert the logic of the endstops + +//This determines the communication speed of the printer +#define BAUDRATE 115200 + +//Comment out (using // at the start of the line) to disable SD support: #define SDSUPPORT 1 + + + + +//ADVANCED SETTINGS - to tweak parameters + +#include "thermistortables.h" + +//For Inverting Stepper Enable Pins (Active Low) use 0, Non Inverting (Active High) use 1 +const bool X_ENABLE_ON = 0; +const bool Y_ENABLE_ON = 0; +const bool Z_ENABLE_ON = 0; +const bool E_ENABLE_ON = 0; + +//Disables axis when it's not being used. +const bool DISABLE_X = false; +const bool DISABLE_Y = false; +const bool DISABLE_Z = true; +const bool DISABLE_E = false; + +const bool INVERT_X_DIR = false; +const bool INVERT_Y_DIR = false; +const bool INVERT_Z_DIR = true; +const bool INVERT_E_DIR = false; + +//ENDSTOP SETTINGS: +// Sets direction of endstops when homing; 1=MAX, -1=MIN +const int X_HOME_DIR = -1; +const int Y_HOME_DIR = -1; +const int Z_HOME_DIR = -1; + +const bool min_software_endstops = false; //If true, axis won't move to coordinates less than zero. +const bool max_software_endstops = true; //If true, axis won't move to coordinates greater than the defined lengths below. +const int X_MAX_LENGTH = 200; +const int Y_MAX_LENGTH = 200; +const int Z_MAX_LENGTH = 100; + + +//MOVEMENT SETTINGS +const int NUM_AXIS = 4; // The axis order in all axis related arrays is X, Y, Z, E +float max_feedrate[] = {200000, 200000, 240, 500000}; +bool axis_relative_modes[] = {false, false, false, false}; + + //Min step delay in microseconds. If you are experiencing missing steps, try to raise the delay microseconds, but be aware this // If you enable this, make sure STEP_DELAY_RATIO is disabled. //#define STEP_DELAY_MICROS 1 @@ -63,13 +137,13 @@ long max_travel_acceleration_units_per_sq_second[] = {500,500,50}; // X, Y, Z ma //If the temperature has not increased at the end of that period, the target temperature is set to zero. It can be reset with another M104/M109 //#define WATCHPERIOD 5000 //5 seconds //The minimal temperature defines the temperature below which the heater will not be enabled -//#define MINTEMP +#define MINTEMP 5 //Experimental max temp //When temperature exceeds max temp, your bot will halt. //This feature exists to protect your hotend from overheating accidentally, but *NOT* from thermistor short/failure! //You should use MINTEMP for thermistor short/failure protection. -//#define MAXTEMP 275 +#define MAXTEMP 275 // Select one of these only to define how the nozzle temp is read. #define HEATER_USES_THERMISTOR @@ -80,69 +154,7 @@ long max_travel_acceleration_units_per_sq_second[] = {500,500,50}; // X, Y, Z ma #define BED_USES_THERMISTOR //#define BED_USES_AD595 -// Calibration formulas -// e_extruded_steps_per_mm = e_feedstock_steps_per_mm * (desired_extrusion_diameter^2 / feedstock_diameter^2) -// new_axis_steps_per_mm = previous_axis_steps_per_mm * (test_distance_instructed/test_distance_traveled) -// units are in millimeters or whatever length unit you prefer: inches,football-fields,parsecs etc -//Calibration variables -const int NUM_AXIS = 4; // The axis order in all axis related arrays is X, Y, Z, E -bool axis_relative_modes[] = {false, false, false, false}; -float axis_steps_per_unit[] = {80.376,80.376,3200/1.25,16}; // {X steps per unit, Y steps per unit, Z steps per unit, E steps per unit} -//For SAE Prusa mendeel float z_steps_per_unit = should be 3200/1.411 for 5/16-18 rod and 3200/1.058 for 5/16-24 -//float axis_steps_per_unit[] = {10.047,10.047,833.398,0.706}; -float max_feedrate[] = {200000, 200000, 240, 500000}; //mmm, acceleration! - -//For Inverting Stepper Enable Pins (Active Low) use 0, Non Inverting (Active High) use 1 -const bool X_ENABLE_ON = 0; -const bool Y_ENABLE_ON = 0; -const bool Z_ENABLE_ON = 0; -const bool E_ENABLE_ON = 0; - -//Disables axis when it's not being used. -const bool DISABLE_X = false; -const bool DISABLE_Y = false; -const bool DISABLE_Z = true; -const bool DISABLE_E = false; - -const bool INVERT_X_DIR = false; -const bool INVERT_Y_DIR = false; -const bool INVERT_Z_DIR = true; -const bool INVERT_E_DIR = false; - -// Sets direction of endstops when homing; 1=MAX, -1=MIN -const int X_HOME_DIR = -1; -const int Y_HOME_DIR = -1; -const int Z_HOME_DIR = -1; - - -//Thermistor settings: - -//Uncomment for 100k thermistor -//#include "ThermistorTable_100k.h" -//#include "BedThermistorTable_100k.h" - -//Uncomment for 200k thermistor -//#include "ThermistorTable_200k.h" -//#include "BedThermistorTable_200k.h" - -//Identical thermistors on heater and bed - use this if you have no heated bed or if the thermistors are the same on both: -#include "ThermistorTable_200k.h" -//#include "ThermistorTable_100k.h" -//#include "ThermistorTable_mendelparts.h" -#define BNUMTEMPS NUMTEMPS -#define bedtemptable temptable - -//Endstop Settings -#define ENDSTOPPULLUPS 1 -const bool ENDSTOPS_INVERTING = false; -const bool min_software_endstops = false; //If true, axis won't move to coordinates less than zero. -const bool max_software_endstops = true; //If true, axis won't move to coordinates greater than the defined lengths below. -const int X_MAX_LENGTH = 220; -const int Y_MAX_LENGTH = 220; -const int Z_MAX_LENGTH = 100; - -#define BAUDRATE 115200 //Uncomment the following line to enable debugging. You can better control debugging below the following line //#define DEBUG diff --git a/Sprinter/Sprinter.pde b/Sprinter/Sprinter.pde index e697231..733aec8 100644 --- a/Sprinter/Sprinter.pde +++ b/Sprinter/Sprinter.pde @@ -2,7 +2,7 @@ // Licence: GPL #include "Sprinter.h" -#include "configuration.h" +#include "Configuration.h" #include "pins.h" #ifdef SDSUPPORT diff --git a/Sprinter/ThermistorTable_100k.h b/Sprinter/ThermistorTable_100k.h deleted file mode 100644 index d0698b2..0000000 --- a/Sprinter/ThermistorTable_100k.h +++ /dev/null @@ -1,85 +0,0 @@ -#ifndef THERMISTORTABLE_H_ -#define THERMISTORTABLE_H_ - -// Thermistor lookup table for RepRap Temperature Sensor Boards (http://make.rrrf.org/ts) -// See this page: -// http://dev.www.reprap.org/bin/view/Main/Thermistor -// for details of what goes in this table. -// Made with createTemperatureLookup.py (http://svn.reprap.org/trunk/reprap/firmware/Arduino/utilities/createTemperatureLookup.py) -// ./createTemperatureLookup.py --r0=100000 --t0=25 --r1=0 --r2=4700 --beta=4066 --max-adc=1023 -// r0: 100000 -// t0: 25 -// r1: 0 -// r2: 4700 -// beta: 4066 -// max adc: 1023 - -#define NUMTEMPS 61 -const short temptable[NUMTEMPS][2] = { -{ 23 , 300 }, -{ 25 , 295 }, -{ 27 , 290 }, -{ 28 , 285 }, -{ 31 , 280 }, -{ 33 , 275 }, -{ 35 , 270 }, -{ 38 , 265 }, -{ 41 , 260 }, -{ 44 , 255 }, -{ 48 , 250 }, -{ 52 , 245 }, -{ 56 , 240 }, -{ 61 , 235 }, -{ 66 , 230 }, -{ 71 , 225 }, -{ 78 , 220 }, -{ 84 , 215 }, -{ 92 , 210 }, -{ 100 , 205 }, -{ 109 , 200 }, -{ 120 , 195 }, -{ 131 , 190 }, -{ 143 , 185 }, -{ 156 , 180 }, -{ 171 , 175 }, -{ 187 , 170 }, -{ 205 , 165 }, -{ 224 , 160 }, -{ 245 , 155 }, -{ 268 , 150 }, -{ 293 , 145 }, -{ 320 , 140 }, -{ 348 , 135 }, -{ 379 , 130 }, -{ 411 , 125 }, -{ 445 , 120 }, -{ 480 , 115 }, -{ 516 , 110 }, -{ 553 , 105 }, -{ 591 , 100 }, -{ 628 , 95 }, -{ 665 , 90 }, -{ 702 , 85 }, -{ 737 , 80 }, -{ 770 , 75 }, -{ 801 , 70 }, -{ 830 , 65 }, -{ 857 , 60 }, -{ 881 , 55 }, -{ 903 , 50 }, -{ 922 , 45 }, -{ 939 , 40 }, -{ 954 , 35 }, -{ 966 , 30 }, -{ 977 , 25 }, -{ 985 , 20 }, -{ 993 , 15 }, -{ 999 , 10 }, -{ 1004 , 5 }, -{ 1008 , 0 }, - -}; - - -#endif - diff --git a/Sprinter/ThermistorTable_200k.h b/Sprinter/ThermistorTable_200k.h deleted file mode 100644 index 4142eb2..0000000 --- a/Sprinter/ThermistorTable_200k.h +++ /dev/null @@ -1,42 +0,0 @@ -#ifndef THERMISTORTABLE_H_ -#define THERMISTORTABLE_H_ - -// Thermistor lookup table for RepRap Temperature Sensor Boards (http://make.rrrf.org/ts) -// See this page: -// http://dev.www.reprap.org/bin/view/Main/Thermistor -// for details of what goes in this table. -// Made with createTemperatureLookup.py (http://svn.reprap.org/trunk/reprap/firmware/Arduino/utilities/createTemperatureLookup.py) -// ./createTemperatureLookup.py --r0=100000 --t0=25 --r1=0 --r2=4700 --beta=4066 --max-adc=1023 -// r0: 100000 -// t0: 25 -// r1: 0 -// r2: 4700 -// beta: 4066 -// max adc: 1023 - -#define NUMTEMPS 20 -const short temptable[NUMTEMPS][2] = { - {1, 848}, - {54, 275}, - {107, 228}, - {160, 202}, - {213, 185}, - {266, 171}, - {319, 160}, - {372, 150}, - {425, 141}, - {478, 133}, - {531, 125}, - {584, 118}, - {637, 110}, - {690, 103}, - {743, 95}, - {796, 86}, - {849, 77}, - {902, 65}, - {955, 49}, - {1008, 17} -}; - - -#endif diff --git a/Sprinter/ThermistorTable_mendelparts.h b/Sprinter/ThermistorTable_mendelparts.h deleted file mode 100644 index 9e65b85..0000000 --- a/Sprinter/ThermistorTable_mendelparts.h +++ /dev/null @@ -1,45 +0,0 @@ -#ifndef THERMISTORTABLE_H_ -#define THERMISTORTABLE_H_ - -//thermistor table for mendel-parts thermistor -// Standardized R/T characteristic no. 8404 - // RS thermistor 484-0183; EPCOS NTC - // Mendel-Parts thermistor G540 / G550 - // Optimized for 100...300C working range. - // Max range: -20...300C - // Max reading error on Gen 6 electronics: ~+5%, -3% in 100 - 300C range. - -#define NUMTEMPS 28 -const short temptable[NUMTEMPS][2] = { - {1,864}, - {21,300}, - {25,290}, - {29,280}, - {33,270}, - {39,260}, - {46,250}, - {54,240}, - {64,230}, - {75,220}, - {90,210}, - {107,200}, - {128,190}, - {154,180}, - {184,170}, - {221,160}, - {265,150}, - {316,140}, - {375,130}, - {441,120}, - {513,110}, - {588,100}, - {734,80}, - {856,60}, - {938,40}, - {986,20}, - {1008,0}, - {1018,-20} - }; - - -#endif diff --git a/Sprinter/pins.h b/Sprinter/pins.h index eee78e8..7540ebc 100644 --- a/Sprinter/pins.h +++ b/Sprinter/pins.h @@ -23,6 +23,8 @@ * +----+ ****************************************************************************************/ #if MOTHERBOARD == 0 +#define KNOWN_BOARD 1 + #ifndef __AVR_ATmega168__ #error Oops! Make sure you have 'Arduino Diecimila' selected from the boards menu. #endif @@ -60,7 +62,7 @@ #define TEMP_0_PIN 0 // MUST USE ANALOG INPUT NUMBERING NOT DIGITAL OUTPUT NUMBERING!!!!!!!!! - +#endif @@ -93,7 +95,9 @@ * +--------+ * ****************************************************************************************/ -#elif MOTHERBOARD == 1 +#if MOTHERBOARD == 1 +#define KNOWN_BOARD 1 + #ifndef __AVR_ATmega644P__ #error Oops! Make sure you have 'Sanguino' selected from the 'Tools -> Boards' menu. #endif @@ -134,14 +138,16 @@ - +#endif /**************************************************************************************** * RepRap Motherboard ****---NOOOOOO RS485/EXTRUDER CONTROLLER!!!!!!!!!!!!!!!!!---******* * ****************************************************************************************/ -#elif MOTHERBOARD == 2 +#if MOTHERBOARD == 2 +#define KNOWN_BOARD 1 + #ifndef __AVR_ATmega644P__ #error Oops! Make sure you have 'Sanguino' selected from the 'Tools -> Boards' menu. #endif @@ -192,13 +198,19 @@ - +#endif /**************************************************************************************** * Arduino Mega pin assignment * ****************************************************************************************/ -#elif MOTHERBOARD == 3 +#if MOTHERBOARD == 33 +#define MOTHERBOARD 3 +#define RAMPS_V_1_3 +#endif +#if MOTHERBOARD == 3 +#define KNOWN_BOARD 1 + //////////////////FIX THIS////////////// #ifndef __AVR_ATmega1280__ #ifndef __AVR_ATmega2560__ @@ -210,7 +222,6 @@ // #define RAMPS_V_1_3 // #define RAMPS_V_1_0 - #ifdef RAMPS_V_1_3 #define X_STEP_PIN 54 @@ -307,12 +318,14 @@ #endif - +#endif /**************************************************************************************** * Duemilanove w/ ATMega328P pin assignment * ****************************************************************************************/ -#elif MOTHERBOARD == 4 +#if MOTHERBOARD == 4 +#define KNOWN_BOARD 1 + #ifndef __AVR_ATmega328P__ #error Oops! Make sure you have 'Arduino Duemilanove w/ ATMega328' selected from the 'Tools -> Boards' menu. #endif @@ -350,13 +363,14 @@ #define TEMP_0_PIN 0 // MUST USE ANALOG INPUT NUMBERING NOT DIGITAL OUTPUT NUMBERING!!!!!!!!! - +#endif /**************************************************************************************** * Gen6 pin assignment * ****************************************************************************************/ -#elif MOTHERBOARD == 5 +#if MOTHERBOARD == 5 +#define KNOWN_BOARD 1 #ifndef __AVR_ATmega644P__ #error Oops! Make sure you have 'Sanguino' selected from the 'Tools -> Boards' menu. @@ -393,7 +407,7 @@ #define SDPOWER -1 - #define SDSS -1 + #define SDSS 17 #define LED_PIN -1 //changed @ rkoeppl 20110410 #define TEMP_1_PIN -1 //changed @ rkoeppl 20110410 #define FAN_PIN -1 //changed @ rkoeppl 20110410 @@ -406,12 +420,17 @@ #define TX_ENABLE_PIN 12 #define RX_ENABLE_PIN 13 - +#endif /**************************************************************************************** * Sanguinololu pin assignment * ****************************************************************************************/ -#elif MOTHERBOARD == 6 +#if MOTHERBOARD == 62 +#define MOTHERBOARD 6 +#define +#endif +#if MOTHERBOARD == 6 +#define KNOWN_BOARD 1 #ifndef __AVR_ATmega644P__ #error Oops! Make sure you have 'Sanguino' selected from the 'Tools -> Boards' menu. #endif @@ -468,9 +487,9 @@ #define SDPOWER -1 #define SDSS 31 -#else - +#ifndef KNOWN_BOARD #error Unknown MOTHERBOARD value in configuration.h +#endif #endif diff --git a/Sprinter/thermistortables.h b/Sprinter/thermistortables.h new file mode 100644 index 0000000..e21b647 --- /dev/null +++ b/Sprinter/thermistortables.h @@ -0,0 +1,274 @@ +#ifndef THERMISTORTABLES_H_ +#define THERMISTORTABLES_H_ + +#if THERMISTORHEATER == 1 //100k bed thermistor + + +#define NUMTEMPS 61 +const short temptable[NUMTEMPS][2] = { +{ 23 , 300 }, +{ 25 , 295 }, +{ 27 , 290 }, +{ 28 , 285 }, +{ 31 , 280 }, +{ 33 , 275 }, +{ 35 , 270 }, +{ 38 , 265 }, +{ 41 , 260 }, +{ 44 , 255 }, +{ 48 , 250 }, +{ 52 , 245 }, +{ 56 , 240 }, +{ 61 , 235 }, +{ 66 , 230 }, +{ 71 , 225 }, +{ 78 , 220 }, +{ 84 , 215 }, +{ 92 , 210 }, +{ 100 , 205 }, +{ 109 , 200 }, +{ 120 , 195 }, +{ 131 , 190 }, +{ 143 , 185 }, +{ 156 , 180 }, +{ 171 , 175 }, +{ 187 , 170 }, +{ 205 , 165 }, +{ 224 , 160 }, +{ 245 , 155 }, +{ 268 , 150 }, +{ 293 , 145 }, +{ 320 , 140 }, +{ 348 , 135 }, +{ 379 , 130 }, +{ 411 , 125 }, +{ 445 , 120 }, +{ 480 , 115 }, +{ 516 , 110 }, +{ 553 , 105 }, +{ 591 , 100 }, +{ 628 , 95 }, +{ 665 , 90 }, +{ 702 , 85 }, +{ 737 , 80 }, +{ 770 , 75 }, +{ 801 , 70 }, +{ 830 , 65 }, +{ 857 , 60 }, +{ 881 , 55 }, +{ 903 , 50 }, +{ 922 , 45 }, +{ 939 , 40 }, +{ 954 , 35 }, +{ 966 , 30 }, +{ 977 , 25 }, +{ 985 , 20 }, +{ 993 , 15 }, +{ 999 , 10 }, +{ 1004 , 5 }, +{ 1008 , 0 } //safety +}; + +#elif THERMISTORHEATER == 2 //200k bed thermistor +#define NUMTEMPS 21 +const short temptable[NUMTEMPS][2] = { + {1, 848}, + {54, 275}, + {107, 228}, + {160, 202}, + {213, 185}, + {266, 171}, + {319, 160}, + {372, 150}, + {425, 141}, + {478, 133}, + {531, 125}, + {584, 118}, + {637, 110}, + {690, 103}, + {743, 95}, + {796, 86}, + {849, 77}, + {902, 65}, + {955, 49}, + {1008, 17}, + {1020, 0} //safety +}; + +#elif THERMISTORHEATER == 3 //mendel-parts +#define NUMTEMPS 28 +const short temptable[NUMTEMPS][2] = { + {1,864}, + {21,300}, + {25,290}, + {29,280}, + {33,270}, + {39,260}, + {46,250}, + {54,240}, + {64,230}, + {75,220}, + {90,210}, + {107,200}, + {128,190}, + {154,180}, + {184,170}, + {221,160}, + {265,150}, + {316,140}, + {375,130}, + {441,120}, + {513,110}, + {588,100}, + {734,80}, + {856,60}, + {938,40}, + {986,20}, + {1008,0}, + {1018,-20} + }; + +#else +#error No thermistor table specified + +#endif + + +#if THERMISTORHEATER==THERMISTORBED +#define BNUMTEMPS NUMTEMPS +#define bedtemptable temptable +#else +#if THERMISTORBED == 1 //100k bed thermistor + + +#define BNUMTEMPS 61 +const short bedtemptable[BNUMTEMPS][2] = { +{ 23 , 300 }, +{ 25 , 295 }, +{ 27 , 290 }, +{ 28 , 285 }, +{ 31 , 280 }, +{ 33 , 275 }, +{ 35 , 270 }, +{ 38 , 265 }, +{ 41 , 260 }, +{ 44 , 255 }, +{ 48 , 250 }, +{ 52 , 245 }, +{ 56 , 240 }, +{ 61 , 235 }, +{ 66 , 230 }, +{ 71 , 225 }, +{ 78 , 220 }, +{ 84 , 215 }, +{ 92 , 210 }, +{ 100 , 205 }, +{ 109 , 200 }, +{ 120 , 195 }, +{ 131 , 190 }, +{ 143 , 185 }, +{ 156 , 180 }, +{ 171 , 175 }, +{ 187 , 170 }, +{ 205 , 165 }, +{ 224 , 160 }, +{ 245 , 155 }, +{ 268 , 150 }, +{ 293 , 145 }, +{ 320 , 140 }, +{ 348 , 135 }, +{ 379 , 130 }, +{ 411 , 125 }, +{ 445 , 120 }, +{ 480 , 115 }, +{ 516 , 110 }, +{ 553 , 105 }, +{ 591 , 100 }, +{ 628 , 95 }, +{ 665 , 90 }, +{ 702 , 85 }, +{ 737 , 80 }, +{ 770 , 75 }, +{ 801 , 70 }, +{ 830 , 65 }, +{ 857 , 60 }, +{ 881 , 55 }, +{ 903 , 50 }, +{ 922 , 45 }, +{ 939 , 40 }, +{ 954 , 35 }, +{ 966 , 30 }, +{ 977 , 25 }, +{ 985 , 20 }, +{ 993 , 15 }, +{ 999 , 10 }, +{ 1004 , 5 }, +{ 1008 , 0 } //safety +}; + +#elif THERMISTORBED == 2 //200k bed thermistor +#define BNUMTEMPS 21 +const short bedtemptable[BNUMTEMPS][2] = { + {1, 848}, + {54, 275}, + {107, 228}, + {160, 202}, + {213, 185}, + {266, 171}, + {319, 160}, + {372, 150}, + {425, 141}, + {478, 133}, + {531, 125}, + {584, 118}, + {637, 110}, + {690, 103}, + {743, 95}, + {796, 86}, + {849, 77}, + {902, 65}, + {955, 49}, + {1008, 17}, + {1020, 0} //safety +}; + +#elif THERMISTORBED == 3 //mendel-parts +#define BNUMTEMPS 28 +const short bedtemptable[BNUMTEMPS][2] = { + {1,864}, + {21,300}, + {25,290}, + {29,280}, + {33,270}, + {39,260}, + {46,250}, + {54,240}, + {64,230}, + {75,220}, + {90,210}, + {107,200}, + {128,190}, + {154,180}, + {184,170}, + {221,160}, + {265,150}, + {316,140}, + {375,130}, + {441,120}, + {513,110}, + {588,100}, + {734,80}, + {856,60}, + {938,40}, + {986,20}, + {1008,0}, + {1018,-20} + }; +#else +#error No bed thermistor table specified + +#endif + + +#endif //if THERMISTORHEATER==THERMISTORBED +#endif //THERMISTORTABLES_H_ From c8767013f10a9b4022e2c260bd0e0d7769a6b1e2 Mon Sep 17 00:00:00 2001 From: kliment Date: Tue, 5 Jul 2011 23:29:45 +0200 Subject: [PATCH 35/45] Fix RAMPS 1.3 number --- Sprinter/Configuration.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprinter/Configuration.h b/Sprinter/Configuration.h index 54ea8ea..39fe1f0 100644 --- a/Sprinter/Configuration.h +++ b/Sprinter/Configuration.h @@ -6,7 +6,7 @@ // The following define selects which electronics board you have. Please choose the one that matches your setup // MEGA/RAMPS up to 1.2 = 3, -// RAMPS 1.3 = 63 +// RAMPS 1.3 = 33 // Gen6 = 5, // Sanguinololu up to 1.1 = 6 // Sanguinololu 1.2 and above = 62 From 709a84956be02e91e12e6dc368d92ebb936630fc Mon Sep 17 00:00:00 2001 From: kliment Date: Wed, 6 Jul 2011 13:34:08 +0200 Subject: [PATCH 36/45] Documentation improvements in Configuration.h --- Sprinter/Configuration.h | 92 ++++++++++++++++++---------------------- 1 file changed, 42 insertions(+), 50 deletions(-) diff --git a/Sprinter/Configuration.h b/Sprinter/Configuration.h index 39fe1f0..de2af79 100644 --- a/Sprinter/Configuration.h +++ b/Sprinter/Configuration.h @@ -1,10 +1,9 @@ #ifndef CONFIGURATION_H #define CONFIGURATION_H +// BASIC SETTINGS: select your board type, thermistor type, axis scaling, and endstop configuration -//BASIC SETTINGS: select your board type, thermistor type, axis scaling, and endstop configuration - -// The following define selects which electronics board you have. Please choose the one that matches your setup +//// The following define selects which electronics board you have. Please choose the one that matches your setup // MEGA/RAMPS up to 1.2 = 3, // RAMPS 1.3 = 33 // Gen6 = 5, @@ -12,58 +11,54 @@ // Sanguinololu 1.2 and above = 62 #define MOTHERBOARD 3 -//Thermistor settings: +//// Thermistor settings: // 1 is 100k thermistor // 2 is 200k thermistor // 3 is mendel-parts thermistor #define THERMISTORHEATER 1 #define THERMISTORBED 1 - -//Calibration variables -//X, Y, Z, E steps per unit - Metric Prusa Mendel with Wade extruder: +//// Calibration variables +// X, Y, Z, E steps per unit - Metric Prusa Mendel with Wade extruder: float axis_steps_per_unit[] = {80, 80, 3200/1.25,700}; -//Metric Prusa Mendel with Makergear geared stepper extruder: +// Metric Prusa Mendel with Makergear geared stepper extruder: //float axis_steps_per_unit[] = {80,80,3200/1.25,1380}; - -////Endstop Settings +//// Endstop Settings #define ENDSTOPPULLUPS 1 // Comment this out (using // at the start of the line) to disable the endstop pullup resistors -//The pullups are needed if you directly connect a mechanical endswitch between the signal and ground pins. +// The pullups are needed if you directly connect a mechanical endswitch between the signal and ground pins. const bool ENDSTOPS_INVERTING = false; //set to true to invert the logic of the endstops -//This determines the communication speed of the printer +// This determines the communication speed of the printer #define BAUDRATE 115200 -//Comment out (using // at the start of the line) to disable SD support: +// Comment out (using // at the start of the line) to disable SD support: #define SDSUPPORT 1 - - - -//ADVANCED SETTINGS - to tweak parameters +//// ADVANCED SETTINGS - to tweak parameters #include "thermistortables.h" -//For Inverting Stepper Enable Pins (Active Low) use 0, Non Inverting (Active High) use 1 +// For Inverting Stepper Enable Pins (Active Low) use 0, Non Inverting (Active High) use 1 const bool X_ENABLE_ON = 0; const bool Y_ENABLE_ON = 0; const bool Z_ENABLE_ON = 0; const bool E_ENABLE_ON = 0; -//Disables axis when it's not being used. +// Disables axis when it's not being used. const bool DISABLE_X = false; const bool DISABLE_Y = false; const bool DISABLE_Z = true; const bool DISABLE_E = false; +// Inverting axis direction const bool INVERT_X_DIR = false; const bool INVERT_Y_DIR = false; const bool INVERT_Z_DIR = true; const bool INVERT_E_DIR = false; -//ENDSTOP SETTINGS: +//// ENDSTOP SETTINGS: // Sets direction of endstops when homing; 1=MAX, -1=MIN const int X_HOME_DIR = -1; const int Y_HOME_DIR = -1; @@ -75,36 +70,34 @@ const int X_MAX_LENGTH = 200; const int Y_MAX_LENGTH = 200; const int Z_MAX_LENGTH = 100; - -//MOVEMENT SETTINGS +//// MOVEMENT SETTINGS const int NUM_AXIS = 4; // The axis order in all axis related arrays is X, Y, Z, E float max_feedrate[] = {200000, 200000, 240, 500000}; bool axis_relative_modes[] = {false, false, false, false}; - -//Min step delay in microseconds. If you are experiencing missing steps, try to raise the delay microseconds, but be aware this +// Min step delay in microseconds. If you are experiencing missing steps, try to raise the delay microseconds, but be aware this // If you enable this, make sure STEP_DELAY_RATIO is disabled. //#define STEP_DELAY_MICROS 1 -//Step delay over interval ratio. If you are still experiencing missing steps, try to uncomment the following line, but be aware this -//If you enable this, make sure STEP_DELAY_MICROS is disabled. +// Step delay over interval ratio. If you are still experiencing missing steps, try to uncomment the following line, but be aware this +// If you enable this, make sure STEP_DELAY_MICROS is disabled. //#define STEP_DELAY_RATIO 0.25 -//Comment this to disable ramp acceleration +// Comment this to disable ramp acceleration #define RAMP_ACCELERATION 1 -//Acceleration settings +//// Acceleration settings #ifdef RAMP_ACCELERATION -//X, Y, Z, E maximum start speed for accelerated moves. E default values are good for skeinforge 40+, for older versions raise them a lot. +// X, Y, Z, E maximum start speed for accelerated moves. E default values are good for skeinforge 40+, for older versions raise them a lot. float max_start_speed_units_per_second[] = {25.0,25.0,0.2,10.0}; long max_acceleration_units_per_sq_second[] = {1000,1000,50,10000}; // X, Y, Z and E max acceleration in mm/s^2 for printing moves or retracts long max_travel_acceleration_units_per_sq_second[] = {500,500,50}; // X, Y, Z max acceleration in mm/s^2 for travel moves #endif -// AD595 THERMOCOUPLE SUPPORT UNTESTED... USE WITH CAUTION!!!! +//// AD595 THERMOCOUPLE SUPPORT UNTESTED... USE WITH CAUTION!!!! -//PID settings: -//Uncomment the following line to enable PID support. This is untested and could be disastrous. Be careful. +//// PID settings: +// Uncomment the following line to enable PID support. This is untested and could be disastrous. Be careful. //#define PIDTEMP 1 #ifdef PIDTEMP #define PID_MAX 255 // limits current to nozzle @@ -114,35 +107,36 @@ long max_travel_acceleration_units_per_sq_second[] = {500,500,50}; // X, Y, Z ma #define PID_DGAIN 100 //100 is 1.0 #endif -//How often should the heater check for new temp readings, in milliseconds +// How often should the heater check for new temp readings, in milliseconds #define HEATER_CHECK_INTERVAL 500 #define BED_CHECK_INTERVAL 5000 -//Comment the following line to enable heat management during acceleration +// Comment the following line to enable heat management during acceleration #define DISABLE_CHECK_DURING_ACC #ifndef DISABLE_CHECK_DURING_ACC - //Uncomment the following line to disable heat management during the move + // Uncomment the following line to disable heat management during moves //#define DISABLE_CHECK_DURING_MOVE #endif -//Uncomment the following line to disable heat management during travel moves (and extruder-only moves, eg: retracts), strongly recommended if you are missing steps mid print. -//Probably this should remain commented if are using PID. -//It also defines the max milliseconds interval after which a travel move is not considered so for the sake of this feature. +// Uncomment the following line to disable heat management during travel moves (and extruder-only moves, eg: retracts), strongly recommended if you are missing steps mid print. +// Probably this should remain commented if are using PID. +// It also defines the max milliseconds interval after which a travel move is not considered so for the sake of this feature. #define DISABLE_CHECK_DURING_TRAVEL 1000 -//Experimental temperature smoothing - only uncomment this if your temp readings are noisy +//// Temperature smoothing - only uncomment this if your temp readings are noisy //#define SMOOTHING 1 //#define SMOOTHFACTOR 16 //best to use a power of two here - determines how many values are averaged together by the smoothing algorithm -//Experimental watchdog and minimal temp -//The watchdog waits for the watchperiod in milliseconds whenever an M104 or M109 increases the target temperature -//If the temperature has not increased at the end of that period, the target temperature is set to zero. It can be reset with another M104/M109 +//// Experimental watchdog and minimal temp +// The watchdog waits for the watchperiod in milliseconds whenever an M104 or M109 increases the target temperature +// If the temperature has not increased at the end of that period, the target temperature is set to zero. It can be reset with another M104/M109 //#define WATCHPERIOD 5000 //5 seconds -//The minimal temperature defines the temperature below which the heater will not be enabled + +//// The minimal temperature defines the temperature below which the heater will not be enabled #define MINTEMP 5 -//Experimental max temp -//When temperature exceeds max temp, your bot will halt. -//This feature exists to protect your hotend from overheating accidentally, but *NOT* from thermistor short/failure! -//You should use MINTEMP for thermistor short/failure protection. +//// Experimental max temp +// When temperature exceeds max temp, your heater will be switched off. +// This feature exists to protect your hotend from overheating accidentally, but *NOT* from thermistor short/failure! +// You should use MINTEMP for thermistor short/failure protection. #define MAXTEMP 275 // Select one of these only to define how the nozzle temp is read. @@ -154,9 +148,7 @@ long max_travel_acceleration_units_per_sq_second[] = {500,500,50}; // X, Y, Z ma #define BED_USES_THERMISTOR //#define BED_USES_AD595 - - -//Uncomment the following line to enable debugging. You can better control debugging below the following line +// Uncomment the following line to enable debugging. You can better control debugging below the following line //#define DEBUG #ifdef DEBUG //#define DEBUG_PREPARE_MOVE //Enable this to debug prepare_move() function From 8dafab9b9a51ae91e1a5c5f5f03e7e2d6ba5be01 Mon Sep 17 00:00:00 2001 From: kliment Date: Wed, 6 Jul 2011 14:22:06 +0200 Subject: [PATCH 37/45] Single definition temp tables --- Sprinter/thermistortables.h | 181 +++++++----------------------------- 1 file changed, 33 insertions(+), 148 deletions(-) diff --git a/Sprinter/thermistortables.h b/Sprinter/thermistortables.h index e21b647..6c583af 100644 --- a/Sprinter/thermistortables.h +++ b/Sprinter/thermistortables.h @@ -1,11 +1,11 @@ #ifndef THERMISTORTABLES_H_ #define THERMISTORTABLES_H_ -#if THERMISTORHEATER == 1 //100k bed thermistor +#if (THERMISTORHEATER == 1) || (THERMISTORBED == 1) //100k bed thermistor -#define NUMTEMPS 61 -const short temptable[NUMTEMPS][2] = { +#define NUMTEMPS_1 61 +const short temptable_1[NUMTEMPS_1][2] = { { 23 , 300 }, { 25 , 295 }, { 27 , 290 }, @@ -68,10 +68,10 @@ const short temptable[NUMTEMPS][2] = { { 1004 , 5 }, { 1008 , 0 } //safety }; - -#elif THERMISTORHEATER == 2 //200k bed thermistor -#define NUMTEMPS 21 -const short temptable[NUMTEMPS][2] = { +#endif +#if (THERMISTORHEATER == 2) || (THERMISTORBED == 2) //200k bed thermistor +#define NUMTEMPS_2 21 +const short temptable_2[NUMTEMPS_2][2] = { {1, 848}, {54, 275}, {107, 228}, @@ -95,9 +95,10 @@ const short temptable[NUMTEMPS][2] = { {1020, 0} //safety }; -#elif THERMISTORHEATER == 3 //mendel-parts -#define NUMTEMPS 28 -const short temptable[NUMTEMPS][2] = { +#endif +#if (THERMISTORHEATER == 3) || (THERMISTORBED == 3) //mendel-parts +#define NUMTEMPS_3 28 +const short temptable_3[NUMTEMPS_3][2] = { {1,864}, {21,300}, {25,290}, @@ -128,147 +129,31 @@ const short temptable[NUMTEMPS][2] = { {1018,-20} }; -#else -#error No thermistor table specified - #endif - -#if THERMISTORHEATER==THERMISTORBED -#define BNUMTEMPS NUMTEMPS -#define bedtemptable temptable -#else -#if THERMISTORBED == 1 //100k bed thermistor - - -#define BNUMTEMPS 61 -const short bedtemptable[BNUMTEMPS][2] = { -{ 23 , 300 }, -{ 25 , 295 }, -{ 27 , 290 }, -{ 28 , 285 }, -{ 31 , 280 }, -{ 33 , 275 }, -{ 35 , 270 }, -{ 38 , 265 }, -{ 41 , 260 }, -{ 44 , 255 }, -{ 48 , 250 }, -{ 52 , 245 }, -{ 56 , 240 }, -{ 61 , 235 }, -{ 66 , 230 }, -{ 71 , 225 }, -{ 78 , 220 }, -{ 84 , 215 }, -{ 92 , 210 }, -{ 100 , 205 }, -{ 109 , 200 }, -{ 120 , 195 }, -{ 131 , 190 }, -{ 143 , 185 }, -{ 156 , 180 }, -{ 171 , 175 }, -{ 187 , 170 }, -{ 205 , 165 }, -{ 224 , 160 }, -{ 245 , 155 }, -{ 268 , 150 }, -{ 293 , 145 }, -{ 320 , 140 }, -{ 348 , 135 }, -{ 379 , 130 }, -{ 411 , 125 }, -{ 445 , 120 }, -{ 480 , 115 }, -{ 516 , 110 }, -{ 553 , 105 }, -{ 591 , 100 }, -{ 628 , 95 }, -{ 665 , 90 }, -{ 702 , 85 }, -{ 737 , 80 }, -{ 770 , 75 }, -{ 801 , 70 }, -{ 830 , 65 }, -{ 857 , 60 }, -{ 881 , 55 }, -{ 903 , 50 }, -{ 922 , 45 }, -{ 939 , 40 }, -{ 954 , 35 }, -{ 966 , 30 }, -{ 977 , 25 }, -{ 985 , 20 }, -{ 993 , 15 }, -{ 999 , 10 }, -{ 1004 , 5 }, -{ 1008 , 0 } //safety -}; - -#elif THERMISTORBED == 2 //200k bed thermistor -#define BNUMTEMPS 21 -const short bedtemptable[BNUMTEMPS][2] = { - {1, 848}, - {54, 275}, - {107, 228}, - {160, 202}, - {213, 185}, - {266, 171}, - {319, 160}, - {372, 150}, - {425, 141}, - {478, 133}, - {531, 125}, - {584, 118}, - {637, 110}, - {690, 103}, - {743, 95}, - {796, 86}, - {849, 77}, - {902, 65}, - {955, 49}, - {1008, 17}, - {1020, 0} //safety -}; - -#elif THERMISTORBED == 3 //mendel-parts -#define BNUMTEMPS 28 -const short bedtemptable[BNUMTEMPS][2] = { - {1,864}, - {21,300}, - {25,290}, - {29,280}, - {33,270}, - {39,260}, - {46,250}, - {54,240}, - {64,230}, - {75,220}, - {90,210}, - {107,200}, - {128,190}, - {154,180}, - {184,170}, - {221,160}, - {265,150}, - {316,140}, - {375,130}, - {441,120}, - {513,110}, - {588,100}, - {734,80}, - {856,60}, - {938,40}, - {986,20}, - {1008,0}, - {1018,-20} - }; -#else +#if THERMISTORHEATER == 1 +#define NUMTEMPS NUMTEMPS_1 +#define temptable temptable_1 +#elif THERMISTORHEATER == 2 +#define NUMTEMPS NUMTEMPS_2 +#define temptable temptable_2 +#elif THERMISTORHEATER == 3 +#define NUMTEMPS NUMTEMPS_3 +#define temptable temptable_3 +#elif defined HEATER_USES_THERMISTOR +#error No heater thermistor table specified +#endif +#if THERMISTORBED == 1 +#define BNUMTEMPS NUMTEMPS_1 +#define bedtemptable temptable_1 +#elif THERMISTORBED == 2 +#define BNUMTEMPS NUMTEMPS_2 +#define bedtemptable temptable_2 +#elif THERMISTORBED == 3 +#define BNUMTEMPS NUMTEMPS_3 +#define bedtemptable temptable_3 +#elif defined BED_USES_THERMISTOR #error No bed thermistor table specified - #endif - -#endif //if THERMISTORHEATER==THERMISTORBED #endif //THERMISTORTABLES_H_ From e5cb83f4aa28cdfc6ff393463ff445869db3502d Mon Sep 17 00:00:00 2001 From: Ahmet Cem TURAN Date: Wed, 6 Jul 2011 05:59:27 -0700 Subject: [PATCH 38/45] Put some notes in for gen6 users.. --- Sprinter/Configuration.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sprinter/Configuration.h b/Sprinter/Configuration.h index de2af79..8bccfcc 100644 --- a/Sprinter/Configuration.h +++ b/Sprinter/Configuration.h @@ -80,7 +80,7 @@ bool axis_relative_modes[] = {false, false, false, false}; //#define STEP_DELAY_MICROS 1 // Step delay over interval ratio. If you are still experiencing missing steps, try to uncomment the following line, but be aware this -// If you enable this, make sure STEP_DELAY_MICROS is disabled. +// If you enable this, make sure STEP_DELAY_MICROS is disabled. (except for Gen6: both need to be enabled.) //#define STEP_DELAY_RATIO 0.25 // Comment this to disable ramp acceleration @@ -121,7 +121,7 @@ long max_travel_acceleration_units_per_sq_second[] = {500,500,50}; // X, Y, Z ma // It also defines the max milliseconds interval after which a travel move is not considered so for the sake of this feature. #define DISABLE_CHECK_DURING_TRAVEL 1000 -//// Temperature smoothing - only uncomment this if your temp readings are noisy +//// Temperature smoothing - only uncomment this if your temp readings are noisy (Gen6 without EvdZ's 5V hack) //#define SMOOTHING 1 //#define SMOOTHFACTOR 16 //best to use a power of two here - determines how many values are averaged together by the smoothing algorithm From bdc7c47ad280c193e5ba53bc6cc8bf10ac081977 Mon Sep 17 00:00:00 2001 From: kliment Date: Wed, 6 Jul 2011 15:13:23 +0200 Subject: [PATCH 39/45] Make M190 not break flow control --- Sprinter/Sprinter.pde | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Sprinter/Sprinter.pde b/Sprinter/Sprinter.pde index 733aec8..f00ff11 100644 --- a/Sprinter/Sprinter.pde +++ b/Sprinter/Sprinter.pde @@ -716,9 +716,7 @@ inline void process_commands() { tt=analog2temp(current_raw); Serial.print("T:"); - Serial.println( tt ); - Serial.print("ok T:"); - Serial.print( tt ); + Serial.print( tt ); Serial.print(" B:"); Serial.println( analog2temp(current_bed_raw) ); codenum = millis(); From b247ffd7dbf4da06b8708ae2228cc4396828d333 Mon Sep 17 00:00:00 2001 From: kliment Date: Wed, 6 Jul 2011 21:27:52 +0200 Subject: [PATCH 40/45] Fix sanguinololu version define --- Sprinter/pins.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Sprinter/pins.h b/Sprinter/pins.h index dfd12b5..b1216a0 100644 --- a/Sprinter/pins.h +++ b/Sprinter/pins.h @@ -427,7 +427,7 @@ ****************************************************************************************/ #if MOTHERBOARD == 62 #define MOTHERBOARD 6 -#define +#define SANGUINOLOLU_V_1_2 #endif #if MOTHERBOARD == 6 #define KNOWN_BOARD 1 @@ -436,7 +436,6 @@ #endif // comment the following line for Sanguinololu v1.1 or earlier. -#define SANGUINOLOLU_V_1_2 #define X_STEP_PIN 15 From 88b8df4a860802e398c5b82b2e640257db40e7a8 Mon Sep 17 00:00:00 2001 From: kliment Date: Wed, 6 Jul 2011 21:30:42 +0200 Subject: [PATCH 41/45] Documentation fix - delete misleading comment --- Sprinter/pins.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/Sprinter/pins.h b/Sprinter/pins.h index b1216a0..1bd6702 100644 --- a/Sprinter/pins.h +++ b/Sprinter/pins.h @@ -435,9 +435,6 @@ #error Oops! Make sure you have 'Sanguino' selected from the 'Tools -> Boards' menu. #endif -// comment the following line for Sanguinololu v1.1 or earlier. - - #define X_STEP_PIN 15 #define X_DIR_PIN 21 #define X_MIN_PIN 18 From f4944f6d8ef6bb51ccf632fff6d80934f7b4e5cb Mon Sep 17 00:00:00 2001 From: kliment Date: Thu, 7 Jul 2011 10:34:24 +0200 Subject: [PATCH 42/45] Fix broken #ifdef Fix declarations in .h file --- Sprinter/Sprinter.h | 3 ++- Sprinter/Sprinter.pde | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Sprinter/Sprinter.h b/Sprinter/Sprinter.h index 4e3c7ea..31d4b69 100644 --- a/Sprinter/Sprinter.h +++ b/Sprinter/Sprinter.h @@ -18,7 +18,8 @@ void ClearToSend(); void get_coordinates(); void prepare_move(); -void linear_move(unsigned long x_steps_remaining, unsigned long y_steps_remaining, unsigned long z_steps_remaining, unsigned long e_steps_remaining); +void linear_move(unsigned long steps_remaining[]); +void do_step_update_micros(int axis); void disable_x(); void disable_y(); void disable_z(); diff --git a/Sprinter/Sprinter.pde b/Sprinter/Sprinter.pde index f00ff11..ea854cb 100644 --- a/Sprinter/Sprinter.pde +++ b/Sprinter/Sprinter.pde @@ -450,7 +450,7 @@ inline void process_commands() { case 0: // G0 -> G1 case 1: // G1 - #ifdef DISABLE_CHECK_DURING_ACC || DISABLE_CHECK_DURING_MOVE || DISABLE_CHECK_DURING_TRAVEL + #if (defined DISABLE_CHECK_DURING_ACC) || (defined DISABLE_CHECK_DURING_MOVE) || (defined DISABLE_CHECK_DURING_TRAVEL) manage_heater(); #endif get_coordinates(); // For X Y Z E F From 57f82b5a5b566025ff0c6da6728dbc4380b937cd Mon Sep 17 00:00:00 2001 From: kliment Date: Thu, 7 Jul 2011 16:32:10 +0200 Subject: [PATCH 43/45] Add missing accel per sq second for E --- Sprinter/Configuration.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprinter/Configuration.h b/Sprinter/Configuration.h index 8bccfcc..319c839 100644 --- a/Sprinter/Configuration.h +++ b/Sprinter/Configuration.h @@ -91,7 +91,7 @@ bool axis_relative_modes[] = {false, false, false, false}; // X, Y, Z, E maximum start speed for accelerated moves. E default values are good for skeinforge 40+, for older versions raise them a lot. float max_start_speed_units_per_second[] = {25.0,25.0,0.2,10.0}; long max_acceleration_units_per_sq_second[] = {1000,1000,50,10000}; // X, Y, Z and E max acceleration in mm/s^2 for printing moves or retracts -long max_travel_acceleration_units_per_sq_second[] = {500,500,50}; // X, Y, Z max acceleration in mm/s^2 for travel moves +long max_travel_acceleration_units_per_sq_second[] = {500,500,50,500}; // X, Y, Z max acceleration in mm/s^2 for travel moves #endif //// AD595 THERMOCOUPLE SUPPORT UNTESTED... USE WITH CAUTION!!!! From d98555ffb0e94ece92311dcf2ff3a2ff13d9e3d4 Mon Sep 17 00:00:00 2001 From: kliment Date: Thu, 7 Jul 2011 16:34:34 +0200 Subject: [PATCH 44/45] Fix makefile and header to compile from command line --- Sprinter/Makefile | 6 +++--- Sprinter/Sprinter.h | 8 +++----- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/Sprinter/Makefile b/Sprinter/Makefile index 618b384..0f9b5b7 100644 --- a/Sprinter/Makefile +++ b/Sprinter/Makefile @@ -33,7 +33,7 @@ # $Id$ TARGET = $(notdir $(CURDIR)) -INSTALL_DIR = /home/chris/arduino-0022 +INSTALL_DIR = ../../arduino22/arduino-0022/ UPLOAD_RATE = 38400 AVRDUDE_PROGRAMMER = stk500v1 PORT = /dev/ttyUSB0 @@ -52,7 +52,7 @@ ARDUINO = $(INSTALL_DIR)/hardware/arduino/cores/arduino AVR_TOOLS_PATH = /usr/bin SRC = $(ARDUINO)/pins_arduino.c $(ARDUINO)/wiring.c \ $(ARDUINO)/wiring_analog.c $(ARDUINO)/wiring_digital.c \ -$(ARDUINO)/wiring_pulse.c $(ARDUINO)/wiring_serial.c \ +$(ARDUINO)/wiring_pulse.c \ $(ARDUINO)/wiring_shift.c $(ARDUINO)/WInterrupts.c CXXSRC = $(ARDUINO)/HardwareSerial.cpp $(ARDUINO)/WMath.cpp \ $(ARDUINO)/Print.cpp ./SdFile.cpp ./SdVolume.cpp ./Sd2Card.cpp @@ -142,7 +142,7 @@ applet_files: $(TARGET).pde test -d applet || mkdir applet echo '#include "WProgram.h"' > applet/$(TARGET).cpp cat $(TARGET).pde >> applet/$(TARGET).cpp - cat $(ARDUINO)/main.cxx >> applet/$(TARGET).cpp + cat $(ARDUINO)/main.cpp >> applet/$(TARGET).cpp elf: applet/$(TARGET).elf hex: applet/$(TARGET).hex diff --git a/Sprinter/Sprinter.h b/Sprinter/Sprinter.h index 31d4b69..7a4b8a9 100644 --- a/Sprinter/Sprinter.h +++ b/Sprinter/Sprinter.h @@ -1,7 +1,8 @@ // Tonokip RepRap firmware rewrite based off of Hydra-mmm firmware. // Licence: GPL #include - +extern "C" void __cxa_pure_virtual(); +void __cxa_pure_virtual(){}; void get_command(); void process_commands(); @@ -28,10 +29,7 @@ void enable_x(); void enable_y(); void enable_z(); void enable_e(); -void do_x_step(); -void do_y_step(); -void do_z_step(); -void do_e_step(); +void do_step(int axis); void kill(byte debug); From 3e28c2e8f00a3440873c806f780641de0ed5190f Mon Sep 17 00:00:00 2001 From: kliment Date: Sat, 9 Jul 2011 10:35:30 +0200 Subject: [PATCH 45/45] Change backoff during homing to 5mm. --- Sprinter/Sprinter.pde | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Sprinter/Sprinter.pde b/Sprinter/Sprinter.pde index ea854cb..4ce93fc 100644 --- a/Sprinter/Sprinter.pde +++ b/Sprinter/Sprinter.pde @@ -479,14 +479,14 @@ inline void process_commands() home_all_axis = !((code_seen(axis_codes[0])) || (code_seen(axis_codes[1])) || (code_seen(axis_codes[2]))); if((home_all_axis) || (code_seen('X'))) { - if((X_MIN_PIN > -1 && X_HOME_DIR==-1) || (X_MAX_PIN > -1 && X_HOME_DIR==1)) { + #if ((X_MIN_PIN > -1 && X_HOME_DIR==-1) || (X_MAX_PIN > -1 && X_HOME_DIR==1)) current_position[0] = 0; destination[0] = 1.5 * X_MAX_LENGTH * X_HOME_DIR; feedrate = max_start_speed_units_per_second[0] * 60; prepare_move(); current_position[0] = 0; - destination[0] = -1 * X_HOME_DIR; + destination[0] = -5 * X_HOME_DIR; prepare_move(); destination[0] = 10 * X_HOME_DIR; @@ -495,18 +495,18 @@ inline void process_commands() current_position[0] = 0; destination[0] = 0; feedrate = 0; - } + #endif } if((home_all_axis) || (code_seen('X'))) { - if((Y_MIN_PIN > -1 && Y_HOME_DIR==-1) || (Y_MAX_PIN > -1 && Y_HOME_DIR==1)) { + #if ((Y_MIN_PIN > -1 && Y_HOME_DIR==-1) || (Y_MAX_PIN > -1 && Y_HOME_DIR==1)) current_position[1] = 0; destination[1] = 1.5 * Y_MAX_LENGTH * Y_HOME_DIR; feedrate = max_start_speed_units_per_second[1] * 60; prepare_move(); current_position[1] = 0; - destination[1] = -1 * Y_HOME_DIR; + destination[1] = -5 * Y_HOME_DIR; prepare_move(); destination[1] = 10 * Y_HOME_DIR; @@ -515,18 +515,18 @@ inline void process_commands() current_position[1] = 0; destination[1] = 0; feedrate = 0; - } + #endif } if((home_all_axis) || (code_seen('X'))) { - if((Z_MIN_PIN > -1 && Z_HOME_DIR==-1) || (Z_MAX_PIN > -1 && Z_HOME_DIR==1)) { + #if ((Z_MIN_PIN > -1 && Z_HOME_DIR==-1) || (Z_MAX_PIN > -1 && Z_HOME_DIR==1)) current_position[2] = 0; destination[2] = 1.5 * Z_MAX_LENGTH * Z_HOME_DIR; feedrate = max_feedrate[2]/2; prepare_move(); current_position[2] = 0; - destination[2] = -1 * Z_HOME_DIR; + destination[2] = -5 * Z_HOME_DIR; prepare_move(); destination[2] = 10 * Z_HOME_DIR; @@ -535,7 +535,7 @@ inline void process_commands() current_position[2] = 0; destination[2] = 0; feedrate = 0; - } + #endif } feedrate = saved_feedrate;