Commit 0a201721 authored by MagoKimbra's avatar MagoKimbra

Same Fix

parent 48e1664e
...@@ -4,6 +4,10 @@ ...@@ -4,6 +4,10 @@
*/ */
#ifndef CONDITIONALS_H #ifndef CONDITIONALS_H
#ifndef M_PI
#define M_PI 3.1415926536
#endif
#ifndef CONFIGURATION_LCD // Get the LCD defines which are needed first #ifndef CONFIGURATION_LCD // Get the LCD defines which are needed first
#define CONFIGURATION_LCD #define CONFIGURATION_LCD
...@@ -286,7 +290,7 @@ ...@@ -286,7 +290,7 @@
* Advance calculated values * Advance calculated values
*/ */
#ifdef ADVANCE #ifdef ADVANCE
#define EXTRUSION_AREA (0.25 * D_FILAMENT * D_FILAMENT * 3.14159) #define EXTRUSION_AREA (0.25 * D_FILAMENT * D_FILAMENT * M_PI)
#define STEPS_PER_CUBIC_MM_E (axis_steps_per_unit[E_AXIS] / EXTRUSION_AREA) #define STEPS_PER_CUBIC_MM_E (axis_steps_per_unit[E_AXIS] / EXTRUSION_AREA)
#endif #endif
...@@ -398,8 +402,6 @@ ...@@ -398,8 +402,6 @@
#define HAS_TEMP_2 (defined(TEMP_2_PIN) && (TEMP_2_PIN >= 0) && TEMP_SENSOR_2) #define HAS_TEMP_2 (defined(TEMP_2_PIN) && (TEMP_2_PIN >= 0) && TEMP_SENSOR_2)
#define HAS_TEMP_3 (defined(TEMP_3_PIN) && (TEMP_3_PIN >= 0) && TEMP_SENSOR_3) #define HAS_TEMP_3 (defined(TEMP_3_PIN) && (TEMP_3_PIN >= 0) && TEMP_SENSOR_3)
#define HAS_TEMP_BED (defined(TEMP_BED_PIN) && (TEMP_BED_PIN >= 0) && TEMP_SENSOR_BED) #define HAS_TEMP_BED (defined(TEMP_BED_PIN) && (TEMP_BED_PIN >= 0) && TEMP_SENSOR_BED)
#define HAS_FILAMENT_SENSOR (defined(FILAMENT_SENSOR) && defined(FILWIDTH_PIN) && FILWIDTH_PIN >= 0)
#define HAS_POWER_CONSUMPTION_SENSOR (defined(POWER_CONSUMPTION) && defined(POWER_CONSUMPTION_PIN) && POWER_CONSUMPTION_PIN >= 0)
#define HAS_HEATER_0 (defined(HEATER_0_PIN) && HEATER_0_PIN >= 0) #define HAS_HEATER_0 (defined(HEATER_0_PIN) && HEATER_0_PIN >= 0)
#define HAS_HEATER_1 (defined(HEATER_1_PIN) && HEATER_1_PIN >= 0) #define HAS_HEATER_1 (defined(HEATER_1_PIN) && HEATER_1_PIN >= 0)
#define HAS_HEATER_2 (defined(HEATER_2_PIN) && HEATER_2_PIN >= 0) #define HAS_HEATER_2 (defined(HEATER_2_PIN) && HEATER_2_PIN >= 0)
...@@ -438,8 +440,10 @@ ...@@ -438,8 +440,10 @@
#endif #endif
/** /**
* Shorthand for sensor test for ultralcd.cpp, dogm_lcd_implementation.h, ultralcd_implementation_hitachi_HD44780.h * Shorthand for filament sensor and power sensor for ultralcd.cpp, dogm_lcd_implementation.h, ultralcd_implementation_hitachi_HD44780.h
*/ */
#define HAS_FILAMENT_SENSOR (defined(FILAMENT_SENSOR) && defined(FILWIDTH_PIN) && FILWIDTH_PIN >= 0)
#define HAS_POWER_CONSUMPTION_SENSOR (defined(POWER_CONSUMPTION) && defined(POWER_CONSUMPTION_PIN) && POWER_CONSUMPTION_PIN >= 0)
#define HAS_LCD_FILAMENT_SENSOR (HAS_FILAMENT_SENSOR && defined(FILAMENT_LCD_DISPLAY)) #define HAS_LCD_FILAMENT_SENSOR (HAS_FILAMENT_SENSOR && defined(FILAMENT_LCD_DISPLAY))
#define HAS_LCD_POWER_SENSOR (HAS_POWER_CONSUMPTION_SENSOR && defined(POWER_CONSUMPTION_LCD_DISPLAY)) #define HAS_LCD_POWER_SENSOR (HAS_POWER_CONSUMPTION_SENSOR && defined(POWER_CONSUMPTION_LCD_DISPLAY))
......
...@@ -649,5 +649,12 @@ void Config_PrintSettings() ...@@ -649,5 +649,12 @@ void Config_PrintSettings()
SERIAL_ECHOLNPGM("Filament settings: Disabled"); SERIAL_ECHOLNPGM("Filament settings: Disabled");
} }
#endif //FWRETRACT #endif //FWRETRACT
#if defined(POWER_CONSUMPTION) && defined(STORE_CONSUMPTION)
SERIAL_ECHO_START;
SERIAL_ECHOLNPGM("Power consumation:");
SERIAL_ECHO_START;
SERIAL_ECHOPAIR(" W/h:", power_consumption_hour);
#endif
} }
#endif //!DISABLE_M503 #endif //!DISABLE_M503
...@@ -30,6 +30,8 @@ ...@@ -30,6 +30,8 @@
#define BIT(b) (1<<(b)) #define BIT(b) (1<<(b))
#define TEST(n,b) (((n)&BIT(b))!=0) #define TEST(n,b) (((n)&BIT(b))!=0)
#define RADIANS(d) ((d)*M_PI/180.0)
#define DEGREES(r) ((d)*180.0/M_PI)
// Arduino < 1.0.0 does not define this, so we need to do it ourselves // Arduino < 1.0.0 does not define this, so we need to do it ourselves
#ifndef analogInputToDigitalPin #ifndef analogInputToDigitalPin
......
...@@ -341,7 +341,7 @@ uint8_t debugLevel = 0; ...@@ -341,7 +341,7 @@ uint8_t debugLevel = 0;
#if HAS_POWER_CONSUMPTION_SENSOR #if HAS_POWER_CONSUMPTION_SENSOR
float power_consumption_meas = 0.0; float power_consumption_meas = 0.0;
unsigned long power_consumption_hour = 0; unsigned long power_consumption_hour;
unsigned long startpower = 0; unsigned long startpower = 0;
unsigned long stoppower = 0; unsigned long stoppower = 0;
#endif #endif
...@@ -930,17 +930,23 @@ void get_command() ...@@ -930,17 +930,23 @@ void get_command()
if(card.eof()){ if(card.eof()){
SERIAL_PROTOCOLLNPGM(MSG_FILE_PRINTED); SERIAL_PROTOCOLLNPGM(MSG_FILE_PRINTED);
stoptime = millis(); stoptime = millis();
#if HAS_POWER_CONSUMPTION_SENSOR
stoppower = power_consumption_hour-startpower; stoppower = power_consumption_hour-startpower;
#endif
char time[30]; char time[30];
unsigned long t = (stoptime-starttime) / 1000; unsigned long t = (stoptime-starttime) / 1000;
int hours, minutes; int hours, minutes;
minutes=(t/60)%60; minutes=(t/60)%60;
hours=t/60/60; hours=t/60/60;
#if HAS_POWER_CONSUMPTION_SENSOR #if HAS_POWER_CONSUMPTION_SENSOR
sprintf_P(time, PSTR("%i "MSG_END_HOUR" %i "MSG_END_MINUTE" %i Wh"), hours, minutes, stoppower); sprintf_P(time, PSTR("%i "MSG_END_HOUR" %i "MSG_END_MINUTE" %i Wh"), hours, minutes, stoppower);
#else #else
sprintf_P(time, PSTR("%i "MSG_END_HOUR" %i "MSG_END_MINUTE), hours, minutes); sprintf_P(time, PSTR("%i "MSG_END_HOUR" %i "MSG_END_MINUTE), hours, minutes);
#endif #endif
SERIAL_ECHO_START; SERIAL_ECHO_START;
SERIAL_ECHOLN(time); SERIAL_ECHOLN(time);
lcd_setstatus(time, true); lcd_setstatus(time, true);
...@@ -1064,6 +1070,12 @@ inline void line_to_destination() { ...@@ -1064,6 +1070,12 @@ inline void line_to_destination() {
inline void sync_plan_position() { inline void sync_plan_position() {
plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]); plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
} }
#if defined(DELTA) || defined(SCARA)
inline void sync_plan_position_delta() {
calculate_delta(current_position);
plan_set_position(delta[X_AXIS], delta[Y_AXIS], delta[Z_AXIS], current_position[E_AXIS]);
}
#endif
#if defined(CARTESIAN) || defined(COREXY) || defined(SCARA) #if defined(CARTESIAN) || defined(COREXY) || defined(SCARA)
static void axis_is_at_home(int axis) { static void axis_is_at_home(int axis) {
...@@ -1216,11 +1228,11 @@ inline void sync_plan_position() { ...@@ -1216,11 +1228,11 @@ inline void sync_plan_position() {
zPosition += home_retract_mm(Z_AXIS); zPosition += home_retract_mm(Z_AXIS);
line_to_z(zPosition); line_to_z(zPosition);
st_synchronize(); st_synchronize();
endstops_hit_on_purpose(); endstops_hit_on_purpose(); // clear endstop hit flags
// move back down slowly to find bed // move back down slowly to find bed
if (homing_bump_divisor[Z_AXIS] >= 1) { if (homing_bump_divisor[Z_AXIS] >= 1) {
feedrate = homing_feedrate[Z_AXIS]/homing_bump_divisor[Z_AXIS]; feedrate = homing_feedrate[Z_AXIS] / homing_bump_divisor[Z_AXIS];
} }
else { else {
feedrate = homing_feedrate[Z_AXIS]/10; feedrate = homing_feedrate[Z_AXIS]/10;
...@@ -1230,7 +1242,7 @@ inline void sync_plan_position() { ...@@ -1230,7 +1242,7 @@ inline void sync_plan_position() {
zPosition -= home_retract_mm(Z_AXIS) * 2; zPosition -= home_retract_mm(Z_AXIS) * 2;
line_to_z(zPosition); line_to_z(zPosition);
st_synchronize(); st_synchronize();
endstops_hit_on_purpose(); endstops_hit_on_purpose(); // clear endstop hit flags
current_position[Z_AXIS] = st_get_position_mm(Z_AXIS); current_position[Z_AXIS] = st_get_position_mm(Z_AXIS);
// make sure the planner knows where we are as it may be a bit different than we last said to move to // make sure the planner knows where we are as it may be a bit different than we last said to move to
...@@ -1282,10 +1294,11 @@ inline void sync_plan_position() { ...@@ -1282,10 +1294,11 @@ inline void sync_plan_position() {
// Retract Z Servo endstop if enabled // Retract Z Servo endstop if enabled
if (servo_endstops[Z_AXIS] >= 0) { if (servo_endstops[Z_AXIS] >= 0) {
/* NON FUNZIONA DA VERIFICARE
#if Z_RAISE_AFTER_PROBING > 0 #if Z_RAISE_AFTER_PROBING > 0
do_blocking_move_to(current_position[X_AXIS], current_position[Y_AXIS], Z_RAISE_AFTER_PROBING); do_blocking_move_to(current_position[X_AXIS], current_position[Y_AXIS], Z_RAISE_AFTER_PROBING);
st_synchronize();
#endif #endif
*/
#if SERVO_LEVELING #if SERVO_LEVELING
servos[servo_endstops[Z_AXIS]].attach(0); servos[servo_endstops[Z_AXIS]].attach(0);
...@@ -1323,7 +1336,7 @@ inline void sync_plan_position() { ...@@ -1323,7 +1336,7 @@ inline void sync_plan_position() {
#if Z_RAISE_BETWEEN_PROBINGS > 0 #if Z_RAISE_BETWEEN_PROBINGS > 0
if (retract_action == ProbeStay) { if (retract_action == ProbeStay) {
do_blocking_move_to(current_position[X_AXIS], current_position[Y_AXIS], Z_RAISE_BETWEEN_PROBINGS); do_blocking_move_to(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS] + Z_RAISE_BETWEEN_PROBINGS);
st_synchronize(); st_synchronize();
} }
#endif #endif
...@@ -1350,92 +1363,105 @@ inline void sync_plan_position() { ...@@ -1350,92 +1363,105 @@ inline void sync_plan_position() {
#define HOMEAXIS_DO(LETTER) \ #define HOMEAXIS_DO(LETTER) \
((LETTER##_MIN_PIN > -1 && LETTER##_HOME_DIR==-1) || (LETTER##_MAX_PIN > -1 && LETTER##_HOME_DIR==1)) ((LETTER##_MIN_PIN > -1 && LETTER##_HOME_DIR==-1) || (LETTER##_MAX_PIN > -1 && LETTER##_HOME_DIR==1))
if (axis==X_AXIS ? HOMEAXIS_DO(X) : if (axis == X_AXIS ? HOMEAXIS_DO(X) : axis == Y_AXIS ? HOMEAXIS_DO(Y) : axis == Z_AXIS ? HOMEAXIS_DO(Z) : 0)
axis==Y_AXIS ? HOMEAXIS_DO(Y) : {
axis==Z_AXIS ? HOMEAXIS_DO(Z) : int axis_home_dir;
0) {
int axis_home_dir = home_dir(axis);
#ifdef DUAL_X_CARRIAGE #ifdef DUAL_X_CARRIAGE
if (axis == X_AXIS) axis_home_dir = x_home_dir(active_extruder); if (axis == X_AXIS) axis_home_dir = x_home_dir(active_extruder);
#else
axis_home_dir = home_dir(axis);
#endif #endif
// Set the axis position as setup for the move
current_position[axis] = 0; current_position[axis] = 0;
sync_plan_position(); sync_plan_position();
#ifndef Z_PROBE_SLED
// Engage Servo endstop if enabled // Engage Servo endstop if enabled
#if defined(SERVO_ENDSTOPS) && (NUM_SERVOS > 0) #ifdef SERVO_ENDSTOPS && !defined(Z_PROBE_SLED)
#if SERVO_LEVELING #if SERVO_LEVELING
if (axis==Z_AXIS) { if (axis == Z_AXIS) engage_z_probe(); else
engage_z_probe();
}
else
#endif #endif
if (servo_endstops[axis] > -1) { {
if (servo_endstops[axis] > -1)
servos[servo_endstops[axis]].write(servo_endstop_angles[axis * 2]); servos[servo_endstops[axis]].write(servo_endstop_angles[axis * 2]);
} }
#endif #endif // SERVO_ENDSTOPS && !Z_PROBE_SLED
#endif // Z_PROBE_SLED
#ifdef Z_DUAL_ENDSTOPS #ifdef Z_DUAL_ENDSTOPS
if (axis == Z_AXIS) In_Homing_Process(true); if (axis == Z_AXIS) In_Homing_Process(true);
#endif #endif
// Move towards the endstop until an endstop is triggered
destination[axis] = 1.5 * max_length(axis) * axis_home_dir; destination[axis] = 1.5 * max_length(axis) * axis_home_dir;
feedrate = homing_feedrate[axis]; feedrate = homing_feedrate[axis];
line_to_destination(); line_to_destination();
st_synchronize(); st_synchronize();
// Set the axis position as setup for the move
current_position[axis] = 0; current_position[axis] = 0;
sync_plan_position(); sync_plan_position();
// Move away from the endstop by the axis HOME_RETRACT_MM
destination[axis] = -home_retract_mm(axis) * axis_home_dir; destination[axis] = -home_retract_mm(axis) * axis_home_dir;
line_to_destination(); line_to_destination();
st_synchronize(); st_synchronize();
destination[axis] = 2*home_retract_mm(axis) * axis_home_dir; // Slow down the feedrate for the next move
if (homing_bump_divisor[axis] >= 1) { if (homing_bump_divisor[axis] >= 1) {
feedrate = homing_feedrate[axis]/homing_bump_divisor[axis]; feedrate = homing_feedrate[axis] / homing_bump_divisor[axis];
} }
else { else {
feedrate = homing_feedrate[axis]/10; feedrate = homing_feedrate[axis] / 10;
SERIAL_ECHOLN("Warning: The Homing Bump Feedrate Divisor cannot be less then 1"); SERIAL_ECHOLN("Warning: The Homing Bump Feedrate Divisor cannot be less then 1");
} }
// Move slowly towards the endstop until triggered
destination[axis] = 2 * home_retract_mm(axis) * axis_home_dir;
line_to_destination(); line_to_destination();
st_synchronize(); st_synchronize();
#ifdef Z_DUAL_ENDSTOPS #ifdef Z_DUAL_ENDSTOPS
if (axis==Z_AXIS) { if (axis == Z_AXIS) {
feedrate = homing_feedrate[axis]; float adj = fabs(z_endstop_adj);
sync_plan_position(); bool lockZ1;
if (axis_home_dir > 0) { if (axis_home_dir > 0) {
destination[axis] = (-1) * fabs(z_endstop_adj); adj = -adj;
if (z_endstop_adj > 0) Lock_z_motor(true); else Lock_z2_motor(true); lockZ1 = (z_endstop_adj > 0);
} else {
destination[axis] = fabs(z_endstop_adj);
if (z_endstop_adj < 0) Lock_z_motor(true); else Lock_z2_motor(true);
} }
else
lockZ1 = (z_endstop_adj < 0);
if (lockZ1) Lock_z_motor(true); else Lock_z2_motor(true);
sync_plan_position();
// Move to the adjusted endstop height
feedrate = homing_feedrate[axis];
destination[Z_AXIS] = adj;
line_to_destination(); line_to_destination();
st_synchronize(); st_synchronize();
Lock_z_motor(false);
Lock_z2_motor(false); if (lockZ1) Lock_z_motor(false); else Lock_z2_motor(false);
In_Homing_Process(false); In_Homing_Process(false);
} } // Z_AXIS
#endif #endif
// Set the axis position to its home position (plus home offsets)
axis_is_at_home(axis); axis_is_at_home(axis);
destination[axis] = current_position[axis]; destination[axis] = current_position[axis];
feedrate = 0.0; feedrate = 0.0;
endstops_hit_on_purpose(); endstops_hit_on_purpose(); // clear endstop hit flags
axis_known_position[axis] = true; axis_known_position[axis] = true;
// Retract Servo endstop if enabled // Retract Servo endstop if enabled
#if NUM_SERVOS > 0 #if NUM_SERVOS > 0
if (servo_endstops[axis] > -1) { if (servo_endstops[axis] >= 0)
servos[servo_endstops[axis]].write(servo_endstop_angles[axis * 2 + 1]); servos[servo_endstops[axis]].write(servo_endstop_angles[axis * 2 + 1]);
}
#endif
#if SERVO_LEVELING
#ifndef Z_PROBE_SLED
if (axis==Z_AXIS) retract_z_probe();
#endif #endif
#if SERVO_LEVELING && !defined(Z_PROBE_SLED)
if (axis == Z_AXIS) retract_z_probe();
#endif #endif
} }
} }
...@@ -1495,7 +1521,7 @@ inline void sync_plan_position() { ...@@ -1495,7 +1521,7 @@ inline void sync_plan_position() {
axis_is_at_home(axis); axis_is_at_home(axis);
destination[axis] = current_position[axis]; destination[axis] = current_position[axis];
feedrate = 0.0; feedrate = 0.0;
endstops_hit_on_purpose(); endstops_hit_on_purpose(); // clear endstop hit flags
axis_known_position[axis] = true; axis_known_position[axis] = true;
} }
} }
...@@ -1597,7 +1623,7 @@ inline void sync_plan_position() { ...@@ -1597,7 +1623,7 @@ inline void sync_plan_position() {
destination[Z_AXIS] = -20; destination[Z_AXIS] = -20;
prepare_move_raw(); prepare_move_raw();
st_synchronize(); st_synchronize();
endstops_hit_on_purpose(); endstops_hit_on_purpose(); // clear endstop hit flags
enable_endstops(false); enable_endstops(false);
long stop_steps = st_get_position(Z_AXIS); long stop_steps = st_get_position(Z_AXIS);
...@@ -1849,7 +1875,7 @@ inline void sync_plan_position() { ...@@ -1849,7 +1875,7 @@ inline void sync_plan_position() {
feedrate = 1.732 * homing_feedrate[X_AXIS]; feedrate = 1.732 * homing_feedrate[X_AXIS];
line_to_destination(); line_to_destination();
st_synchronize(); st_synchronize();
endstops_hit_on_purpose(); endstops_hit_on_purpose(); // clear endstop hit flags
current_position[X_AXIS] = destination[X_AXIS]; current_position[X_AXIS] = destination[X_AXIS];
current_position[Y_AXIS] = destination[Y_AXIS]; current_position[Y_AXIS] = destination[Y_AXIS];
...@@ -1870,7 +1896,7 @@ inline void sync_plan_position() { ...@@ -1870,7 +1896,7 @@ inline void sync_plan_position() {
feedrate = saved_feedrate; feedrate = saved_feedrate;
feedmultiply = saved_feedmultiply; feedmultiply = saved_feedmultiply;
refresh_cmd_timeout(); refresh_cmd_timeout();
endstops_hit_on_purpose(); endstops_hit_on_purpose(); // clear endstop hit flags
} }
void prepare_move_raw() void prepare_move_raw()
...@@ -1976,75 +2002,62 @@ void refresh_cmd_timeout(void) { previous_millis_cmd = millis(); } ...@@ -1976,75 +2002,62 @@ void refresh_cmd_timeout(void) { previous_millis_cmd = millis(); }
#endif #endif
#ifdef FWRETRACT #ifdef FWRETRACT
void retract(bool retracting, bool swapretract = false) void retract(bool retracting, bool swapretract = false) {
{
if(retracting && !retracted[active_extruder]) if (retracting == retracted[active_extruder]) return;
{
destination[X_AXIS]=current_position[X_AXIS];
destination[Y_AXIS]=current_position[Y_AXIS];
destination[Z_AXIS]=current_position[Z_AXIS];
destination[E_AXIS]=current_position[E_AXIS];
if (swapretract)
{
current_position[E_AXIS]+=retract_length_swap/volumetric_multiplier[active_extruder];
}
else
{
current_position[E_AXIS]+=retract_length/volumetric_multiplier[active_extruder];
}
plan_set_e_position(current_position[E_AXIS]);
float oldFeedrate = feedrate; float oldFeedrate = feedrate;
feedrate=retract_feedrate*60;
retracted[active_extruder]=true; for (int i = 0; i < NUM_AXIS; i++) destination[i] = current_position[i];
if (retracting) {
feedrate = retract_feedrate * 60;
current_position[E_AXIS] += (swapretract ? retract_length_swap : retract_length) / volumetric_multiplier[active_extruder];
plan_set_e_position(current_position[E_AXIS]);
prepare_move(); prepare_move();
if(retract_zlift > 0.01)
{ if (retract_zlift > 0.01) {
current_position[Z_AXIS]-=retract_zlift; current_position[Z_AXIS] -= retract_zlift;
#ifdef DELTA #ifdef DELTA
calculate_delta(current_position); // change cartesian kinematic to delta kinematic; sync_plan_position_delta();
plan_set_position(delta[X_AXIS], delta[Y_AXIS], delta[Z_AXIS], current_position[E_AXIS]);
#else #else
sync_plan_position(); sync_plan_position();
#endif //DELTA #endif
prepare_move(); prepare_move();
} }
feedrate = oldFeedrate;
} }
else if(!retracting && retracted[active_extruder]) else {
{
destination[X_AXIS]=current_position[X_AXIS]; if (retract_zlift > 0.01) {
destination[Y_AXIS]=current_position[Y_AXIS]; current_position[Z_AXIS] += retract_zlift;
destination[Z_AXIS]=current_position[Z_AXIS];
destination[E_AXIS]=current_position[E_AXIS];
if(retract_zlift > 0.01)
{
current_position[Z_AXIS]+=retract_zlift;
#ifdef DELTA #ifdef DELTA
calculate_delta(current_position); // change cartesian kinematic to delta kinematic; sync_plan_position_delta();
plan_set_position(delta[X_AXIS], delta[Y_AXIS], delta[Z_AXIS], current_position[E_AXIS]);
#else #else
sync_plan_position(); sync_plan_position();
#endif //DELTA #endif
} //prepare_move();
if (swapretract)
{
current_position[E_AXIS]-=(retract_length_swap+retract_recover_length_swap)/volumetric_multiplier[active_extruder];
}
else
{
current_position[E_AXIS]-=(retract_length+retract_recover_length)/volumetric_multiplier[active_extruder];
} }
feedrate = retract_recover_feedrate * 60;
float move_e = swapretract ? retract_length_swap + retract_recover_length_swap : retract_length + retract_recover_length;
current_position[E_AXIS] -= move_e / volumetric_multiplier[active_extruder];
plan_set_e_position(current_position[E_AXIS]); plan_set_e_position(current_position[E_AXIS]);
float oldFeedrate = feedrate;
feedrate=retract_recover_feedrate * 60;
retracted[active_extruder] = false;
prepare_move(); prepare_move();
feedrate = oldFeedrate;
}
} }
feedrate = oldFeedrate;
retracted[active_extruder] = retract;
} // retract()
#endif //FWRETRACT #endif //FWRETRACT
#ifdef Z_PROBE_SLED #ifdef Z_PROBE_SLED
#ifndef SLED_DOCKING_OFFSET
#define SLED_DOCKING_OFFSET 0
#endif
// //
// Method to dock/undock a sled designed by Charles Bell. // Method to dock/undock a sled designed by Charles Bell.
// //
...@@ -2052,9 +2065,7 @@ void refresh_cmd_timeout(void) { previous_millis_cmd = millis(); } ...@@ -2052,9 +2065,7 @@ void refresh_cmd_timeout(void) { previous_millis_cmd = millis(); }
// offset[in] The additional distance to move to adjust docking location // offset[in] The additional distance to move to adjust docking location
// //
static void dock_sled(bool dock, int offset=0) { static void dock_sled(bool dock, int offset=0) {
int z_loc; if (!axis_known_position[X_AXIS] || !axis_known_position[Y_AXIS]) {
if (!((axis_known_position[X_AXIS]) && (axis_known_position[Y_AXIS]))) {
LCD_MESSAGEPGM(MSG_POSITION_UNKNOWN); LCD_MESSAGEPGM(MSG_POSITION_UNKNOWN);
SERIAL_ECHO_START; SERIAL_ECHO_START;
SERIAL_ECHOLNPGM(MSG_POSITION_UNKNOWN); SERIAL_ECHOLNPGM(MSG_POSITION_UNKNOWN);
...@@ -2063,17 +2074,12 @@ void refresh_cmd_timeout(void) { previous_millis_cmd = millis(); } ...@@ -2063,17 +2074,12 @@ void refresh_cmd_timeout(void) { previous_millis_cmd = millis(); }
if (dock) { if (dock) {
do_blocking_move_to(X_MAX_POS + SLED_DOCKING_OFFSET + offset, current_position[Y_AXIS], current_position[Z_AXIS]); do_blocking_move_to(X_MAX_POS + SLED_DOCKING_OFFSET + offset, current_position[Y_AXIS], current_position[Z_AXIS]);
// turn off magnet digitalWrite(SERVO0_PIN, LOW); // turn off magnet
digitalWrite(SERVO0_PIN, LOW); } else {
} float z_loc = current_position[Z_AXIS];
else { if (z_loc < Z_RAISE_BEFORE_PROBING + 5) z_loc = Z_RAISE_BEFORE_PROBING;
if (current_position[Z_AXIS] < (Z_RAISE_BEFORE_PROBING + 5))
z_loc = Z_RAISE_BEFORE_PROBING;
else
z_loc = current_position[Z_AXIS];
do_blocking_move_to(X_MAX_POS + SLED_DOCKING_OFFSET + offset, Y_PROBE_OFFSET_FROM_EXTRUDER, z_loc); do_blocking_move_to(X_MAX_POS + SLED_DOCKING_OFFSET + offset, Y_PROBE_OFFSET_FROM_EXTRUDER, z_loc);
// turn on magnet digitalWrite(SERVO0_PIN, HIGH); // turn on magnet
digitalWrite(SERVO0_PIN, HIGH);
} }
} }
#endif //Z_PROBE_SLED #endif //Z_PROBE_SLED
...@@ -2270,8 +2276,28 @@ inline void gcode_G4() { ...@@ -2270,8 +2276,28 @@ inline void gcode_G4() {
} }
#endif //FWRETRACT #endif //FWRETRACT
// G28: Home all axes, one at a time /**
inline void gcode_G28(boolean home_x=false, boolean home_y=false) { * G28: Home all axes according to settings
*
* Parameters
*
* None Home to all axes with no parameters.
* With QUICK_HOME enabled XY will home together, then Z.
*
* Cartesian parameters
*
* X Home to the X endstop
* Y Home to the Y endstop
* Z Home to the Z endstop
*
* If numbers are included with XYZ set the position as with G92
* Currently adds the home_offset, which may be wrong and removed soon.
*
* Xn Home X, setting X to n + home_offset[X_AXIS]
* Yn Home Y, setting Y to n + home_offset[Y_AXIS]
* Zn Home Z, setting Z to n + home_offset[Z_AXIS]
*/
inline void gcode_G28(boolean home_x = false, boolean home_y = false) {
#ifdef ENABLE_AUTO_BED_LEVELING #ifdef ENABLE_AUTO_BED_LEVELING
plan_bed_level_matrix.set_to_identity(); //Reset the plane ("erase" all levelling data) plan_bed_level_matrix.set_to_identity(); //Reset the plane ("erase" all levelling data)
#endif //ENABLE_AUTO_BED_LEVELING #endif //ENABLE_AUTO_BED_LEVELING
...@@ -2287,7 +2313,12 @@ inline void gcode_G28(boolean home_x=false, boolean home_y=false) { ...@@ -2287,7 +2313,12 @@ inline void gcode_G28(boolean home_x=false, boolean home_y=false) {
feedrate = 0.0; feedrate = 0.0;
home_all_axis = !((code_seen(axis_codes[X_AXIS])) || (code_seen(axis_codes[Y_AXIS])) || (code_seen(axis_codes[Z_AXIS])) || (code_seen(axis_codes[E_AXIS])) || home_x || home_y); bool homeX = code_seen(axis_codes[X_AXIS]),
homeY = code_seen(axis_codes[Y_AXIS]),
homeZ = code_seen(axis_codes[Z_AXIS]),
homeE = code_seen(axis_codes[E_AXIS]);
home_all_axis = !(homeX || homeY || homeZ || homeE || home_x || home_y);
#ifdef NPR2 #ifdef NPR2
if((home_all_axis) || (code_seen(axis_codes[E_AXIS]))) { if((home_all_axis) || (code_seen(axis_codes[E_AXIS]))) {
...@@ -2311,7 +2342,7 @@ inline void gcode_G28(boolean home_x=false, boolean home_y=false) { ...@@ -2311,7 +2342,7 @@ inline void gcode_G28(boolean home_x=false, boolean home_y=false) {
feedrate = 1.732 * homing_feedrate[X_AXIS]; feedrate = 1.732 * homing_feedrate[X_AXIS];
line_to_destination(); line_to_destination();
st_synchronize(); st_synchronize();
endstops_hit_on_purpose(); endstops_hit_on_purpose(); // clear endstop hit flags
// Destination reached // Destination reached
for (int i = X_AXIS; i <= Z_AXIS; i++) current_position[i] = destination[i]; for (int i = X_AXIS; i <= Z_AXIS; i++) current_position[i] = destination[i];
...@@ -2321,24 +2352,27 @@ inline void gcode_G28(boolean home_x=false, boolean home_y=false) { ...@@ -2321,24 +2352,27 @@ inline void gcode_G28(boolean home_x=false, boolean home_y=false) {
HOMEAXIS(Y); HOMEAXIS(Y);
HOMEAXIS(Z); HOMEAXIS(Z);
calculate_delta(current_position); sync_plan_position_delta();
plan_set_position(delta[X_AXIS], delta[Y_AXIS], delta[Z_AXIS], current_position[E_AXIS]);
#endif //DELTA #endif //DELTA
#if defined(CARTESIAN) || defined(COREXY) || defined(SCARA) #if defined(CARTESIAN) || defined(COREXY) || defined(SCARA)
bool homeX = code_seen(axis_codes[X_AXIS]),
homeY = code_seen(axis_codes[Y_AXIS]),
homeZ = code_seen(axis_codes[Z_AXIS]);
home_all_axis = !homeX && !homeY && !homeZ; // No parameters means home all axes
#if Z_HOME_DIR > 0 // If homing away from BED do Z first #if Z_HOME_DIR > 0 // If homing away from BED do Z first
if((home_all_axis) || homeZ) HOMEAXIS(Z); if (home_all_axis || homeZ) HOMEAXIS(Z);
#elif !defined(Z_SAFE_HOMING) && defined(Z_RAISE_BEFORE_HOMING) && Z_RAISE_BEFORE_HOMING > 0
// Raise Z before homing any other axes
if (home_all_axis || homeZ) {
destination[Z_AXIS] = -Z_RAISE_BEFORE_HOMING * home_dir(Z_AXIS); // Set destination away from bed
feedrate = max_feedrate[Z_AXIS];
line_to_destination();
st_synchronize();
}
#endif #endif
#ifdef QUICK_HOME #ifdef QUICK_HOME
if (home_all_axis || (homeX && homeY)) { //first diagonal move if (home_all_axis || (homeX && homeY)) { // First diagonal move
current_position[X_AXIS] = current_position[Y_AXIS] = 0; current_position[X_AXIS] = current_position[Y_AXIS] = 0;
#ifdef DUAL_X_CARRIAGE #ifdef DUAL_X_CARRIAGE
...@@ -2349,28 +2383,26 @@ inline void gcode_G28(boolean home_x=false, boolean home_y=false) { ...@@ -2349,28 +2383,26 @@ inline void gcode_G28(boolean home_x=false, boolean home_y=false) {
#endif #endif
sync_plan_position(); sync_plan_position();
destination[X_AXIS] = 1.5 * max_length(X_AXIS) * x_axis_home_dir;
destination[Y_AXIS] = 1.5 * max_length(Y_AXIS) * home_dir(Y_AXIS); float mlx = max_length(X_AXIS), mly = max_length(Y_AXIS),
feedrate = homing_feedrate[X_AXIS]; mlratio = mlx>mly ? mly/mlx : mlx/mly;
if (homing_feedrate[Y_AXIS] < feedrate) feedrate = homing_feedrate[Y_AXIS];
if (max_length(X_AXIS) > max_length(Y_AXIS)) { destination[X_AXIS] = 1.5 * mlx * x_axis_home_dir;
feedrate *= sqrt(pow(max_length(Y_AXIS) / max_length(X_AXIS), 2) + 1); destination[Y_AXIS] = 1.5 * mly * home_dir(Y_AXIS);
} feedrate = min(homing_feedrate[X_AXIS], homing_feedrate[Y_AXIS]) * sqrt(mlratio * mlratio + 1);
else {
feedrate *= sqrt(pow(max_length(X_AXIS) / max_length(Y_AXIS), 2) + 1);
}
line_to_destination(); line_to_destination();
st_synchronize(); st_synchronize();
axis_is_at_home(X_AXIS); axis_is_at_home(X_AXIS);
axis_is_at_home(Y_AXIS); axis_is_at_home(Y_AXIS);
sync_plan_position(); sync_plan_position();
destination[X_AXIS] = current_position[X_AXIS]; destination[X_AXIS] = current_position[X_AXIS];
destination[Y_AXIS] = current_position[Y_AXIS]; destination[Y_AXIS] = current_position[Y_AXIS];
line_to_destination(); line_to_destination();
feedrate = 0.0; feedrate = 0.0;
st_synchronize(); st_synchronize();
endstops_hit_on_purpose(); endstops_hit_on_purpose(); // clear endstop hit flags
current_position[X_AXIS] = destination[X_AXIS]; current_position[X_AXIS] = destination[X_AXIS];
current_position[Y_AXIS] = destination[Y_AXIS]; current_position[Y_AXIS] = destination[Y_AXIS];
...@@ -2460,7 +2492,7 @@ inline void gcode_G28(boolean home_x=false, boolean home_y=false) { ...@@ -2460,7 +2492,7 @@ inline void gcode_G28(boolean home_x=false, boolean home_y=false) {
feedrate = saved_feedrate; feedrate = saved_feedrate;
feedmultiply = saved_feedmultiply; feedmultiply = saved_feedmultiply;
previous_millis_cmd = millis(); previous_millis_cmd = millis();
endstops_hit_on_purpose(); endstops_hit_on_purpose(); // clear endstop hit flags
sync_plan_position(); sync_plan_position();
...@@ -2527,25 +2559,17 @@ inline void gcode_G28(boolean home_x=false, boolean home_y=false) { ...@@ -2527,25 +2559,17 @@ inline void gcode_G28(boolean home_x=false, boolean home_y=false) {
enquecommands_P(PSTR("G28 X0 Y0\nG4 P0\nG4 P0\nG4 P0")); enquecommands_P(PSTR("G28 X0 Y0\nG4 P0\nG4 P0\nG4 P0"));
#endif // ULTIPANEL #endif // ULTIPANEL
} }
else if(home_all_axis || homeZ) { else if(home_all_axis || homeZ) HOMEAXIS(Z);
#if defined (Z_RAISE_BEFORE_HOMING) && (Z_RAISE_BEFORE_HOMING > 0)
destination[Z_AXIS] = -Z_RAISE_BEFORE_HOMING * home_dir(Z_AXIS); // Set destination away from bed
feedrate = max_feedrate[Z_AXIS];
plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate, active_extruder, active_driver);
st_synchronize();
#endif
HOMEAXIS(Z);
}
#elif defined(Z_SAFE_HOMING) && defined(ENABLE_AUTO_BED_LEVELING)// Z Safe mode activated. #elif defined(Z_SAFE_HOMING) && defined(ENABLE_AUTO_BED_LEVELING)// Z Safe mode activated.
if (home_all_axis) { if (home_all_axis) {
destination[X_AXIS] = round(Z_SAFE_HOMING_X_POINT - X_PROBE_OFFSET_FROM_EXTRUDER); destination[X_AXIS] = round(Z_SAFE_HOMING_X_POINT - X_PROBE_OFFSET_FROM_EXTRUDER);
destination[Y_AXIS] = round(Z_SAFE_HOMING_Y_POINT - Y_PROBE_OFFSET_FROM_EXTRUDER); destination[Y_AXIS] = round(Z_SAFE_HOMING_Y_POINT - Y_PROBE_OFFSET_FROM_EXTRUDER);
destination[Z_AXIS] = -Z_RAISE_BEFORE_HOMING * home_dir(Z_AXIS); // Set destination away from bed destination[Z_AXIS] = -Z_RAISE_BEFORE_HOMING * home_dir(Z_AXIS); // Set destination away from bed
feedrate = xy_travel_speed / 60; feedrate = xy_travel_speed;
current_position[Z_AXIS] = 0; current_position[Z_AXIS] = 0;
sync_plan_position(); sync_plan_position();
plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate, active_extruder, active_driver); line_to_destination();
st_synchronize(); st_synchronize();
current_position[X_AXIS] = destination[X_AXIS]; current_position[X_AXIS] = destination[X_AXIS];
current_position[Y_AXIS] = destination[Y_AXIS]; current_position[Y_AXIS] = destination[Y_AXIS];
...@@ -2560,10 +2584,10 @@ inline void gcode_G28(boolean home_x=false, boolean home_y=false) { ...@@ -2560,10 +2584,10 @@ inline void gcode_G28(boolean home_x=false, boolean home_y=false) {
&& cpy >= Y_MIN_POS - Y_PROBE_OFFSET_FROM_EXTRUDER && cpy >= Y_MIN_POS - Y_PROBE_OFFSET_FROM_EXTRUDER
&& cpy <= Y_MAX_POS - Y_PROBE_OFFSET_FROM_EXTRUDER) { && cpy <= Y_MAX_POS - Y_PROBE_OFFSET_FROM_EXTRUDER) {
current_position[Z_AXIS] = 0; current_position[Z_AXIS] = 0;
plan_set_position(cpx, cpy, current_position[Z_AXIS], current_position[E_AXIS]); plan_set_position(cpx, cpy, 0, current_position[E_AXIS]);
destination[Z_AXIS] = -Z_RAISE_BEFORE_HOMING * home_dir(Z_AXIS); // Set destination away from bed destination[Z_AXIS] = -Z_RAISE_BEFORE_HOMING * home_dir(Z_AXIS); // Set destination away from bed
feedrate = max_feedrate[Z_AXIS]; feedrate = max_feedrate[Z_AXIS];
plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate, active_extruder, active_driver); line_to_destination();
st_synchronize(); st_synchronize();
HOMEAXIS(Z); HOMEAXIS(Z);
} }
...@@ -2583,10 +2607,10 @@ inline void gcode_G28(boolean home_x=false, boolean home_y=false) { ...@@ -2583,10 +2607,10 @@ inline void gcode_G28(boolean home_x=false, boolean home_y=false) {
if(home_all_axis || homeZ) { if(home_all_axis || homeZ) {
destination[X_AXIS] = round(Z_SAFE_HOMING_X_POINT); destination[X_AXIS] = round(Z_SAFE_HOMING_X_POINT);
destination[Y_AXIS] = round(Z_SAFE_HOMING_Y_POINT); destination[Y_AXIS] = round(Z_SAFE_HOMING_Y_POINT);
feedrate = xy_travel_speed / 60; feedrate = xy_travel_speed;
destination[Z_AXIS] = current_position[Z_AXIS] = 0; destination[Z_AXIS] = current_position[Z_AXIS] = 0;
sync_plan_position(); sync_plan_position();
plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate, active_extruder, active_driver); line_to_destination();
st_synchronize(); st_synchronize();
current_position[X_AXIS] = destination[X_AXIS]; current_position[X_AXIS] = destination[X_AXIS];
current_position[Y_AXIS] = destination[Y_AXIS]; current_position[Y_AXIS] = destination[Y_AXIS];
...@@ -2603,15 +2627,14 @@ inline void gcode_G28(boolean home_x=false, boolean home_y=false) { ...@@ -2603,15 +2627,14 @@ inline void gcode_G28(boolean home_x=false, boolean home_y=false) {
if (v) current_position[Z_AXIS] = v + home_offset[Z_AXIS]; if (v) current_position[Z_AXIS] = v + home_offset[Z_AXIS];
} }
#ifdef ENABLE_AUTO_BED_LEVELING #ifdef ENABLE_AUTO_BED_LEVELING && (Z_HOME_DIR < 0)
if (home_all_axis || homeZ) current_position[Z_AXIS] += zprobe_zoffset; //Add Z_Probe offset (the distance is negative) if (home_all_axis || homeZ) current_position[Z_AXIS] += zprobe_zoffset; //Add Z_Probe offset (the distance is negative)
#endif //ENABLE_AUTO_BED_LEVELING #endif //ENABLE_AUTO_BED_LEVELING
sync_plan_position(); sync_plan_position();
#endif // defined(CARTESIAN) || defined(COREXY) || defined(SCARA) #endif // defined(CARTESIAN) || defined(COREXY) || defined(SCARA)
#ifdef SCARA #ifdef SCARA
calculate_delta(current_position); sync_plan_position_delta();
plan_set_position(delta[X_AXIS], delta[Y_AXIS], delta[Z_AXIS], current_position[E_AXIS]);
#endif //SCARA #endif //SCARA
#ifdef ENDSTOPS_ONLY_FOR_HOMING #ifdef ENDSTOPS_ONLY_FOR_HOMING
...@@ -2621,7 +2644,7 @@ inline void gcode_G28(boolean home_x=false, boolean home_y=false) { ...@@ -2621,7 +2644,7 @@ inline void gcode_G28(boolean home_x=false, boolean home_y=false) {
feedrate = saved_feedrate; feedrate = saved_feedrate;
feedmultiply = saved_feedmultiply; feedmultiply = saved_feedmultiply;
previous_millis_cmd = millis(); previous_millis_cmd = millis();
endstops_hit_on_purpose(); endstops_hit_on_purpose(); // clear endstop hit flags
} }
#ifdef ENABLE_AUTO_BED_LEVELING #ifdef ENABLE_AUTO_BED_LEVELING
...@@ -2918,13 +2941,14 @@ inline void gcode_G28(boolean home_x=false, boolean home_y=false) { ...@@ -2918,13 +2941,14 @@ inline void gcode_G28(boolean home_x=false, boolean home_y=false) {
// Correct the Z height difference from z-probe position and hotend tip position. // Correct the Z height difference from z-probe position and hotend tip position.
// The Z height on homing is measured by Z-Probe, but the probe is quite far from the hotend. // The Z height on homing is measured by Z-Probe, but the probe is quite far from the hotend.
// When the bed is uneven, this height must be corrected. // When the bed is uneven, this height must be corrected.
if (!dryrun) if (!dryrun) {
{ // Correct the Z height difference from z-probe position and hotend tip position.
float x_tmp, y_tmp, z_tmp, real_z; // The Z height on homing is measured by Z-Probe, but the probe is quite far from the hotend.
real_z = float(st_get_position(Z_AXIS)) / axis_steps_per_unit[Z_AXIS]; //get the real Z (since the auto bed leveling is already correcting the plane) // When the bed is uneven, this height must be corrected.
x_tmp = current_position[X_AXIS] + X_PROBE_OFFSET_FROM_EXTRUDER; float x_tmp = current_position[X_AXIS] + X_PROBE_OFFSET_FROM_EXTRUDER,
y_tmp = current_position[Y_AXIS] + Y_PROBE_OFFSET_FROM_EXTRUDER; y_tmp = current_position[Y_AXIS] + Y_PROBE_OFFSET_FROM_EXTRUDER,
z_tmp = current_position[Z_AXIS]; z_tmp = current_position[Z_AXIS],
real_z = (float)st_get_position(Z_AXIS) / axis_steps_per_unit[Z_AXIS]; //get the real Z (since the auto bed leveling is already correcting the plane)
apply_rotation_xyz(plan_bed_level_matrix, x_tmp, y_tmp, z_tmp); //Apply the correction sending the probe offset apply_rotation_xyz(plan_bed_level_matrix, x_tmp, y_tmp, z_tmp); //Apply the correction sending the probe offset
current_position[Z_AXIS] = z_tmp - real_z + current_position[Z_AXIS]; //The difference is added to current position and sent to planner. current_position[Z_AXIS] = z_tmp - real_z + current_position[Z_AXIS]; //The difference is added to current position and sent to planner.
...@@ -2987,7 +3011,7 @@ inline void gcode_G28(boolean home_x=false, boolean home_y=false) { ...@@ -2987,7 +3011,7 @@ inline void gcode_G28(boolean home_x=false, boolean home_y=false) {
feedrate = saved_feedrate; feedrate = saved_feedrate;
feedmultiply = saved_feedmultiply; feedmultiply = saved_feedmultiply;
refresh_cmd_timeout(); refresh_cmd_timeout();
endstops_hit_on_purpose(); endstops_hit_on_purpose(); // clear endstop hit flags
} }
// G30: Delta AutoCalibration // G30: Delta AutoCalibration
...@@ -3587,6 +3611,9 @@ inline void gcode_G92() { ...@@ -3587,6 +3611,9 @@ inline void gcode_G92() {
printing = true; printing = true;
paused = false; paused = false;
SERIAL_ECHOLN("Start Printing, pause pin active."); SERIAL_ECHOLN("Start Printing, pause pin active.");
#if HAS_POWER_CONSUMPTION_SENSOR
startpower = power_consumption_hour;
#endif
} }
#endif #endif
...@@ -3632,7 +3659,9 @@ inline void gcode_G92() { ...@@ -3632,7 +3659,9 @@ inline void gcode_G92() {
inline void gcode_M24() { inline void gcode_M24() {
card.startFileprint(); card.startFileprint();
starttime = millis(); starttime = millis();
#if HAS_POWER_CONSUMPTION_SENSOR
startpower = power_consumption_hour; startpower = power_consumption_hour;
#endif
} }
// M25: Pause SD Print // M25: Pause SD Print
...@@ -3725,7 +3754,9 @@ inline void gcode_M31() { ...@@ -3725,7 +3754,9 @@ inline void gcode_M31() {
card.startFileprint(); card.startFileprint();
if (!call_procedure) { if (!call_procedure) {
starttime = millis(); //procedure calls count as normal print time. starttime = millis(); //procedure calls count as normal print time.
#if HAS_POWER_CONSUMPTION_SENSOR
startpower = power_consumption_hour; startpower = power_consumption_hour;
#endif
} }
} }
} }
...@@ -3795,43 +3826,40 @@ inline void gcode_M42() { ...@@ -3795,43 +3826,40 @@ inline void gcode_M42() {
inline void gcode_M49() { inline void gcode_M49() {
double sum = 0.0, mean = 0.0, sigma = 0.0, sample_set[50]; double sum = 0.0, mean = 0.0, sigma = 0.0, sample_set[50];
int verbose_level = 1, n = 0, j, n_samples = 10, n_legs = 0, engage_probe_for_each_reading = 0; int verbose_level = 1, n_samples = 10, n_legs = 0;
double X_current, Y_current, Z_current;
double X_probe_location, Y_probe_location, Z_start_location, ext_position;
if (code_seen('V') || code_seen('v')) { if (code_seen('V') || code_seen('v')) {
verbose_level = code_value(); verbose_level = code_value();
if (verbose_level < 0 || verbose_level > 4) { if (verbose_level < 0 || verbose_level > 4 ) {
SERIAL_PROTOCOLPGM("?Verbose Level not plausible (0-4).\n"); SERIAL_PROTOCOLPGM("?Verbose Level not plausible (0-4).\n");
return; return;
} }
} }
if (verbose_level > 0) { if (verbose_level > 0)
SERIAL_PROTOCOLPGM("M49 Z-Probe Repeatability test.\n"); SERIAL_PROTOCOLPGM("M49 Z-Probe Repeatability test\n");
}
if (code_seen('n')) { if (code_seen('P') || code_seen('p') || code_seen('n')) { // `n` for legacy support only - please use `P`!
n_samples = code_value(); n_samples = code_value();
if (n_samples < 4 || n_samples > 50) { if (n_samples < 4 || n_samples > 50) {
SERIAL_PROTOCOLPGM("?Specified sample size not plausible (4-50).\n"); SERIAL_PROTOCOLPGM("?Sample size not plausible (4-50).\n");
return; return;
} }
} }
X_current = X_probe_location = st_get_position_mm(X_AXIS); double X_probe_location, Y_probe_location,
Y_current = Y_probe_location = st_get_position_mm(Y_AXIS); X_current = X_probe_location = st_get_position_mm(X_AXIS),
Z_current = st_get_position_mm(Z_AXIS); Y_current = Y_probe_location = st_get_position_mm(Y_AXIS),
Z_start_location = st_get_position_mm(Z_AXIS) + Z_RAISE_BEFORE_PROBING; Z_current = st_get_position_mm(Z_AXIS),
Z_start_location = Z_current + Z_RAISE_BEFORE_PROBING,
ext_position = st_get_position_mm(E_AXIS); ext_position = st_get_position_mm(E_AXIS);
if (code_seen('E') || code_seen('e')) bool engage_probe_for_each_reading = code_seen('E') || code_seen('e');
engage_probe_for_each_reading++;
if (code_seen('X') || code_seen('x')) { if (code_seen('X') || code_seen('x')) {
X_probe_location = code_value() - X_PROBE_OFFSET_FROM_EXTRUDER; X_probe_location = code_value() - X_PROBE_OFFSET_FROM_EXTRUDER;
if (X_probe_location < X_MIN_POS || X_probe_location > X_MAX_POS) { if (X_probe_location < X_MIN_POS || X_probe_location > X_MAX_POS) {
SERIAL_PROTOCOLPGM("?Specified X position out of range.\n"); SERIAL_PROTOCOLPGM("?X position out of range.\n");
return; return;
} }
} }
...@@ -3839,7 +3867,7 @@ inline void gcode_M42() { ...@@ -3839,7 +3867,7 @@ inline void gcode_M42() {
if (code_seen('Y') || code_seen('y')) { if (code_seen('Y') || code_seen('y')) {
Y_probe_location = code_value() - Y_PROBE_OFFSET_FROM_EXTRUDER; Y_probe_location = code_value() - Y_PROBE_OFFSET_FROM_EXTRUDER;
if (Y_probe_location < Y_MIN_POS || Y_probe_location > Y_MAX_POS) { if (Y_probe_location < Y_MIN_POS || Y_probe_location > Y_MAX_POS) {
SERIAL_PROTOCOLPGM("?Specified Y position out of range.\n"); SERIAL_PROTOCOLPGM("?Y position out of range.\n");
return; return;
} }
} }
...@@ -3848,7 +3876,7 @@ inline void gcode_M42() { ...@@ -3848,7 +3876,7 @@ inline void gcode_M42() {
n_legs = code_value(); n_legs = code_value();
if (n_legs == 1) n_legs = 2; if (n_legs == 1) n_legs = 2;
if (n_legs < 0 || n_legs > 15) { if (n_legs < 0 || n_legs > 15) {
SERIAL_PROTOCOLPGM("?Specified number of legs in movement not plausible (0-15).\n"); SERIAL_PROTOCOLPGM("?Number of legs in movement not plausible (0-15).\n");
return; return;
} }
} }
...@@ -3868,7 +3896,7 @@ inline void gcode_M42() { ...@@ -3868,7 +3896,7 @@ inline void gcode_M42() {
// use that as a starting point for each probe. // use that as a starting point for each probe.
// //
if (verbose_level > 2) if (verbose_level > 2)
SERIAL_PROTOCOL("Positioning probe for the test.\n"); SERIAL_PROTOCOL("Positioning the probe...\n");
plan_buffer_line(X_probe_location, Y_probe_location, Z_start_location, ext_position, homing_feedrate[X_AXIS]/60, active_extruder, active_driver); plan_buffer_line(X_probe_location, Y_probe_location, Z_start_location, ext_position, homing_feedrate[X_AXIS]/60, active_extruder, active_driver);
st_synchronize(); st_synchronize();
...@@ -3897,33 +3925,29 @@ inline void gcode_M42() { ...@@ -3897,33 +3925,29 @@ inline void gcode_M42() {
if (engage_probe_for_each_reading) retract_z_probe(); if (engage_probe_for_each_reading) retract_z_probe();
for (n = 0; n < n_samples; n++) { for (uint16_t n=0; n < n_samples; n++) {
do_blocking_move_to( X_probe_location, Y_probe_location, Z_start_location); // Make sure we are at the probe location do_blocking_move_to(X_probe_location, Y_probe_location, Z_start_location); // Make sure we are at the probe location
if (n_legs) { if (n_legs) {
double radius = 0.0, theta = 0.0, x_sweep, y_sweep; unsigned long ms = millis();
int l; double radius = ms % (X_MAX_LENGTH / 4), // limit how far out to go
int rotational_direction = (unsigned long) millis() & 0x0001; // clockwise or counter clockwise theta = RADIANS(ms % 360L);
radius = (unsigned long)millis() % (long)(X_MAX_LENGTH / 4); // limit how far out to go float dir = (ms & 0x0001) ? 1 : -1; // clockwise or counter clockwise
theta = (float)((unsigned long)millis() % 360L) / (360. / (2 * 3.1415926)); // turn into radians
//SERIAL_ECHOPAIR("starting radius: ",radius); //SERIAL_ECHOPAIR("starting radius: ",radius);
//SERIAL_ECHOPAIR(" theta: ",theta); //SERIAL_ECHOPAIR(" theta: ",theta);
//SERIAL_ECHOPAIR(" direction: ",rotational_direction); //SERIAL_ECHOPAIR(" direction: ",dir);
//SERIAL_EOL; //SERIAL_EOL;
float dir = rotational_direction ? 1 : -1; for (int l = 0; l < n_legs - 1; l++) {
for (l = 0; l < n_legs - 1; l++) { ms = millis();
theta += dir * (float)((unsigned long)millis() % 20L) / (360.0/(2*3.1415926)); // turn into radians theta += RADIANS(dir * (ms % 20L));
radius += (ms % 10L) - 5L;
radius += (float)(((long)((unsigned long) millis() % 10L)) - 5L);
if (radius < 0.0) radius = -radius; if (radius < 0.0) radius = -radius;
X_current = X_probe_location + cos(theta) * radius; X_current = X_probe_location + cos(theta) * radius;
Y_current = Y_probe_location + sin(theta) * radius; Y_current = Y_probe_location + sin(theta) * radius;
// Make sure our X & Y are sane
X_current = constrain(X_current, X_MIN_POS, X_MAX_POS); X_current = constrain(X_current, X_MIN_POS, X_MAX_POS);
Y_current = constrain(Y_current, Y_MIN_POS, Y_MAX_POS); Y_current = constrain(Y_current, Y_MIN_POS, Y_MAX_POS);
...@@ -3933,10 +3957,13 @@ inline void gcode_M42() { ...@@ -3933,10 +3957,13 @@ inline void gcode_M42() {
SERIAL_EOL; SERIAL_EOL;
} }
do_blocking_move_to( X_current, Y_current, Z_current ); do_blocking_move_to(X_current, Y_current, Z_current);
}
do_blocking_move_to( X_probe_location, Y_probe_location, Z_start_location); // Go back to the probe location } // n_legs loop
}
do_blocking_move_to(X_probe_location, Y_probe_location, Z_start_location); // Go back to the probe location
} // n_legs
if (engage_probe_for_each_reading) { if (engage_probe_for_each_reading) {
engage_z_probe(); engage_z_probe();
...@@ -3952,30 +3979,32 @@ inline void gcode_M42() { ...@@ -3952,30 +3979,32 @@ inline void gcode_M42() {
// Get the current mean for the data points we have so far // Get the current mean for the data points we have so far
// //
sum = 0.0; sum = 0.0;
for (j=0; j<=n; j++) sum += sample_set[j]; for (int j = 0; j <= n; j++) sum += sample_set[j];
mean = sum / (double (n+1)); mean = sum / (n + 1);
// //
// Now, use that mean to calculate the standard deviation for the // Now, use that mean to calculate the standard deviation for the
// data points we have so far // data points we have so far
// //
sum = 0.0; sum = 0.0;
for (j = 0; j <= n; j++) sum += (sample_set[j] - mean) * (sample_set[j] - mean); for (int j = 0; j <= n; j++) {
sigma = sqrt( sum / (double (n+1)) ); float ss = sample_set[j] - mean;
sum += ss * ss;
}
sigma = sqrt(sum / (n + 1));
if (verbose_level > 1) { if (verbose_level > 1) {
SERIAL_PROTOCOL(n + 1); SERIAL_PROTOCOL(n+1);
SERIAL_PROTOCOL(" of "); SERIAL_PROTOCOLPGM(" of ");
SERIAL_PROTOCOL(n_samples); SERIAL_PROTOCOL(n_samples);
SERIAL_PROTOCOLPGM(" z: "); SERIAL_PROTOCOLPGM(" z: ");
SERIAL_PROTOCOL_F(current_position[Z_AXIS], 6); SERIAL_PROTOCOL_F(current_position[Z_AXIS], 6);
}
if (verbose_level > 2) { if (verbose_level > 2) {
SERIAL_PROTOCOL(" mean: "); SERIAL_PROTOCOLPGM(" mean: ");
SERIAL_PROTOCOL_F(mean, 6); SERIAL_PROTOCOL_F(mean,6);
SERIAL_PROTOCOL(" sigma: "); SERIAL_PROTOCOLPGM(" sigma: ");
SERIAL_PROTOCOL_F(sigma, 6); SERIAL_PROTOCOL_F(sigma,6);
}
} }
if (verbose_level > 0) SERIAL_EOL; if (verbose_level > 0) SERIAL_EOL;
...@@ -3989,11 +4018,15 @@ inline void gcode_M42() { ...@@ -3989,11 +4018,15 @@ inline void gcode_M42() {
} }
} }
if (!engage_probe_for_each_reading) {
retract_z_probe(); retract_z_probe();
delay(1000); delay(1000);
}
clean_up_after_endstop_move(); clean_up_after_endstop_move();
// enable_endstops(true);
if (verbose_level > 0) { if (verbose_level > 0) {
SERIAL_PROTOCOLPGM("Mean: "); SERIAL_PROTOCOLPGM("Mean: ");
SERIAL_PROTOCOL_F(mean, 6); SERIAL_PROTOCOL_F(mean, 6);
...@@ -6230,15 +6263,15 @@ void prepare_move() ...@@ -6230,15 +6263,15 @@ void prepare_move()
} }
#endif //DUAL_X_CARRIAGE #endif //DUAL_X_CARRIAGE
#if ! (defined DELTA || defined SCARA) #if !defined(DELTA) && !defined(SCARA)
// Do not use feedmultiply for E or Z only moves // Do not use feedmultiply for E or Z only moves
if( (current_position[X_AXIS] == destination [X_AXIS]) && (current_position[Y_AXIS] == destination [Y_AXIS])) { if( (current_position[X_AXIS] == destination [X_AXIS]) && (current_position[Y_AXIS] == destination [Y_AXIS])) {
line_to_destination(); line_to_destination();
} }
else { else {
plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate*feedmultiply/60/100.0, active_extruder, active_driver); plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], (feedrate/60)*(feedmultiply/100.0), active_extruder, active_driver);
} }
#endif // !(DELTA || SCARA) #endif // !defined(DELTA) && !defined(SCARA)
#ifdef IDLE_OOZING_PREVENT || EXTRUDER_RUNOUT_PREVENT #ifdef IDLE_OOZING_PREVENT || EXTRUDER_RUNOUT_PREVENT
axis_last_activity = millis(); axis_last_activity = millis();
......
...@@ -199,11 +199,11 @@ static void lcd_implementation_init() ...@@ -199,11 +199,11 @@ static void lcd_implementation_init()
// digitalWrite(17, HIGH); // digitalWrite(17, HIGH);
#ifdef LCD_SCREEN_ROT_90 #ifdef LCD_SCREEN_ROT_90
u8g.setRot90(); // Rotate screen by 90° u8g.setRot90(); // Rotate screen by 90
#elif defined(LCD_SCREEN_ROT_180) #elif defined(LCD_SCREEN_ROT_180)
u8g.setRot180(); // Rotate screen by 180° u8g.setRot180(); // Rotate screen by 180
#elif defined(LCD_SCREEN_ROT_270) #elif defined(LCD_SCREEN_ROT_270)
u8g.setRot270(); // Rotate screen by 270° u8g.setRot270(); // Rotate screen by 270
#endif #endif
// Show splashscreen // Show splashscreen
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment