From 3f2863244380187161b77fe2b4b9cca2b9b9945f Mon Sep 17 00:00:00 2001 From: Marek Bel Date: Mon, 24 Sep 2018 14:54:41 +0200 Subject: [PATCH] Use cs.axis_steps_per_unit from ConfigurationStore. --- Firmware/ConfigurationStore.cpp | 6 ++-- Firmware/ConfigurationStore.h | 2 +- Firmware/Marlin_main.cpp | 50 +++++++++++++------------- Firmware/fsensor.cpp | 3 +- Firmware/mesh_bed_calibration.cpp | 4 +-- Firmware/planner.cpp | 59 +++++++++++++++---------------- Firmware/planner.h | 2 -- Firmware/stepper.cpp | 9 ++--- Firmware/ultralcd.cpp | 8 ++--- 9 files changed, 71 insertions(+), 72 deletions(-) diff --git a/Firmware/ConfigurationStore.cpp b/Firmware/ConfigurationStore.cpp index 7d00742ff..08334f352 100644 --- a/Firmware/ConfigurationStore.cpp +++ b/Firmware/ConfigurationStore.cpp @@ -9,7 +9,7 @@ #include "mesh_bed_leveling.h" #endif -//M500_conf cs; +M500_conf cs; #ifdef DEBUG_EEPROM_WRITE #define EEPROM_WRITE_VAR(pos, value) _EEPROM_writeData(pos, (uint8_t*)&value, sizeof(value), #value) @@ -97,7 +97,7 @@ void Config_PrintSettings(uint8_t level) "%SAdvanced variables: S=Min feedrate (mm/s), T=Min travel feedrate (mm/s), B=minimum segment time (ms), X=maximum XY jerk (mm/s), Z=maximum Z jerk (mm/s), E=maximum E jerk (mm/s)\n%S M205 S%.2f T%.2f B%.2f X%.2f Y%.2f Z%.2f E%.2f\n" "%SHome offset (mm):\n%S M206 X%.2f Y%.2f Z%.2f\n" ), - echomagic, echomagic, axis_steps_per_unit[X_AXIS], axis_steps_per_unit[Y_AXIS], axis_steps_per_unit[Z_AXIS], axis_steps_per_unit[E_AXIS], + echomagic, echomagic, cs.axis_steps_per_unit[X_AXIS], cs.axis_steps_per_unit[Y_AXIS], cs.axis_steps_per_unit[Z_AXIS], cs.axis_steps_per_unit[E_AXIS], echomagic, echomagic, max_feedrate_normal[X_AXIS], max_feedrate_normal[Y_AXIS], max_feedrate_normal[Z_AXIS], max_feedrate_normal[E_AXIS], echomagic, echomagic, max_feedrate_silent[X_AXIS], max_feedrate_silent[Y_AXIS], max_feedrate_silent[Z_AXIS], max_feedrate_silent[E_AXIS], echomagic, echomagic, max_acceleration_units_per_sq_second_normal[X_AXIS], max_acceleration_units_per_sq_second_normal[Y_AXIS], max_acceleration_units_per_sq_second_normal[Z_AXIS], max_acceleration_units_per_sq_second_normal[E_AXIS], @@ -114,7 +114,7 @@ void Config_PrintSettings(uint8_t level) "%SAdvanced variables: S=Min feedrate (mm/s), T=Min travel feedrate (mm/s), B=minimum segment time (ms), X=maximum XY jerk (mm/s), Z=maximum Z jerk (mm/s), E=maximum E jerk (mm/s)\n%S M205 S%.2f T%.2f B%.2f X%.2f Y%.2f Z%.2f E%.2f\n" "%SHome offset (mm):\n%S M206 X%.2f Y%.2f Z%.2f\n" ), - echomagic, echomagic, axis_steps_per_unit[X_AXIS], axis_steps_per_unit[Y_AXIS], axis_steps_per_unit[Z_AXIS], axis_steps_per_unit[E_AXIS], + echomagic, echomagic, cs.axis_steps_per_unit[X_AXIS], cs.axis_steps_per_unit[Y_AXIS], cs.axis_steps_per_unit[Z_AXIS], cs.axis_steps_per_unit[E_AXIS], echomagic, echomagic, max_feedrate[X_AXIS], max_feedrate[Y_AXIS], max_feedrate[Z_AXIS], max_feedrate[E_AXIS], echomagic, echomagic, max_acceleration_units_per_sq_second[X_AXIS], max_acceleration_units_per_sq_second[Y_AXIS], max_acceleration_units_per_sq_second[Z_AXIS], max_acceleration_units_per_sq_second[E_AXIS], echomagic, echomagic, acceleration, retract_acceleration, diff --git a/Firmware/ConfigurationStore.h b/Firmware/ConfigurationStore.h index 7837a56eb..761af1c80 100644 --- a/Firmware/ConfigurationStore.h +++ b/Firmware/ConfigurationStore.h @@ -37,7 +37,7 @@ typedef struct unsigned long max_acceleration_units_per_sq_second_silent[4]; } __attribute__ ((packed)) M500_conf; -//extern M500_conf cs; +extern M500_conf cs; void Config_ResetDefault(); diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 2544dce6c..cb24202b9 100644 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -3054,13 +3054,13 @@ void gcode_M114() SERIAL_PROTOCOL(current_position[E_AXIS]); SERIAL_PROTOCOLRPGM(_n(" Count X: "));////MSG_COUNT_X c=0 r=0 - SERIAL_PROTOCOL(float(st_get_position(X_AXIS)) / axis_steps_per_unit[X_AXIS]); + SERIAL_PROTOCOL(float(st_get_position(X_AXIS)) / cs.axis_steps_per_unit[X_AXIS]); SERIAL_PROTOCOLPGM(" Y:"); - SERIAL_PROTOCOL(float(st_get_position(Y_AXIS)) / axis_steps_per_unit[Y_AXIS]); + SERIAL_PROTOCOL(float(st_get_position(Y_AXIS)) / cs.axis_steps_per_unit[Y_AXIS]); SERIAL_PROTOCOLPGM(" Z:"); - SERIAL_PROTOCOL(float(st_get_position(Z_AXIS)) / axis_steps_per_unit[Z_AXIS]); + SERIAL_PROTOCOL(float(st_get_position(Z_AXIS)) / cs.axis_steps_per_unit[Z_AXIS]); SERIAL_PROTOCOLPGM(" E:"); - SERIAL_PROTOCOL(float(st_get_position(E_AXIS)) / axis_steps_per_unit[E_AXIS]); + SERIAL_PROTOCOL(float(st_get_position(E_AXIS)) / cs.axis_steps_per_unit[E_AXIS]); SERIAL_PROTOCOLLN(""); } @@ -3942,7 +3942,7 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) // The following code 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. // When the bed is uneven, this height must be corrected. - 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) + real_z = float(st_get_position(Z_AXIS))/cs.axis_steps_per_unit[Z_AXIS]; //get the real Z (since the auto bed leveling is already correcting the plane) x_tmp = current_position[X_AXIS] + X_PROBE_OFFSET_FROM_EXTRUDER; y_tmp = current_position[Y_AXIS] + Y_PROBE_OFFSET_FROM_EXTRUDER; z_tmp = current_position[Z_AXIS]; @@ -4148,7 +4148,7 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) lcd_temp_cal_show_result(find_z_result); break; } - z_shift = (int)((current_position[Z_AXIS] - zero_z)*axis_steps_per_unit[Z_AXIS]); + z_shift = (int)((current_position[Z_AXIS] - zero_z)*cs.axis_steps_per_unit[Z_AXIS]); printf_P(_N("\nPINDA temperature: %.1f Z shift (mm): %.3f"), current_temperature_pinda, current_position[Z_AXIS] - zero_z); @@ -4235,7 +4235,7 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 3000 / 60, active_extruder); st_synchronize(); find_bed_induction_sensor_point_z(-1.f); - z_shift = (int)((current_position[Z_AXIS] - zero_z)*axis_steps_per_unit[Z_AXIS]); + z_shift = (int)((current_position[Z_AXIS] - zero_z)*cs.axis_steps_per_unit[Z_AXIS]); printf_P(_N("\nTemperature: %d Z shift (mm): %.3f\n"), t_c, current_position[Z_AXIS] - zero_z); @@ -5699,15 +5699,15 @@ Sigma_Exit: if(i == 3) { // E float value = code_value(); if(value < 20.0) { - float factor = axis_steps_per_unit[i] / value; // increase e constants if M92 E14 is given for netfab. + float factor = cs.axis_steps_per_unit[i] / value; // increase e constants if M92 E14 is given for netfab. max_jerk[E_AXIS] *= factor; max_feedrate[i] *= factor; axis_steps_per_sqr_second[i] *= factor; } - axis_steps_per_unit[i] = value; + cs.axis_steps_per_unit[i] = value; } else { - axis_steps_per_unit[i] = code_value(); + cs.axis_steps_per_unit[i] = code_value(); } } } @@ -5905,7 +5905,7 @@ Sigma_Exit: #if 0 // Not used for Sprinter/grbl gen6 case 202: // M202 for(int8_t 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]; + if(code_seen(axis_codes[i])) axis_travel_steps_per_sqr_second[i] = code_value() * cs.axis_steps_per_unit[i]; } break; #endif @@ -6548,7 +6548,7 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) for (uint8_t i = 0; i < 6; i++) { if(i>0) EEPROM_read_B(EEPROM_PROBE_TEMP_SHIFT + (i-1) * 2, &usteps); - float mm = ((float)usteps) / axis_steps_per_unit[Z_AXIS]; + float mm = ((float)usteps) / cs.axis_steps_per_unit[Z_AXIS]; i == 0 ? SERIAL_PROTOCOLPGM("n/a") : SERIAL_PROTOCOL(i - 1); SERIAL_PROTOCOLPGM(", "); SERIAL_PROTOCOL(35 + (i * 5)); @@ -6591,7 +6591,7 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) { usteps = 0; if (i>0) EEPROM_read_B(EEPROM_PROBE_TEMP_SHIFT + (i - 1) * 2, &usteps); - float mm = ((float)usteps) / axis_steps_per_unit[Z_AXIS]; + float mm = ((float)usteps) / cs.axis_steps_per_unit[Z_AXIS]; i == 0 ? SERIAL_PROTOCOLPGM("n/a") : SERIAL_PROTOCOL(i - 1); SERIAL_PROTOCOLPGM(", "); SERIAL_PROTOCOL(35 + (i * 5)); @@ -6740,13 +6740,13 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) if (res_new > res) { uint16_t fac = (res_new / res); - axis_steps_per_unit[axis] *= fac; + cs.axis_steps_per_unit[axis] *= fac; position[E_AXIS] *= fac; } else { uint16_t fac = (res / res_new); - axis_steps_per_unit[axis] /= fac; + cs.axis_steps_per_unit[axis] /= fac; position[E_AXIS] /= fac; } } @@ -7450,8 +7450,8 @@ void manage_inactivity(bool ignore_stepper_queue/*=false*/) //default argument s float oldepos=current_position[E_AXIS]; float oldedes=destination[E_AXIS]; plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], - destination[E_AXIS]+EXTRUDER_RUNOUT_EXTRUDE*EXTRUDER_RUNOUT_ESTEPS/axis_steps_per_unit[E_AXIS], - EXTRUDER_RUNOUT_SPEED/60.*EXTRUDER_RUNOUT_ESTEPS/axis_steps_per_unit[E_AXIS], active_extruder); + destination[E_AXIS]+EXTRUDER_RUNOUT_EXTRUDE*EXTRUDER_RUNOUT_ESTEPS/cs.axis_steps_per_unit[E_AXIS], + EXTRUDER_RUNOUT_SPEED/60.*EXTRUDER_RUNOUT_ESTEPS/cs.axis_steps_per_unit[E_AXIS], active_extruder); current_position[E_AXIS]=oldepos; destination[E_AXIS]=oldedes; plan_set_e_position(oldepos); @@ -8030,10 +8030,10 @@ void temp_compensation_apply() { if (target_temperature_bed % 10 == 0 && target_temperature_bed >= 60 && target_temperature_bed <= 100) { i_add = (target_temperature_bed - 60) / 10; EEPROM_read_B(EEPROM_PROBE_TEMP_SHIFT + i_add * 2, &z_shift); - z_shift_mm = z_shift / axis_steps_per_unit[Z_AXIS]; + z_shift_mm = z_shift / cs.axis_steps_per_unit[Z_AXIS]; }else { //interpolation - z_shift_mm = temp_comp_interpolation(target_temperature_bed) / axis_steps_per_unit[Z_AXIS]; + z_shift_mm = temp_comp_interpolation(target_temperature_bed) / cs.axis_steps_per_unit[Z_AXIS]; } printf_P(_N("\nZ shift applied:%.3f\n"), z_shift_mm); plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS] - z_shift_mm, current_position[E_AXIS], homing_feedrate[Z_AXIS] / 40, active_extruder); @@ -8116,7 +8116,7 @@ float temp_compensation_pinda_thermistor_offset(float temperature_pinda) { if (!temp_cal_active) return 0; if (!calibration_status_pinda()) return 0; - return temp_comp_interpolation(temperature_pinda) / axis_steps_per_unit[Z_AXIS]; + return temp_comp_interpolation(temperature_pinda) / cs.axis_steps_per_unit[Z_AXIS]; } #endif //PINDA_THERMISTOR @@ -8246,7 +8246,7 @@ void uvlo_() plan_buffer_line( current_position[X_AXIS], current_position[Y_AXIS], - current_position[Z_AXIS] + UVLO_Z_AXIS_SHIFT + float((1024 - z_microsteps + 7) >> 4) / axis_steps_per_unit[Z_AXIS], + current_position[Z_AXIS] + UVLO_Z_AXIS_SHIFT + float((1024 - z_microsteps + 7) >> 4) / cs.axis_steps_per_unit[Z_AXIS], current_position[E_AXIS] - default_retraction, 40, active_extruder); @@ -8256,7 +8256,7 @@ void uvlo_() plan_buffer_line( current_position[X_AXIS], current_position[Y_AXIS], - current_position[Z_AXIS] + UVLO_Z_AXIS_SHIFT + float((1024 - z_microsteps + 7) >> 4) / axis_steps_per_unit[Z_AXIS], + current_position[Z_AXIS] + UVLO_Z_AXIS_SHIFT + float((1024 - z_microsteps + 7) >> 4) / cs.axis_steps_per_unit[Z_AXIS], current_position[E_AXIS] - default_retraction, 40, active_extruder); st_synchronize(); @@ -8348,7 +8348,7 @@ plan_buffer_line( current_position[X_AXIS], current_position[Y_AXIS], // current_position[Z_AXIS]+float((1024-z_microsteps+7)>>4)/axis_steps_per_unit[Z_AXIS], - current_position[Z_AXIS]+UVLO_Z_AXIS_SHIFT+float((1024-z_microsteps+7)>>4)/axis_steps_per_unit[Z_AXIS], + current_position[Z_AXIS]+UVLO_Z_AXIS_SHIFT+float((1024-z_microsteps+7)>>4)/cs.axis_steps_per_unit[Z_AXIS], current_position[E_AXIS], 40, active_extruder); st_synchronize(); @@ -8472,10 +8472,10 @@ void recover_machine_state_after_power_panic(bool bTiny) // The current position after power panic is moved to the next closest 0th full step. if(bTiny) current_position[Z_AXIS] = eeprom_read_float((float*)(EEPROM_UVLO_TINY_CURRENT_POSITION_Z)) + - UVLO_Z_AXIS_SHIFT + float((1024 - eeprom_read_word((uint16_t*)(EEPROM_UVLO_TINY_Z_MICROSTEPS)) + 7) >> 4) / axis_steps_per_unit[Z_AXIS]; + UVLO_Z_AXIS_SHIFT + float((1024 - eeprom_read_word((uint16_t*)(EEPROM_UVLO_TINY_Z_MICROSTEPS)) + 7) >> 4) / cs.axis_steps_per_unit[Z_AXIS]; else current_position[Z_AXIS] = eeprom_read_float((float*)(EEPROM_UVLO_CURRENT_POSITION_Z)) + - UVLO_Z_AXIS_SHIFT + float((1024 - eeprom_read_word((uint16_t*)(EEPROM_UVLO_Z_MICROSTEPS)) + 7) >> 4) / axis_steps_per_unit[Z_AXIS]; + UVLO_Z_AXIS_SHIFT + float((1024 - eeprom_read_word((uint16_t*)(EEPROM_UVLO_Z_MICROSTEPS)) + 7) >> 4) / cs.axis_steps_per_unit[Z_AXIS]; if (eeprom_read_byte((uint8_t*)EEPROM_UVLO_E_ABS)) { current_position[E_AXIS] = eeprom_read_float((float*)(EEPROM_UVLO_CURRENT_POSITION_E)); sprintf_P(cmd, PSTR("G92 E")); diff --git a/Firmware/fsensor.cpp b/Firmware/fsensor.cpp index c46572937..d2608da4f 100644 --- a/Firmware/fsensor.cpp +++ b/Firmware/fsensor.cpp @@ -7,6 +7,7 @@ #include "planner.h" #include "fastio.h" #include "cmdqueue.h" +#include "ConfigurationStore.h" //Basic params #define FSENSOR_CHUNK_LEN 0.64F //filament sensor chunk length 0.64mm @@ -114,7 +115,7 @@ void fsensor_init(void) printf_P(PSTR("PAT9125_init:%hhu\n"), pat9125); uint8_t fsensor = eeprom_read_byte((uint8_t*)EEPROM_FSENSOR); fsensor_autoload_enabled=eeprom_read_byte((uint8_t*)EEPROM_FSENS_AUTOLOAD_ENABLED); - fsensor_chunk_len = (int16_t)(FSENSOR_CHUNK_LEN * axis_steps_per_unit[E_AXIS]); + fsensor_chunk_len = (int16_t)(FSENSOR_CHUNK_LEN * cs.axis_steps_per_unit[E_AXIS]); if (!pat9125) { diff --git a/Firmware/mesh_bed_calibration.cpp b/Firmware/mesh_bed_calibration.cpp index 102aebaed..9cb48c147 100644 --- a/Firmware/mesh_bed_calibration.cpp +++ b/Firmware/mesh_bed_calibration.cpp @@ -3009,7 +3009,7 @@ void babystep_apply() { babystep_load(); #ifdef BABYSTEP_LOADZ_BY_PLANNER - shift_z(- float(babystepLoadZ) / float(axis_steps_per_unit[Z_AXIS])); + shift_z(- float(babystepLoadZ) / float(cs.axis_steps_per_unit[Z_AXIS])); #else babystepsTodoZadd(babystepLoadZ); #endif /* BABYSTEP_LOADZ_BY_PLANNER */ @@ -3018,7 +3018,7 @@ void babystep_apply() void babystep_undo() { #ifdef BABYSTEP_LOADZ_BY_PLANNER - shift_z(float(babystepLoadZ) / float(axis_steps_per_unit[Z_AXIS])); + shift_z(float(babystepLoadZ) / float(cs.axis_steps_per_unit[Z_AXIS])); #else babystepsTodoZsubtract(babystepLoadZ); #endif /* BABYSTEP_LOADZ_BY_PLANNER */ diff --git a/Firmware/planner.cpp b/Firmware/planner.cpp index 058fd2a9d..ef8ba5a8b 100644 --- a/Firmware/planner.cpp +++ b/Firmware/planner.cpp @@ -57,6 +57,7 @@ #include "temperature.h" #include "ultralcd.h" #include "language.h" +#include "ConfigurationStore.h" #ifdef MESH_BED_LEVELING #include "mesh_bed_leveling.h" @@ -78,8 +79,6 @@ float max_feedrate_normal[NUM_AXIS]; // max speeds for normal mode float max_feedrate_silent[NUM_AXIS]; // max speeds for silent mode float* max_feedrate = max_feedrate_normal; -// Use M92 to override by software -float axis_steps_per_unit[NUM_AXIS]; // Use M201 to override by software unsigned long max_acceleration_units_per_sq_second_normal[NUM_AXIS]; @@ -623,9 +622,9 @@ void planner_abort_hard() else { float t = float(step_events_completed) / float(current_block->step_event_count); float vec[3] = { - current_block->steps_x / axis_steps_per_unit[X_AXIS], - current_block->steps_y / axis_steps_per_unit[Y_AXIS], - current_block->steps_z / axis_steps_per_unit[Z_AXIS] + current_block->steps_x / cs.axis_steps_per_unit[X_AXIS], + current_block->steps_y / cs.axis_steps_per_unit[Y_AXIS], + current_block->steps_z / cs.axis_steps_per_unit[Z_AXIS] }; float pos1[3], pos2[3]; for (int8_t i = 0; i < 3; ++ i) { @@ -743,18 +742,18 @@ void plan_buffer_line(float x, float y, float z, const float &e, float feed_rate // Calculate target position in absolute steps //this should be done after the wait, because otherwise a M92 code within the gcode disrupts this calculation somehow long target[4]; - target[X_AXIS] = lround(x*axis_steps_per_unit[X_AXIS]); - target[Y_AXIS] = lround(y*axis_steps_per_unit[Y_AXIS]); + target[X_AXIS] = lround(x*cs.axis_steps_per_unit[X_AXIS]); + target[Y_AXIS] = lround(y*cs.axis_steps_per_unit[Y_AXIS]); #ifdef MESH_BED_LEVELING if (mbl.active){ - target[Z_AXIS] = lround((z+mbl.get_z(x, y))*axis_steps_per_unit[Z_AXIS]); + target[Z_AXIS] = lround((z+mbl.get_z(x, y))*cs.axis_steps_per_unit[Z_AXIS]); }else{ - target[Z_AXIS] = lround(z*axis_steps_per_unit[Z_AXIS]); + target[Z_AXIS] = lround(z*cs.axis_steps_per_unit[Z_AXIS]); } #else - target[Z_AXIS] = lround(z*axis_steps_per_unit[Z_AXIS]); + target[Z_AXIS] = lround(z*cs.axis_steps_per_unit[Z_AXIS]); #endif // ENABLE_MESH_BED_LEVELING - target[E_AXIS] = lround(e*axis_steps_per_unit[E_AXIS]); + target[E_AXIS] = lround(e*cs.axis_steps_per_unit[E_AXIS]); #ifdef LIN_ADVANCE const float mm_D_float = sqrt(sq(x - position_float[X_AXIS]) + sq(y - position_float[Y_AXIS])); @@ -776,7 +775,7 @@ void plan_buffer_line(float x, float y, float z, const float &e, float feed_rate } #ifdef PREVENT_LENGTHY_EXTRUDE - if(labs(target[E_AXIS]-position[E_AXIS])>axis_steps_per_unit[E_AXIS]*EXTRUDE_MAXLENGTH) + if(labs(target[E_AXIS]-position[E_AXIS])>cs.axis_steps_per_unit[E_AXIS]*EXTRUDE_MAXLENGTH) { position[E_AXIS]=target[E_AXIS]; //behave as if the move really took place, but ignore E part #ifdef LIN_ADVANCE @@ -931,17 +930,17 @@ Having the real displacement of the head, we can calculate the total movement le */ #ifndef COREXY float delta_mm[4]; - delta_mm[X_AXIS] = (target[X_AXIS]-position[X_AXIS])/axis_steps_per_unit[X_AXIS]; - delta_mm[Y_AXIS] = (target[Y_AXIS]-position[Y_AXIS])/axis_steps_per_unit[Y_AXIS]; + delta_mm[X_AXIS] = (target[X_AXIS]-position[X_AXIS])/cs.axis_steps_per_unit[X_AXIS]; + delta_mm[Y_AXIS] = (target[Y_AXIS]-position[Y_AXIS])/cs.axis_steps_per_unit[Y_AXIS]; #else float delta_mm[6]; - delta_mm[X_HEAD] = (target[X_AXIS]-position[X_AXIS])/axis_steps_per_unit[X_AXIS]; - delta_mm[Y_HEAD] = (target[Y_AXIS]-position[Y_AXIS])/axis_steps_per_unit[Y_AXIS]; - delta_mm[X_AXIS] = ((target[X_AXIS]-position[X_AXIS]) + (target[Y_AXIS]-position[Y_AXIS]))/axis_steps_per_unit[X_AXIS]; - delta_mm[Y_AXIS] = ((target[X_AXIS]-position[X_AXIS]) - (target[Y_AXIS]-position[Y_AXIS]))/axis_steps_per_unit[Y_AXIS]; + delta_mm[X_HEAD] = (target[X_AXIS]-position[X_AXIS])/cs.axis_steps_per_unit[X_AXIS]; + delta_mm[Y_HEAD] = (target[Y_AXIS]-position[Y_AXIS])/cs.axis_steps_per_unit[Y_AXIS]; + delta_mm[X_AXIS] = ((target[X_AXIS]-position[X_AXIS]) + (target[Y_AXIS]-position[Y_AXIS]))/cs.axis_steps_per_unit[X_AXIS]; + delta_mm[Y_AXIS] = ((target[X_AXIS]-position[X_AXIS]) - (target[Y_AXIS]-position[Y_AXIS]))/cs.axis_steps_per_unit[Y_AXIS]; #endif - delta_mm[Z_AXIS] = (target[Z_AXIS]-position[Z_AXIS])/axis_steps_per_unit[Z_AXIS]; - delta_mm[E_AXIS] = (target[E_AXIS]-position[E_AXIS])/axis_steps_per_unit[E_AXIS]; + delta_mm[Z_AXIS] = (target[Z_AXIS]-position[Z_AXIS])/cs.axis_steps_per_unit[Z_AXIS]; + delta_mm[E_AXIS] = (target[E_AXIS]-position[E_AXIS])/cs.axis_steps_per_unit[E_AXIS]; if ( block->steps_x.wide <=dropsegments && block->steps_y.wide <=dropsegments && block->steps_z.wide <=dropsegments ) { block->millimeters = fabs(delta_mm[E_AXIS]); @@ -1188,7 +1187,7 @@ Having the real displacement of the head, we can calculate the total movement le extruder_advance_k * ((advance_ed_ratio < 0.000001) ? de_float / mm_D_float : advance_ed_ratio) // Use the fixed ratio, if set * (block->nominal_speed / (float)block->nominal_rate) - * axis_steps_per_unit[E_AXIS] * 256.0 + * cs.axis_steps_per_unit[E_AXIS] * 256.0 ); #endif @@ -1263,16 +1262,16 @@ void plan_set_position(float x, float y, float z, const float &e) y = world2machine_rotation_and_skew[1][0] * tmpx + world2machine_rotation_and_skew[1][1] * tmpy + world2machine_shift[1]; } - position[X_AXIS] = lround(x*axis_steps_per_unit[X_AXIS]); - position[Y_AXIS] = lround(y*axis_steps_per_unit[Y_AXIS]); + position[X_AXIS] = lround(x*cs.axis_steps_per_unit[X_AXIS]); + position[Y_AXIS] = lround(y*cs.axis_steps_per_unit[Y_AXIS]); #ifdef MESH_BED_LEVELING position[Z_AXIS] = mbl.active ? - lround((z+mbl.get_z(x, y))*axis_steps_per_unit[Z_AXIS]) : - lround(z*axis_steps_per_unit[Z_AXIS]); + lround((z+mbl.get_z(x, y))*cs.axis_steps_per_unit[Z_AXIS]) : + lround(z*cs.axis_steps_per_unit[Z_AXIS]); #else - position[Z_AXIS] = lround(z*axis_steps_per_unit[Z_AXIS]); + position[Z_AXIS] = lround(z*cs.axis_steps_per_unit[Z_AXIS]); #endif // ENABLE_MESH_BED_LEVELING - position[E_AXIS] = lround(e*axis_steps_per_unit[E_AXIS]); + position[E_AXIS] = lround(e*cs.axis_steps_per_unit[E_AXIS]); #ifdef LIN_ADVANCE position_float[X_AXIS] = x; position_float[Y_AXIS] = y; @@ -1293,7 +1292,7 @@ void plan_set_z_position(const float &z) #ifdef LIN_ADVANCE position_float[Z_AXIS] = z; #endif - position[Z_AXIS] = lround(z*axis_steps_per_unit[Z_AXIS]); + position[Z_AXIS] = lround(z*cs.axis_steps_per_unit[Z_AXIS]); st_set_position(position[X_AXIS], position[Y_AXIS], position[Z_AXIS], position[E_AXIS]); } @@ -1302,7 +1301,7 @@ void plan_set_e_position(const float &e) #ifdef LIN_ADVANCE position_float[E_AXIS] = e; #endif - position[E_AXIS] = lround(e*axis_steps_per_unit[E_AXIS]); + position[E_AXIS] = lround(e*cs.axis_steps_per_unit[E_AXIS]); st_set_e_position(position[E_AXIS]); } @@ -1317,7 +1316,7 @@ void set_extrude_min_temp(float temp) void reset_acceleration_rates() { for(int8_t i=0; i < NUM_AXIS; i++) - axis_steps_per_sqr_second[i] = max_acceleration_units_per_sq_second[i] * axis_steps_per_unit[i]; + axis_steps_per_sqr_second[i] = max_acceleration_units_per_sq_second[i] * cs.axis_steps_per_unit[i]; } #ifdef TMC2130 diff --git a/Firmware/planner.h b/Firmware/planner.h index 998a3595b..5f9f2cb80 100644 --- a/Firmware/planner.h +++ b/Firmware/planner.h @@ -165,8 +165,6 @@ extern float max_feedrate_normal[NUM_AXIS]; extern float max_feedrate_silent[NUM_AXIS]; extern float* max_feedrate; -// Use M92 to override by software -extern float axis_steps_per_unit[NUM_AXIS]; // Use M201 to override by software extern unsigned long max_acceleration_units_per_sq_second_normal[NUM_AXIS]; diff --git a/Firmware/stepper.cpp b/Firmware/stepper.cpp index 45175c028..7218aa6a6 100644 --- a/Firmware/stepper.cpp +++ b/Firmware/stepper.cpp @@ -42,6 +42,7 @@ int fsensor_counter = 0; //counter for e-steps #endif //FILAMENT_SENSOR #include "mmu.h" +#include "ConfigurationStore.h" #ifdef DEBUG_STACK_MONITOR uint16_t SP_min = 0x21FF; @@ -231,15 +232,15 @@ void checkHitEndstops() SERIAL_ECHO_START; SERIAL_ECHORPGM(_T(MSG_ENDSTOPS_HIT)); if(endstop_x_hit) { - SERIAL_ECHOPAIR(" X:",(float)endstops_trigsteps[X_AXIS]/axis_steps_per_unit[X_AXIS]); + SERIAL_ECHOPAIR(" X:",(float)endstops_trigsteps[X_AXIS]/cs.axis_steps_per_unit[X_AXIS]); // LCD_MESSAGERPGM(CAT2(_T(MSG_ENDSTOPS_HIT), PSTR("X"))); } if(endstop_y_hit) { - SERIAL_ECHOPAIR(" Y:",(float)endstops_trigsteps[Y_AXIS]/axis_steps_per_unit[Y_AXIS]); + SERIAL_ECHOPAIR(" Y:",(float)endstops_trigsteps[Y_AXIS]/cs.axis_steps_per_unit[Y_AXIS]); // LCD_MESSAGERPGM(CAT2(_T(MSG_ENDSTOPS_HIT), PSTR("Y"))); } if(endstop_z_hit) { - SERIAL_ECHOPAIR(" Z:",(float)endstops_trigsteps[Z_AXIS]/axis_steps_per_unit[Z_AXIS]); + SERIAL_ECHOPAIR(" Z:",(float)endstops_trigsteps[Z_AXIS]/cs.axis_steps_per_unit[Z_AXIS]); // LCD_MESSAGERPGM(CAT2(_T(MSG_ENDSTOPS_HIT),PSTR("Z"))); } SERIAL_ECHOLN(""); @@ -1390,7 +1391,7 @@ void st_get_position_xy(long &x, long &y) float st_get_position_mm(uint8_t axis) { float steper_position_in_steps = st_get_position(axis); - return steper_position_in_steps / axis_steps_per_unit[axis]; + return steper_position_in_steps / cs.axis_steps_per_unit[axis]; } diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index b78b4c97b..3e7db0206 100644 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -2764,9 +2764,9 @@ static void _lcd_babystep(int axis, const char *msg) if (calibration_status() >= CALIBRATION_STATUS_LIVE_ADJUST) _md->babystepMem[2] = 0; - _md->babystepMemMM[0] = _md->babystepMem[0]/axis_steps_per_unit[X_AXIS]; - _md->babystepMemMM[1] = _md->babystepMem[1]/axis_steps_per_unit[Y_AXIS]; - _md->babystepMemMM[2] = _md->babystepMem[2]/axis_steps_per_unit[Z_AXIS]; + _md->babystepMemMM[0] = _md->babystepMem[0]/cs.axis_steps_per_unit[X_AXIS]; + _md->babystepMemMM[1] = _md->babystepMem[1]/cs.axis_steps_per_unit[Y_AXIS]; + _md->babystepMemMM[2] = _md->babystepMem[2]/cs.axis_steps_per_unit[Z_AXIS]; lcd_draw_update = 1; //SERIAL_ECHO("Z baby step: "); //SERIAL_ECHO(_md->babystepMem[2]); @@ -2789,7 +2789,7 @@ static void _lcd_babystep(int axis, const char *msg) CRITICAL_SECTION_END } } - _md->babystepMemMM[axis] = _md->babystepMem[axis]/axis_steps_per_unit[axis]; + _md->babystepMemMM[axis] = _md->babystepMem[axis]/cs.axis_steps_per_unit[axis]; delay(50); lcd_encoder = 0; lcd_draw_update = 1;