Commit 439d4e2c authored by MagoKimbra's avatar MagoKimbra

Rewrite Marlin. Insert specific fuction for G-code

parent a00a83f3
...@@ -371,8 +371,8 @@ int fanSpeed = 0; ...@@ -371,8 +371,8 @@ int fanSpeed = 0;
#endif #endif
#endif //ULTIPANEL #endif //ULTIPANEL
#ifdef SCARA // Build size scaling #ifdef SCARA
float axis_scaling[3]={1,1,1}; // Build size scaling, default to 1 float axis_scaling[3] = { 1, 1, 1 }; // Build size scaling, default to 1
#endif //SCARA #endif //SCARA
bool cancel_heatup = false; bool cancel_heatup = false;
...@@ -432,6 +432,7 @@ static bool fromsd[BUFSIZE]; ...@@ -432,6 +432,7 @@ static bool fromsd[BUFSIZE];
static int bufindr = 0; static int bufindr = 0;
static int bufindw = 0; static int bufindw = 0;
static int buflen = 0; static int buflen = 0;
static char serial_char; static char serial_char;
static int serial_count = 0; static int serial_count = 0;
static boolean comment_mode = false; static boolean comment_mode = false;
...@@ -577,6 +578,16 @@ void setup_photpin() ...@@ -577,6 +578,16 @@ void setup_photpin()
#endif #endif
} }
void setup_laserbeampin()
{
#ifdef LASERBEAM
SET_OUTPUT(LASER_PWR_PIN);
WRITE(LASER_PWR_PIN, LOW);
SET_OUTPUT(LASER_TTL_PIN);
WRITE(LASER_TTL_PIN, LOW);
#endif
}
void setup_powerhold() void setup_powerhold()
{ {
#if defined(SUICIDE_PIN) && SUICIDE_PIN > -1 #if defined(SUICIDE_PIN) && SUICIDE_PIN > -1
...@@ -636,8 +647,8 @@ void servo_init() ...@@ -636,8 +647,8 @@ void servo_init()
} }
void setup() void setup() {
{
setup_killpin(); setup_killpin();
setup_pausepin(); setup_pausepin();
...@@ -686,15 +697,9 @@ void setup() ...@@ -686,15 +697,9 @@ void setup()
watchdog_init(); watchdog_init();
st_init(); // Initialize stepper, this enables interrupts! st_init(); // Initialize stepper, this enables interrupts!
setup_photpin(); setup_photpin();
#ifdef LASERBEAM // Initialize Laser beam setup_laserbeampin(); // Initialize Laserbeam
SET_OUTPUT(LASER_PWR_PIN);
WRITE(LASER_PWR_PIN, LOW);
SET_OUTPUT(LASER_TTL_PIN);
WRITE(LASER_TTL_PIN, LOW);
#endif
servo_init(); servo_init();
lcd_init(); lcd_init();
_delay_ms(1000); // wait 1sec to display the splash screen _delay_ms(1000); // wait 1sec to display the splash screen
...@@ -716,38 +721,30 @@ void setup() ...@@ -716,38 +721,30 @@ void setup()
} }
void loop() void loop() {
{
if(buflen < (BUFSIZE-1)) if (buflen < (BUFSIZE-1)) get_command();
get_command();
#ifdef SDSUPPORT #ifdef SDSUPPORT
card.checkautostart(false); card.checkautostart(false);
#endif #endif
if(buflen) if(buflen) {
{
#ifdef SDSUPPORT #ifdef SDSUPPORT
if(card.saving) if(card.saving) {
{ if(strstr_P(cmdbuffer[bufindr], PSTR("M29")) == NULL) {
if(strstr_P(cmdbuffer[bufindr], PSTR("M29")) == NULL)
{
card.write_command(cmdbuffer[bufindr]); card.write_command(cmdbuffer[bufindr]);
if(card.logging) if(card.logging) {
{
process_commands(); process_commands();
} }
else else {
{
SERIAL_PROTOCOLLNPGM(MSG_OK); SERIAL_PROTOCOLLNPGM(MSG_OK);
} }
} }
else else {
{
card.closefile(); card.closefile();
SERIAL_PROTOCOLLNPGM(MSG_FILE_SAVED); SERIAL_PROTOCOLLNPGM(MSG_FILE_SAVED);
} }
} }
else else {
{
process_commands(); process_commands();
} }
#else #else
...@@ -763,8 +760,8 @@ void loop() ...@@ -763,8 +760,8 @@ void loop()
lcd_update(); lcd_update();
} }
void get_command() void get_command() {
{
while( MYSERIAL.available() > 0 && buflen < BUFSIZE) { while( MYSERIAL.available() > 0 && buflen < BUFSIZE) {
serial_char = MYSERIAL.read(); serial_char = MYSERIAL.read();
if(serial_char == '\n' || if(serial_char == '\n' ||
...@@ -777,11 +774,10 @@ void get_command() ...@@ -777,11 +774,10 @@ void get_command()
return; return;
} }
cmdbuffer[bufindw][serial_count] = 0; //terminate string cmdbuffer[bufindw][serial_count] = 0; //terminate string
if(!comment_mode){ if(!comment_mode) {
comment_mode = false; //for new command comment_mode = false; //for new command
fromsd[bufindw] = false; fromsd[bufindw] = false;
if(strchr(cmdbuffer[bufindw], 'N') != NULL) if(strchr(cmdbuffer[bufindw], 'N') != NULL) {
{
strchr_pointer = strchr(cmdbuffer[bufindw], 'N'); strchr_pointer = strchr(cmdbuffer[bufindw], 'N');
gcode_N = (strtol(&cmdbuffer[bufindw][strchr_pointer - cmdbuffer[bufindw] + 1], NULL, 10)); gcode_N = (strtol(&cmdbuffer[bufindw][strchr_pointer - cmdbuffer[bufindw] + 1], NULL, 10));
if(gcode_N != gcode_LastN+1 && (strstr_P(cmdbuffer[bufindw], PSTR("M110")) == NULL) ) { if(gcode_N != gcode_LastN+1 && (strstr_P(cmdbuffer[bufindw], PSTR("M110")) == NULL) ) {
...@@ -794,8 +790,7 @@ void get_command() ...@@ -794,8 +790,7 @@ void get_command()
return; return;
} }
if(strchr(cmdbuffer[bufindw], '*') != NULL) if(strchr(cmdbuffer[bufindw], '*') != NULL) {
{
byte checksum = 0; byte checksum = 0;
byte count = 0; byte count = 0;
while(cmdbuffer[bufindw][count] != '*') checksum = checksum^cmdbuffer[bufindw][count++]; while(cmdbuffer[bufindw][count] != '*') checksum = checksum^cmdbuffer[bufindw][count++];
...@@ -826,8 +821,7 @@ void get_command() ...@@ -826,8 +821,7 @@ void get_command()
} }
else // if we don't receive 'N' but still see '*' else // if we don't receive 'N' but still see '*'
{ {
if((strchr(cmdbuffer[bufindw], '*') != NULL)) if((strchr(cmdbuffer[bufindw], '*') != NULL)) {
{
SERIAL_ERROR_START; SERIAL_ERROR_START;
SERIAL_ERRORPGM(MSG_ERR_NO_LINENUMBER_WITH_CHECKSUM); SERIAL_ERRORPGM(MSG_ERR_NO_LINENUMBER_WITH_CHECKSUM);
SERIAL_ERRORLN(gcode_LastN); SERIAL_ERRORLN(gcode_LastN);
...@@ -835,7 +829,7 @@ void get_command() ...@@ -835,7 +829,7 @@ void get_command()
return; return;
} }
} }
if((strchr(cmdbuffer[bufindw], 'G') != NULL)){ if((strchr(cmdbuffer[bufindw], 'G') != NULL)) {
strchr_pointer = strchr(cmdbuffer[bufindw], 'G'); strchr_pointer = strchr(cmdbuffer[bufindw], 'G');
switch((int)((strtod(&cmdbuffer[bufindw][strchr_pointer - cmdbuffer[bufindw] + 1], NULL)))){ switch((int)((strtod(&cmdbuffer[bufindw][strchr_pointer - cmdbuffer[bufindw] + 1], NULL)))){
case 0: case 0:
...@@ -850,12 +844,10 @@ void get_command() ...@@ -850,12 +844,10 @@ void get_command()
default: default:
break; break;
} }
} }
//If command was e-stop process now //If command was e-stop process now
if(strcmp(cmdbuffer[bufindw], "M112") == 0) if(strcmp(cmdbuffer[bufindw], "M112") == 0) kill();
kill();
bufindw = (bufindw + 1)%BUFSIZE; bufindw = (bufindw + 1)%BUFSIZE;
buflen += 1; buflen += 1;
...@@ -1248,17 +1240,19 @@ static void retract_z_probe() { ...@@ -1248,17 +1240,19 @@ static void retract_z_probe() {
} }
/// Probe bed height at position (x,y), returns the measured z value /// Probe bed height at position (x,y), returns the measured z value
static float probe_pt(float x, float y, float z_before) { static float probe_pt(float x, float y, float z_before, int retract_action=0) {
// move to right place // move to right place
do_blocking_move_to(current_position[X_AXIS], current_position[Y_AXIS], z_before); do_blocking_move_to(current_position[X_AXIS], current_position[Y_AXIS], z_before);
do_blocking_move_to(x - X_PROBE_OFFSET_FROM_EXTRUDER, y - Y_PROBE_OFFSET_FROM_EXTRUDER, current_position[Z_AXIS]); do_blocking_move_to(x - X_PROBE_OFFSET_FROM_EXTRUDER, y - Y_PROBE_OFFSET_FROM_EXTRUDER, current_position[Z_AXIS]);
#ifndef Z_PROBE_SLED #ifndef Z_PROBE_SLED
if ((retract_action==0) || (retract_action==1))
engage_z_probe(); // Engage Z Servo endstop if available engage_z_probe(); // Engage Z Servo endstop if available
#endif // Z_PROBE_SLED #endif // Z_PROBE_SLED
run_z_probe(); run_z_probe();
float measured_z = current_position[Z_AXIS]; float measured_z = current_position[Z_AXIS];
#ifndef Z_PROBE_SLED #ifndef Z_PROBE_SLED
if ((retract_action==0) || (retract_action==3))
retract_z_probe(); retract_z_probe();
#endif // Z_PROBE_SLED #endif // Z_PROBE_SLED
...@@ -1800,8 +1794,7 @@ void refresh_cmd_timeout(void) ...@@ -1800,8 +1794,7 @@ void refresh_cmd_timeout(void)
} }
#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]) {
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];
...@@ -1817,6 +1810,7 @@ void retract(bool retracting, bool swapretract = false) ...@@ -1817,6 +1810,7 @@ void retract(bool retracting, bool swapretract = false)
feedrate=retract_feedrate*60; feedrate=retract_feedrate*60;
retracted[active_extruder]=true; retracted[active_extruder]=true;
prepare_move(); prepare_move();
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; calculate_delta(current_position); // change cartesian kinematic to delta kinematic;
...@@ -1825,12 +1819,14 @@ void retract(bool retracting, bool swapretract = false) ...@@ -1825,12 +1819,14 @@ void retract(bool retracting, bool swapretract = false)
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]);
#endif #endif
prepare_move(); prepare_move();
}
feedrate = oldFeedrate; feedrate = oldFeedrate;
} else if(!retracting && retracted[active_extruder]) { } else if(!retracting && retracted[active_extruder]) {
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];
destination[Z_AXIS]=current_position[Z_AXIS]; destination[Z_AXIS]=current_position[Z_AXIS];
destination[E_AXIS]=current_position[E_AXIS]; destination[E_AXIS]=current_position[E_AXIS];
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; calculate_delta(current_position); // change cartesian kinematic to delta kinematic;
...@@ -1839,6 +1835,7 @@ void retract(bool retracting, bool swapretract = false) ...@@ -1839,6 +1835,7 @@ void retract(bool retracting, bool swapretract = false)
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]);
#endif #endif
//prepare_move(); //prepare_move();
}
if (swapretract) { if (swapretract) {
current_position[E_AXIS]-=(retract_length_swap+retract_recover_length_swap)/volumetric_multiplier[active_extruder]; current_position[E_AXIS]-=(retract_length_swap+retract_recover_length_swap)/volumetric_multiplier[active_extruder];
} else { } else {
...@@ -1891,89 +1888,93 @@ static void dock_sled(bool dock, int offset=0) ...@@ -1891,89 +1888,93 @@ static void dock_sled(bool dock, int offset=0)
} }
#endif //Z_PROBE_SLED #endif //Z_PROBE_SLED
void process_commands()
{ /******************************************************************************
unsigned long codenum; //throw away variable * G-Code Functions
char *starpos = NULL; *******************************************************************************/
#ifdef ENABLE_AUTO_BED_LEVELING
float x_tmp, y_tmp, z_tmp, real_z; /**
#endif * G0 / G1: Coordinated movement of X Y Z E axes
if(code_seen('G')) { */
switch((int)code_value()) { void gcode_G0_G1() {
case 0: // G0 -> G1 if (!Stopped) {
case 1: // G1
if(Stopped == false) {
get_coordinates(); // For X Y Z E F get_coordinates(); // For X Y Z E F
#ifdef FWRETRACT #ifdef FWRETRACT
if(autoretract_enabled) if (autoretract_enabled)
if( !(code_seen('X') || code_seen('Y') || code_seen('Z')) && code_seen('E')) { if (!(code_seen('X') || code_seen('Y') || code_seen('Z')) && code_seen('E')) {
float echange=destination[E_AXIS]-current_position[E_AXIS]; float echange = destination[E_AXIS] - current_position[E_AXIS];
if((echange<-MIN_RETRACT && !retracted) || (echange>MIN_RETRACT && retracted)) { //move appears to be an attempt to retract or recover // Is this move an attempt to retract or recover?
current_position[E_AXIS] = destination[E_AXIS]; //hide the slicer-generated retract/recover from calculations if ((echange < -MIN_RETRACT && !retracted) || (echange > MIN_RETRACT && retracted)) {
plan_set_e_position(current_position[E_AXIS]); //AND from the planner current_position[E_AXIS] = destination[E_AXIS]; // hide the slicer-generated retract/recover from calculations
plan_set_e_position(current_position[E_AXIS]); // AND from the planner
retract(!retracted); retract(!retracted);
return; return;
} }
} }
#endif //FWRETRACT #endif //FWRETRACT
prepare_move(); prepare_move();
//ClearToSend(); //ClearToSend();
} }
break; }
#ifndef SCARA //disable arc support /**
case 2: // G2 - CW ARC * G2: Clockwise Arc
if(Stopped == false) { * G3: Counterclockwise Arc
get_arc_coordinates(); */
prepare_arc_move(true); void gcode_G2_G3(bool clockwise) {
} if (!Stopped) {
break;
case 3: // G3 - CCW ARC
if(Stopped == false) {
get_arc_coordinates(); get_arc_coordinates();
prepare_arc_move(false); prepare_arc_move(clockwise);
} }
break; }
#endif // no SCARA
/**
* G4: Dwell S<seconds> or P<milliseconds>
*/
void gcode_G4() {
unsigned long codenum;
case 4: // G4 dwell
LCD_MESSAGEPGM(MSG_DWELL); LCD_MESSAGEPGM(MSG_DWELL);
codenum = 0;
if(code_seen('P')) codenum = code_value(); // milliseconds to wait if (code_seen('P')) codenum = code_value(); // milliseconds to wait
if(code_seen('S')) codenum = code_value() * 1000; // seconds to wait if (code_seen('S')) codenum = code_value() * 1000; // seconds to wait
st_synchronize(); st_synchronize();
codenum += millis(); // keep track of when we started waiting codenum += millis(); // keep track of when we started waiting
refresh_cmd_timeout(); previous_millis_cmd = millis();
while(millis() < codenum) { while(millis() < codenum) {
manage_heater(); manage_heater();
manage_inactivity(); manage_inactivity();
lcd_update(); lcd_update();
} }
break; }
#ifdef FWRETRACT #ifdef FWRETRACT
case 10: // G10 retract /**
#if EXTRUDERS > 1 * G10 - Retract filament according to settings of M207
retracted_swap[active_extruder]=(code_seen('S') && code_value_long() == 1); // checks for swap retract argument * G11 - Recover filament according to settings of M208
retract(true,retracted_swap[active_extruder]); */
#else void gcode_G10_G11(bool doRetract=false) {
retract(true); #if EXTRUDERS > 1
#endif if (doRetract) {
break; retracted_swap[active_extruder] = (code_seen('S') && code_value_long() == 1); // checks for swap retract argument
case 11: // G11 retract_recover }
#if EXTRUDERS > 1 #endif
retract(false,retracted_swap[active_extruder]); retract (doRetract
#else #if EXTRUDERS > 1
retract(false); , retracted_swap[active_extruder]
#endif #endif
break; );
}
#endif //FWRETRACT #endif //FWRETRACT
case 28: //G28 Home all Axis one at a time /**
#ifdef ENABLE_AUTO_BED_LEVELING * G28: Home all axes, one at a time
*/
void gcode_G28() {
#ifdef ENABLE_AUTO_BED_LEVELING
plan_bed_level_matrix.set_to_identity(); //Reset the plane ("erase" all leveling data) plan_bed_level_matrix.set_to_identity(); //Reset the plane ("erase" all leveling data)
#endif //ENABLE_AUTO_BED_LEVELING #endif //ENABLE_AUTO_BED_LEVELING
saved_feedrate = feedrate; saved_feedrate = feedrate;
saved_feedmultiply = feedmultiply; saved_feedmultiply = feedmultiply;
...@@ -1982,14 +1983,13 @@ void process_commands() ...@@ -1982,14 +1983,13 @@ void process_commands()
enable_endstops(true); enable_endstops(true);
for(int8_t i=0; i < NUM_AXIS; i++) { for(int8_t i=0; i < NUM_AXIS; i++) destination[i] = current_position[i];
destination[i] = current_position[i];
}
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_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])));
#ifdef NPR2 #ifdef NPR2
if((home_all_axis) || (code_seen(axis_codes[E_AXIS]))) { if((home_all_axis) || (code_seen(axis_codes[E_AXIS]))) {
active_driver = active_extruder = 1; active_driver = active_extruder = 1;
plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], -200, COLOR_HOMERATE, active_extruder, active_driver); plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], -200, COLOR_HOMERATE, active_extruder, active_driver);
...@@ -1997,29 +1997,24 @@ void process_commands() ...@@ -1997,29 +1997,24 @@ void process_commands()
old_color = 99; old_color = 99;
active_driver = active_extruder = 0; active_driver = active_extruder = 0;
} }
#endif #endif
#ifdef DELTA #ifdef DELTA
// A delta can only safely home all axis at the same time // A delta can only safely home all axis at the same time
// all axis have to home at the same time // all axis have to home at the same time
// Move all carriages up together until the first endstop is hit. // Move all carriages up together until the first endstop is hit.
current_position[X_AXIS] = 0; for (int i = X_AXIS; i <= Z_AXIS; i++) current_position[i] = 0;
current_position[Y_AXIS] = 0;
current_position[Z_AXIS] = 0;
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]);
destination[X_AXIS] = 3 * max_length[Z_AXIS]; for (int i = X_AXIS; i <= Z_AXIS; i++) destination[i] = 3 * max_length[Z_AXIS];
destination[Y_AXIS] = 3 * max_length[Z_AXIS];
destination[Z_AXIS] = 3 * max_length[Z_AXIS];
feedrate = 1.732 * homing_feedrate[X_AXIS]; feedrate = 1.732 * homing_feedrate[X_AXIS];
plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder, active_driver); plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder, active_driver);
st_synchronize(); st_synchronize();
endstops_hit_on_purpose(); endstops_hit_on_purpose();
current_position[X_AXIS] = destination[X_AXIS]; // Destination reached
current_position[Y_AXIS] = destination[Y_AXIS]; for (int i = X_AXIS; i <= Z_AXIS; i++) current_position[i] = destination[i];
current_position[Z_AXIS] = destination[Z_AXIS];
// take care of back off and rehome now we are all at the top // take care of back off and rehome now we are all at the top
HOMEAXIS(X); HOMEAXIS(X);
...@@ -2029,32 +2024,30 @@ void process_commands() ...@@ -2029,32 +2024,30 @@ void process_commands()
calculate_delta(current_position); calculate_delta(current_position);
plan_set_position(delta[X_AXIS], delta[Y_AXIS], delta[Z_AXIS], current_position[E_AXIS]); plan_set_position(delta[X_AXIS], delta[Y_AXIS], delta[Z_AXIS], current_position[E_AXIS]);
#else // NOT DELTA #else // NOT DELTA
#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) || (code_seen(axis_codes[Z_AXIS]))) { if((home_all_axis) || (code_seen(axis_codes[Z_AXIS]))) {
HOMEAXIS(Z); HOMEAXIS(Z);
} }
#endif #endif
#ifdef QUICK_HOME #ifdef QUICK_HOME
if((home_all_axis)||( code_seen(axis_codes[X_AXIS]) && code_seen(axis_codes[Y_AXIS]))) { //first diagonal move if((home_all_axis)||( code_seen(axis_codes[X_AXIS]) && code_seen(axis_codes[Y_AXIS]))) { //first diagonal move
current_position[X_AXIS] = 0; current_position[X_AXIS] = current_position[Y_AXIS] = 0;
current_position[Y_AXIS] = 0;
#ifndef DUAL_X_CARRIAGE #ifndef DUAL_X_CARRIAGE
int x_axis_home_dir = home_dir(X_AXIS); int x_axis_home_dir = home_dir(X_AXIS);
#else #else
int x_axis_home_dir = x_home_dir(active_extruder); int x_axis_home_dir = x_home_dir(active_extruder);
extruder_duplication_enabled = false; extruder_duplication_enabled = false;
#endif #endif
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]);
destination[X_AXIS] = 1.5 * max_length(X_AXIS) * x_axis_home_dir; 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); destination[Y_AXIS] = 1.5 * max_length(Y_AXIS) * home_dir(Y_AXIS);
feedrate = homing_feedrate[X_AXIS]; feedrate = homing_feedrate[X_AXIS];
if(homing_feedrate[Y_AXIS]<feedrate) if(homing_feedrate[Y_AXIS]<feedrate) feedrate = homing_feedrate[Y_AXIS];
feedrate = homing_feedrate[Y_AXIS];
if (max_length(X_AXIS) > max_length(Y_AXIS)) { if (max_length(X_AXIS) > max_length(Y_AXIS)) {
feedrate *= sqrt(pow(max_length(Y_AXIS) / max_length(X_AXIS), 2) + 1); feedrate *= sqrt(pow(max_length(Y_AXIS) / max_length(X_AXIS), 2) + 1);
} }
...@@ -2076,14 +2069,14 @@ void process_commands() ...@@ -2076,14 +2069,14 @@ void process_commands()
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];
#ifndef SCARA #ifndef SCARA
current_position[Z_AXIS] = destination[Z_AXIS]; current_position[Z_AXIS] = destination[Z_AXIS];
#endif #endif
} }
#endif // QUICK_HOME #endif // QUICK_HOME
if((home_all_axis) || (code_seen(axis_codes[X_AXIS]))) { if((home_all_axis) || (code_seen(axis_codes[X_AXIS]))) {
#ifdef DUAL_X_CARRIAGE #ifdef DUAL_X_CARRIAGE
int tmp_extruder = active_extruder; int tmp_extruder = active_extruder;
extruder_duplication_enabled = false; extruder_duplication_enabled = false;
active_extruder = !active_extruder; active_extruder = !active_extruder;
...@@ -2095,39 +2088,35 @@ void process_commands() ...@@ -2095,39 +2088,35 @@ void process_commands()
memcpy(raised_parked_position, current_position, sizeof(raised_parked_position)); memcpy(raised_parked_position, current_position, sizeof(raised_parked_position));
delayed_move_time = 0; delayed_move_time = 0;
active_extruder_parked = true; active_extruder_parked = true;
#else #else
HOMEAXIS(X); HOMEAXIS(X);
#endif // DUAL_X_CARRIAGE #endif // DUAL_X_CARRIAGE
} }
if((home_all_axis) || (code_seen(axis_codes[Y_AXIS]))) { if((home_all_axis) || (code_seen(axis_codes[Y_AXIS]))) HOMEAXIS(Y);
HOMEAXIS(Y);
}
if(code_seen(axis_codes[X_AXIS])) { if(code_seen(axis_codes[X_AXIS])) {
if(code_value_long() != 0) { if(code_value_long() != 0) {
#ifdef SCARA #ifdef SCARA
current_position[X_AXIS]=code_value(); current_position[X_AXIS]=code_value();
#else #else
current_position[X_AXIS]=code_value()+add_homing[X_AXIS]; current_position[X_AXIS]=code_value()+add_homing[X_AXIS];
#endif #endif
} }
} }
if(code_seen(axis_codes[Y_AXIS])) { if (code_seen(axis_codes[Y_AXIS]) && code_value_long() != 0) {
if(code_value_long() != 0) { #ifdef SCARA
#ifdef SCARA
current_position[Y_AXIS]=code_value(); current_position[Y_AXIS]=code_value();
#else #else
current_position[Y_AXIS]=code_value()+add_homing[Y_AXIS]; current_position[Y_AXIS]=code_value()+add_homing[Y_AXIS];
#endif #endif
}
} }
#if Z_HOME_DIR < 0 // If homing towards BED do Z last #if Z_HOME_DIR < 0 // If homing towards BED do Z last
#ifndef Z_SAFE_HOMING #ifndef Z_SAFE_HOMING
if (code_seen('M')) { // Manual G28 if (code_seen('M')) { // Manual G28
#ifdef ULTIPANEL #ifdef ULTIPANEL
if(home_all_axis) { if(home_all_axis) {
boolean zig = true; boolean zig = true;
int xGridSpacing = (RIGHT_PROBE_BED_POSITION - LEFT_PROBE_BED_POSITION); int xGridSpacing = (RIGHT_PROBE_BED_POSITION - LEFT_PROBE_BED_POSITION);
...@@ -2163,19 +2152,18 @@ void process_commands() ...@@ -2163,19 +2152,18 @@ void process_commands()
manage_inactivity(); manage_inactivity();
lcd_update(); lcd_update();
if(beepbutton) { if(beepbutton) {
#if BEEPER > 0 #if BEEPER > 0
SET_OUTPUT(BEEPER); SET_OUTPUT(BEEPER);
WRITE(BEEPER,HIGH); WRITE(BEEPER,HIGH);
delay(100); delay(100);
WRITE(BEEPER,LOW); WRITE(BEEPER,LOW);
delay(3); delay(3);
#else #else
#if !defined(LCD_FEEDBACK_FREQUENCY_HZ) || !defined(LCD_FEEDBACK_FREQUENCY_DURATION_MS) #if !defined(LCD_FEEDBACK_FREQUENCY_HZ) || !defined(LCD_FEEDBACK_FREQUENCY_DURATION_MS)
lcd_buzz(1000/6,100); lcd_buzz(1000/6,100);
#else #else lcd_buzz(LCD_FEEDBACK_FREQUENCY_DURATION_MS,LCD_FEEDBACK_FREQUENCY_HZ);
lcd_buzz(LCD_FEEDBACK_FREQUENCY_DURATION_MS,LCD_FEEDBACK_FREQUENCY_HZ); #endif
#endif #endif
#endif
beepbutton=false; beepbutton=false;
} }
} }
...@@ -2188,18 +2176,18 @@ void process_commands() ...@@ -2188,18 +2176,18 @@ void process_commands()
enquecommand("G4 P0"); enquecommand("G4 P0");
enquecommand("G4 P0"); enquecommand("G4 P0");
} }
#endif // ULTIPANEL #endif // ULTIPANEL
} }
else if((home_all_axis) || (code_seen(axis_codes[Z_AXIS]))) { else if((home_all_axis) || (code_seen(axis_codes[Z_AXIS]))) {
#if defined (Z_RAISE_BEFORE_HOMING) && (Z_RAISE_BEFORE_HOMING > 0) #if defined (Z_RAISE_BEFORE_HOMING) && (Z_RAISE_BEFORE_HOMING > 0)
destination[Z_AXIS] = Z_RAISE_BEFORE_HOMING * home_dir(Z_AXIS) * (-1); // Set destination away from bed destination[Z_AXIS] = Z_RAISE_BEFORE_HOMING * home_dir(Z_AXIS) * (-1); // 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); plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate, active_extruder, active_driver);
st_synchronize(); st_synchronize();
#endif #endif
HOMEAXIS(Z); HOMEAXIS(Z);
} }
#else // Z Safe mode activated. #else // 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);
...@@ -2217,83 +2205,84 @@ void process_commands() ...@@ -2217,83 +2205,84 @@ void process_commands()
} }
// Let's see if X and Y are homed and probe is inside bed area. // Let's see if X and Y are homed and probe is inside bed area.
if(code_seen(axis_codes[Z_AXIS])) { if(code_seen(axis_codes[Z_AXIS])) {
if ( (axis_known_position[X_AXIS]) && (axis_known_position[Y_AXIS]) \ if (axis_known_position[X_AXIS] && axis_known_position[Y_AXIS]) {
&& (current_position[X_AXIS]+X_PROBE_OFFSET_FROM_EXTRUDER >= X_MIN_POS) \
&& (current_position[X_AXIS]+X_PROBE_OFFSET_FROM_EXTRUDER <= X_MAX_POS) \
&& (current_position[Y_AXIS]+Y_PROBE_OFFSET_FROM_EXTRUDER >= Y_MIN_POS) \
&& (current_position[Y_AXIS]+Y_PROBE_OFFSET_FROM_EXTRUDER <= Y_MAX_POS)) {
float cpx = current_position[X_AXIS] + X_PROBE_OFFSET_FROM_EXTRUDER,
cpy = current_position[Y_AXIS] + Y_PROBE_OFFSET_FROM_EXTRUDER;
if (cpx >= X_MIN_POS && cpx <= X_MAX_POS && cpy >= Y_MIN_POS && cpy <= Y_MAX_POS) {
current_position[Z_AXIS] = 0; current_position[Z_AXIS] = 0;
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]);
destination[Z_AXIS] = Z_RAISE_BEFORE_HOMING * home_dir(Z_AXIS) * (-1); // Set destination away from bed destination[Z_AXIS] = Z_RAISE_BEFORE_HOMING * home_dir(Z_AXIS) * (-1); // 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); plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate, active_extruder, active_driver);
st_synchronize(); st_synchronize();
HOMEAXIS(Z); HOMEAXIS(Z);
} }
else if (!((axis_known_position[X_AXIS]) && (axis_known_position[Y_AXIS]))) {
LCD_MESSAGEPGM(MSG_POSITION_UNKNOWN);
SERIAL_ECHO_START;
SERIAL_ECHOLNPGM(MSG_POSITION_UNKNOWN);
}
else { else {
LCD_MESSAGEPGM(MSG_ZPROBE_OUT); LCD_MESSAGEPGM(MSG_ZPROBE_OUT);
SERIAL_ECHO_START; SERIAL_ECHO_START;
SERIAL_ECHOLNPGM(MSG_ZPROBE_OUT); SERIAL_ECHOLNPGM(MSG_ZPROBE_OUT);
} }
} }
#endif // Z_SAFE_HOMING else {
#endif // Z_HOME_DIR < 0 LCD_MESSAGEPGM(MSG_POSITION_UNKNOWN);
SERIAL_ECHO_START;
if(code_seen(axis_codes[Z_AXIS])) { SERIAL_ECHOLNPGM(MSG_POSITION_UNKNOWN);
if(code_value_long() != 0) {
current_position[Z_AXIS]=code_value()+add_homing[Z_AXIS];
} }
} }
#endif // Z_SAFE_HOMING
#ifdef ENABLE_AUTO_BED_LEVELING #endif // Z_HOME_DIR < 0
if (code_seen(axis_codes[Z_AXIS]) && code_value_long() != 0) current_position[Z_AXIS] = code_value() + add_homing[Z_AXIS];
#ifdef ENABLE_AUTO_BED_LEVELING
if((home_all_axis) || (code_seen(axis_codes[Z_AXIS]))) { if((home_all_axis) || (code_seen(axis_codes[Z_AXIS]))) {
current_position[Z_AXIS] += zprobe_zoffset; //Add Z_Probe offset (the distance is negative) current_position[Z_AXIS] += zprobe_zoffset; //Add Z_Probe offset (the distance is negative)
} }
#endif #endif
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]);
#endif // else DELTA #endif // else DELTA
#ifdef SCARA #ifdef SCARA
calculate_delta(current_position); calculate_delta(current_position);
plan_set_position(delta[X_AXIS], delta[Y_AXIS], delta[Z_AXIS], current_position[E_AXIS]); 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
enable_endstops(false); enable_endstops(false);
#endif #endif
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();
break; }
#ifdef ENABLE_AUTO_BED_LEVELING #ifdef ENABLE_AUTO_BED_LEVELING
case 29: // G29 Detailed Z-Probe, probes the bed at 3 or more points. /**
{ * G29: Detailed Z-Probe, probes the bed at 3 or more points.
#if Z_MIN_PIN == -1 * Will fail if the printer has not been homed with G28.
#error "You must have a Z_MIN endstop in order to enable Auto Bed Leveling feature!!! Z_MIN_PIN must point to a valid hardware pin." */
#endif void gcode_G29() {
float x_tmp, y_tmp, z_tmp, real_z;
#if Z_MIN_PIN == -1
#error "You must have a Z_MIN endstop in order to enable Auto Bed Leveling feature!!! Z_MIN_PIN must point to a valid hardware pin."
#endif
// Prevent user from running a G29 without first homing in X and Y // Prevent user from running a G29 without first homing in X and Y
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);
break; // abort G29, since we don't know where we are return; // abort G29, since we don't know where we are
} }
#ifdef Z_PROBE_SLED #ifdef Z_PROBE_SLED
dock_sled(false); dock_sled(false);
#endif // Z_PROBE_SLED #endif // Z_PROBE_SLED
st_synchronize(); st_synchronize();
// make sure the bed_level_rotation_matrix is identity or the planner will get it incorectly // make sure the bed_level_rotation_matrix is identity or the planner will get it incorectly
...@@ -2309,48 +2298,26 @@ void process_commands() ...@@ -2309,48 +2298,26 @@ void process_commands()
setup_for_endstop_move(); setup_for_endstop_move();
feedrate = homing_feedrate[Z_AXIS]; feedrate = homing_feedrate[Z_AXIS];
#ifdef AUTO_BED_LEVELING_GRID #ifdef AUTO_BED_LEVELING_GRID
int r_probe_bed_position = RIGHT_PROBE_BED_POSITION; int r_probe_bed_position = RIGHT_PROBE_BED_POSITION;
int l_probe_bed_position = LEFT_PROBE_BED_POSITION; int l_probe_bed_position = LEFT_PROBE_BED_POSITION;
int f_probe_bed_position = FRONT_PROBE_BED_POSITION; int f_probe_bed_position = FRONT_PROBE_BED_POSITION;
int b_probe_bed_position = BACK_PROBE_BED_POSITION; int b_probe_bed_position = BACK_PROBE_BED_POSITION;
int a_bed_leveling_points = AUTO_BED_LEVELING_GRID_POINTS; int a_bed_leveling_points = AUTO_BED_LEVELING_GRID_POINTS;
if(code_seen('R')) if (code_seen('R')) r_probe_bed_position = code_value();
{ if (code_seen('L')) l_probe_bed_position = code_value();
r_probe_bed_position = code_value(); if (code_seen('F')) f_probe_bed_position = code_value();
} if (code_seen('B')) b_probe_bed_position = code_value();
if (code_seen('A')) a_bed_leveling_points = code_value();
if(code_seen('L'))
{
l_probe_bed_position = code_value();
}
if(code_seen('F'))
{
f_probe_bed_position = code_value();
}
if(code_seen('B'))
{
b_probe_bed_position = code_value();
}
if(code_seen('A'))
{
a_bed_leveling_points = code_value();
}
if((f_probe_bed_position == b_probe_bed_position) || (r_probe_bed_position == l_probe_bed_position)) if((f_probe_bed_position == b_probe_bed_position) || (r_probe_bed_position == l_probe_bed_position)) {
{
SERIAL_ERROR_START; SERIAL_ERROR_START;
SERIAL_ERRORLNPGM(MSG_EMPTY_PLANE); SERIAL_ERRORLNPGM(MSG_EMPTY_PLANE);
break;
return; return;
} }
// probe at the points of a lattice grid // probe at the points of a lattice grid
int xGridSpacing = (r_probe_bed_position - l_probe_bed_position) / (a_bed_leveling_points-1); int xGridSpacing = (r_probe_bed_position - l_probe_bed_position) / (a_bed_leveling_points-1);
int yGridSpacing = (b_probe_bed_position - f_probe_bed_position) / (a_bed_leveling_points-1); int yGridSpacing = (b_probe_bed_position - f_probe_bed_position) / (a_bed_leveling_points-1);
...@@ -2368,11 +2335,9 @@ void process_commands() ...@@ -2368,11 +2335,9 @@ void process_commands()
int probePointCounter = 0; int probePointCounter = 0;
bool zig = true; bool zig = true;
for (int yProbe=f_probe_bed_position; yProbe <= b_probe_bed_position; yProbe += yGridSpacing) for (int yProbe=f_probe_bed_position; yProbe <= b_probe_bed_position; yProbe += yGridSpacing) {
{
int xProbe, xInc; int xProbe, xInc;
if (zig) if (zig) {
{
xProbe = l_probe_bed_position; xProbe = l_probe_bed_position;
//xEnd = RIGHT_PROBE_BED_POSITION; //xEnd = RIGHT_PROBE_BED_POSITION;
xInc = xGridSpacing; xInc = xGridSpacing;
...@@ -2386,24 +2351,19 @@ void process_commands() ...@@ -2386,24 +2351,19 @@ void process_commands()
zig = true; zig = true;
} }
for (int xCount=0; xCount < a_bed_leveling_points; xCount++) for (int xCount=0; xCount < a_bed_leveling_points; xCount++) {
{
float z_before; float z_before;
if (probePointCounter == 0) if (probePointCounter == 0) {
{
// raise before probing // raise before probing
z_before = Z_RAISE_BEFORE_PROBING; z_before = Z_RAISE_BEFORE_PROBING;
} }
else else {
{
// raise extruder // raise extruder
z_before = current_position[Z_AXIS] + Z_RAISE_BETWEEN_PROBINGS; z_before = current_position[Z_AXIS] + Z_RAISE_BETWEEN_PROBINGS;
} }
float measured_z = probe_pt(xProbe, yProbe, z_before); float measured_z = probe_pt(xProbe, yProbe, z_before);
eqnBVector[probePointCounter] = measured_z; eqnBVector[probePointCounter] = measured_z;
eqnAMatrix[probePointCounter + 0*a_bed_leveling_points*a_bed_leveling_points] = xProbe; eqnAMatrix[probePointCounter + 0*a_bed_leveling_points*a_bed_leveling_points] = xProbe;
eqnAMatrix[probePointCounter + 1*a_bed_leveling_points*a_bed_leveling_points] = yProbe; eqnAMatrix[probePointCounter + 1*a_bed_leveling_points*a_bed_leveling_points] = yProbe;
eqnAMatrix[probePointCounter + 2*a_bed_leveling_points*a_bed_leveling_points] = 1; eqnAMatrix[probePointCounter + 2*a_bed_leveling_points*a_bed_leveling_points] = 1;
...@@ -2423,12 +2383,10 @@ void process_commands() ...@@ -2423,12 +2383,10 @@ void process_commands()
SERIAL_PROTOCOLPGM(" d: "); SERIAL_PROTOCOLPGM(" d: ");
SERIAL_PROTOCOLLN(plane_equation_coefficients[2]); SERIAL_PROTOCOLLN(plane_equation_coefficients[2]);
set_bed_level_equation_lsq(plane_equation_coefficients); set_bed_level_equation_lsq(plane_equation_coefficients);
free(plane_equation_coefficients); free(plane_equation_coefficients);
#else // AUTO_BED_LEVELING_GRID not defined #else // AUTO_BED_LEVELING_GRID not defined
// Probe at 3 arbitrary points // Probe at 3 arbitrary points
// probe 1 // probe 1
...@@ -2441,10 +2399,10 @@ void process_commands() ...@@ -2441,10 +2399,10 @@ void process_commands()
float z_at_pt_3 = probe_pt(ABL_PROBE_PT_3_X, ABL_PROBE_PT_3_Y, current_position[Z_AXIS] + Z_RAISE_BETWEEN_PROBINGS); float z_at_pt_3 = probe_pt(ABL_PROBE_PT_3_X, ABL_PROBE_PT_3_Y, current_position[Z_AXIS] + Z_RAISE_BETWEEN_PROBINGS);
clean_up_after_endstop_move(); clean_up_after_endstop_move();
set_bed_level_equation_3pts(z_at_pt_1, z_at_pt_2, z_at_pt_3); set_bed_level_equation_3pts(z_at_pt_1, z_at_pt_2, z_at_pt_3);
#endif // AUTO_BED_LEVELING_GRID #endif // AUTO_BED_LEVELING_GRID
st_synchronize(); st_synchronize();
// The following code correct the Z height difference from z-probe position and hotend tip position. // The following code correct the Z height difference from z-probe position and hotend tip position.
...@@ -2458,15 +2416,13 @@ void process_commands() ...@@ -2458,15 +2416,13 @@ void process_commands()
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.
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]);
#ifdef Z_PROBE_SLED #ifdef Z_PROBE_SLED
dock_sled(true, -SLED_DOCKING_OFFSET); // correct for over travel. dock_sled(true, -SLED_DOCKING_OFFSET); // correct for over travel.
#endif // Z_PROBE_SLED #endif // Z_PROBE_SLED
} }
break;
#ifndef Z_PROBE_SLED #ifndef Z_PROBE_SLED
case 30: // G30 Single Z Probe void gcode_G30() {
{
engage_z_probe(); // Engage Z Servo endstop if available engage_z_probe(); // Engage Z Servo endstop if available
st_synchronize(); st_synchronize();
// TODO: make sure the bed_level_rotation_matrix is identity or the planner will get set incorectly // TODO: make sure the bed_level_rotation_matrix is identity or the planner will get set incorectly
...@@ -2486,21 +2442,16 @@ void process_commands() ...@@ -2486,21 +2442,16 @@ void process_commands()
clean_up_after_endstop_move(); clean_up_after_endstop_move();
retract_z_probe(); // Retract Z Servo endstop if available retract_z_probe(); // Retract Z Servo endstop if available
} }
break;
#else
case 31: // G31 - dock the sled
dock_sled(true);
break;
case 32: // G32 - undock the sled
dock_sled(false);
break;
#endif // Z_PROBE_SLED #endif // Z_PROBE_SLED
#endif // ENABLE_AUTO_BED_LEVELING #endif // ENABLE_AUTO_BED_LEVELING
#ifdef DELTA #ifdef DELTA
case 29: // G29 Calibrate print surface with automatic Z probe. /**
* G29: Detailed Z-Probe, probes the bed at more points.
*/
void gcode_G29() {
if (code_seen('D')){ if (code_seen('D')){
SERIAL_ECHOLN("Current bed level array values:"); SERIAL_ECHOLN("Current bed level array values:");
SERIAL_ECHOLN(""); SERIAL_ECHOLN("");
...@@ -2511,25 +2462,26 @@ void process_commands() ...@@ -2511,25 +2462,26 @@ void process_commands()
} }
SERIAL_ECHOLN(""); SERIAL_ECHOLN("");
} }
break; return;
} }
saved_feedrate = feedrate; saved_feedrate = feedrate;
saved_feedmultiply = feedmultiply; saved_feedmultiply = feedmultiply;
feedmultiply = 100; feedmultiply = 100;
deploy_z_probe(); deploy_z_probe();
calibrate_print_surface(z_probe_offset[Z_AXIS] + calibrate_print_surface(z_probe_offset[Z_AXIS] + (code_seen(axis_codes[Z_AXIS]) ? code_value() : 0.0));
(code_seen(axis_codes[Z_AXIS]) ? code_value() : 0.0));
retract_z_probe(); retract_z_probe();
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();
break; }
case 30: //G30 Delta AutoCalibration /**
* G30: Delta AutoCalibration
*/
void gcode_G30() {
int iterations; int iterations;
//Zero the bed level array //Zero the bed level array
...@@ -2551,7 +2503,7 @@ void process_commands() ...@@ -2551,7 +2503,7 @@ void process_commands()
SERIAL_ECHO(saved_positions[i][Z_AXIS]); SERIAL_ECHO(saved_positions[i][Z_AXIS]);
SERIAL_ECHOLN("]"); SERIAL_ECHOLN("]");
} }
break; return;
} }
if (code_seen('F')) { if (code_seen('F')) {
probing_feedrate=code_value(); probing_feedrate=code_value();
...@@ -2580,7 +2532,7 @@ void process_commands() ...@@ -2580,7 +2532,7 @@ void process_commands()
SERIAL_ECHO(saved_position[Z_AXIS]); SERIAL_ECHO(saved_position[Z_AXIS]);
SERIAL_ECHOLN("]"); SERIAL_ECHOLN("]");
retract_z_probe(); retract_z_probe();
break; return;
} }
saved_feedrate = feedrate; saved_feedrate = feedrate;
...@@ -2656,7 +2608,7 @@ void process_commands() ...@@ -2656,7 +2608,7 @@ void process_commands()
//Restore saved variables //Restore saved variables
feedrate = saved_feedrate; feedrate = saved_feedrate;
feedmultiply = saved_feedmultiply; feedmultiply = saved_feedmultiply;
break; return;
} }
if (code_seen('D')) { if (code_seen('D')) {
...@@ -2800,7 +2752,7 @@ void process_commands() ...@@ -2800,7 +2752,7 @@ void process_commands()
if ((radiusErrorC >= (radiusErrorA - 0.02)) and (radiusErrorC <= (radiusErrorA + 0.02))) equalCA = true; if ((radiusErrorC >= (radiusErrorA - 0.02)) and (radiusErrorC <= (radiusErrorA + 0.02))) equalCA = true;
else equalCA = false; else equalCA = false;
#ifdef DEBUG_MESSAGES #ifdef DEBUG_MESSAGES
if (equalAB == true) { if (equalAB == true) {
SERIAL_ECHOPAIR("Tower AB Equal (A=",radiusErrorA); SERIAL_ECHOPAIR("Tower AB Equal (A=",radiusErrorA);
SERIAL_ECHOPAIR(" B=",radiusErrorB); SERIAL_ECHOPAIR(" B=",radiusErrorB);
...@@ -2821,13 +2773,13 @@ void process_commands() ...@@ -2821,13 +2773,13 @@ void process_commands()
SERIAL_ECHOLN(")"); SERIAL_ECHOLN(")");
} }
else SERIAL_ECHOLN("equalCA=false"); else SERIAL_ECHOLN("equalCA=false");
#endif // DEBUG_MESSAGES #endif // DEBUG_MESSAGES
if ((equalAB == true) and (equalBC == true) and (equalCA == true)) { if ((equalAB == true) and (equalBC == true) and (equalCA == true)) {
// all tower radius out by the same amount (within 0.02) - allow adjustment with delta rod length // all tower radius out by the same amount (within 0.02) - allow adjustment with delta rod length
#ifdef DEBUG_MESSAGES #ifdef DEBUG_MESSAGES
SERIAL_ECHOLN("All tower radius errors equal"); SERIAL_ECHOLN("All tower radius errors equal");
#endif #endif
adj_RadiusA = adj_RadiusB = adj_RadiusC = 0; adj_RadiusA = adj_RadiusB = adj_RadiusC = 0;
} }
...@@ -2837,10 +2789,10 @@ void process_commands() ...@@ -2837,10 +2789,10 @@ void process_commands()
if (adj_RadiusC == 0) { if (adj_RadiusC == 0) {
if (bed_level_z < bed_level_oz) adj_RadiusC = 0.5; if (bed_level_z < bed_level_oz) adj_RadiusC = 0.5;
if (bed_level_z > bed_level_oz) adj_RadiusC = -0.5; if (bed_level_z > bed_level_oz) adj_RadiusC = -0.5;
#ifdef DEBUG_MESSAGES #ifdef DEBUG_MESSAGES
SERIAL_ECHOPAIR("adj_RadiusC set to ",adj_RadiusC); SERIAL_ECHOPAIR("adj_RadiusC set to ",adj_RadiusC);
SERIAL_ECHOLN(""); SERIAL_ECHOLN("");
#endif #endif
} }
} }
if ((equalBC == true) and (equalAB == false) and (equalCA == false)) { if ((equalBC == true) and (equalAB == false) and (equalCA == false)) {
...@@ -2849,10 +2801,10 @@ void process_commands() ...@@ -2849,10 +2801,10 @@ void process_commands()
if (adj_RadiusA == 0) { if (adj_RadiusA == 0) {
if (bed_level_x < bed_level_ox) adj_RadiusA = 0.5; if (bed_level_x < bed_level_ox) adj_RadiusA = 0.5;
if (bed_level_x > bed_level_ox) adj_RadiusA = -0.5; if (bed_level_x > bed_level_ox) adj_RadiusA = -0.5;
#ifdef DEBUG_MESSAGES #ifdef DEBUG_MESSAGES
SERIAL_ECHOPAIR("adj_RadiusA set to ",adj_RadiusA); SERIAL_ECHOPAIR("adj_RadiusA set to ",adj_RadiusA);
SERIAL_ECHOLN(""); SERIAL_ECHOLN("");
#endif #endif
} }
} }
if ((equalCA == true) and (equalAB == false) and (equalBC == false)) { if ((equalCA == true) and (equalAB == false) and (equalBC == false)) {
...@@ -2861,10 +2813,10 @@ void process_commands() ...@@ -2861,10 +2813,10 @@ void process_commands()
if (adj_RadiusB == 0) { if (adj_RadiusB == 0) {
if (bed_level_y < bed_level_oy) adj_RadiusB = 0.5; if (bed_level_y < bed_level_oy) adj_RadiusB = 0.5;
if (bed_level_y > bed_level_oy) adj_RadiusB = -0.5; if (bed_level_y > bed_level_oy) adj_RadiusB = -0.5;
#ifdef DEBUG_MESSAGES #ifdef DEBUG_MESSAGES
SERIAL_ECHOPAIR("adj_RadiusB set to ",adj_RadiusB); SERIAL_ECHOPAIR("adj_RadiusB set to ",adj_RadiusB);
SERIAL_ECHOLN(""); SERIAL_ECHOLN("");
#endif #endif
} }
} }
...@@ -2891,7 +2843,7 @@ void process_commands() ...@@ -2891,7 +2843,7 @@ void process_commands()
if ((adj_dr_target >= (adj_r_target - ac_prec)) and (adj_dr_target <= (adj_r_target + ac_prec))) adj_dr_done = true; if ((adj_dr_target >= (adj_r_target - ac_prec)) and (adj_dr_target <= (adj_r_target + ac_prec))) adj_dr_done = true;
else adj_dr_done = false; else adj_dr_done = false;
#ifdef DEBUG_MESSAGES #ifdef DEBUG_MESSAGES
SERIAL_ECHOPAIR("c: ", bed_level_c); SERIAL_ECHOPAIR("c: ", bed_level_c);
SERIAL_ECHOPAIR(" x: ", bed_level_x); SERIAL_ECHOPAIR(" x: ", bed_level_x);
SERIAL_ECHOPAIR(" y: ", bed_level_y); SERIAL_ECHOPAIR(" y: ", bed_level_y);
...@@ -2927,8 +2879,7 @@ void process_commands() ...@@ -2927,8 +2879,7 @@ void process_commands()
SERIAL_ECHOLN(""); SERIAL_ECHOLN("");
SERIAL_ECHOPAIR("DeltaAlphaC: ",adj_AlphaC); SERIAL_ECHOPAIR("DeltaAlphaC: ",adj_AlphaC);
SERIAL_ECHOLN(""); SERIAL_ECHOLN("");
#endif #endif
} }
while (((adj_r_done == false) or (adj_dr_done = false)) and (loopcount < iterations)); while (((adj_r_done == false) or (adj_dr_done = false)) and (loopcount < iterations));
} }
...@@ -2962,7 +2913,6 @@ void process_commands() ...@@ -2962,7 +2913,6 @@ void process_commands()
and (bed_level_c >= -ac_prec) and (bed_level_c <= ac_prec)) loopcount = iterations; and (bed_level_c >= -ac_prec) and (bed_level_c <= ac_prec)) loopcount = iterations;
} }
} }
loopcount ++; loopcount ++;
} }
while(loopcount < iterations); while(loopcount < iterations);
...@@ -2986,10 +2936,14 @@ void process_commands() ...@@ -2986,10 +2936,14 @@ void process_commands()
//Restore saved variables //Restore saved variables
feedrate = saved_feedrate; feedrate = saved_feedrate;
feedmultiply = saved_feedmultiply; feedmultiply = saved_feedmultiply;
break; }
#endif // DELTA #endif // DELTA
case 60: // G60 Memory actual position
/**
* G60: Store in memory actual position
*/
void gcode_G60() {
lastpos[X_AXIS]=current_position[X_AXIS]; lastpos[X_AXIS]=current_position[X_AXIS];
lastpos[Y_AXIS]=current_position[Y_AXIS]; lastpos[Y_AXIS]=current_position[Y_AXIS];
lastpos[Z_AXIS]=current_position[Z_AXIS]; lastpos[Z_AXIS]=current_position[Z_AXIS];
...@@ -2999,16 +2953,17 @@ void process_commands() ...@@ -2999,16 +2953,17 @@ void process_commands()
//SERIAL_ECHOPAIR(" Lastpos Z: ", lastpos[Z_AXIS]); //SERIAL_ECHOPAIR(" Lastpos Z: ", lastpos[Z_AXIS]);
//SERIAL_ECHOPAIR(" Lastpos E: ", lastpos[E_AXIS]); //SERIAL_ECHOPAIR(" Lastpos E: ", lastpos[E_AXIS]);
//SERIAL_ECHOLN(""); //SERIAL_ECHOLN("");
break; }
case 61: // G61 move to X Y Z in memory
{ /**
* G61: move to X Y Z in memory
*/
void gcode_G61() {
for(int8_t i=0; i < NUM_AXIS; i++) { for(int8_t i=0; i < NUM_AXIS; i++) {
if(code_seen(axis_codes[i])) if(code_seen(axis_codes[i])) {
{
destination[i] = (float)code_value() + lastpos[i]; destination[i] = (float)code_value() + lastpos[i];
} }
else else {
{
destination[i] = current_position[i]; destination[i] = current_position[i];
} }
} }
...@@ -3025,43 +2980,131 @@ void process_commands() ...@@ -3025,43 +2980,131 @@ void process_commands()
//finish moves //finish moves
prepare_move(); prepare_move();
} }
break;
case 90: // G90 /**
relative_mode = false; * G92: Set current position to given X Y Z E
break; */
case 91: // G91 void gcode_G92() {
relative_mode = true; if (!code_seen(axis_codes[E_AXIS]))
break;
case 92: // G92
if(!code_seen(axis_codes[E_AXIS]))
st_synchronize(); st_synchronize();
for(int8_t i=0; i < NUM_AXIS; i++) {
if(code_seen(axis_codes[i])) { for (int i=0; i < NUM_AXIS; i++) {
if(i == E_AXIS) { if (code_seen(axis_codes[i])) {
if (i == E_AXIS) {
current_position[i] = code_value(); current_position[i] = code_value();
plan_set_e_position(current_position[E_AXIS]); plan_set_e_position(current_position[E_AXIS]);
} }
else { else {
#ifdef SCARA current_position[i] = code_value() +
if (i == X_AXIS || i == Y_AXIS) { #ifdef SCARA
current_position[i] = code_value(); ((i != X_AXIS && i != Y_AXIS) ? add_homing[i] : 0)
} #else
else { add_homing[i]
current_position[i] = code_value()+add_homing[i]; #endif
} ;
#else
current_position[i] = code_value()+add_homing[i];
#endif
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]);
} }
} }
} }
}
/**
* Process Commands and dispatch them to handlers
*/
void process_commands() {
unsigned long codenum; //throw away variable
char *starpos = NULL;
if(code_seen('G')) {
switch((int)code_value()) {
// G0 -> G1
case 0:
case 1:
gcode_G0_G1();
break;
// G2, G3
#ifndef SCARA
case 2: // G2 - CW ARC
gcode_G2_G3(true);
break;
case 3: // G3 - CCW ARC
gcode_G2_G3(false);
break;
#endif
// G4 Dwell
case 4:
gcode_G4();
break;
#ifdef FWRETRACT
case 10: // G10: retract
gcode_G10_G11(true);
break;
case 11: // G11: retract_recover
gcode_G10_G11(false);
break;
#endif //FWRETRACT
case 28: // G28: Home all axes, one at a time
gcode_G28();
break;
#ifdef ENABLE_AUTO_BED_LEVELING
case 29: // G29 Detailed Z-Probe, probes the bed at 3 or more points.
gcode_G29();
break;
#ifndef Z_PROBE_SLED
case 30: // G30 Single Z Probe
gcode_G30();
break;
#else // Z_PROBE_SLED
case 31: // G31: dock the sled
dock_sled(true);
break;
case 32: // G32: undock the sled
dock_sled(false);
break;
#endif // Z_PROBE_SLED
#endif // ENABLE_AUTO_BED_LEVELING
#ifdef DELTA
case 29: // G29 Detailed Z-Probe, probes the bed at more points.
gcode_G29();
break;
case 30: // G30 Delta AutoCalibration
gcode_G30();
break;
#endif //DELTA
case 60: // G60 Store in memory actual position
gcode_G60();
break;
case 61: // G61 move to X Y Z in memory
gcode_G61();
break;
case 90: // G90
relative_mode = false;
break;
case 91: // G91
relative_mode = true;
break;
case 92: // G92
gcode_G92();
break; break;
} }
} }
else if(code_seen('M')){ else if(code_seen('M')) {
switch((int)code_value()){ switch((int)code_value()) {
#ifdef ULTIPANEL #ifdef ULTIPANEL
case 0: // M0 - Unconditional stop - Wait for user button press on LCD case 0: // M0 - Unconditional stop - Wait for user button press on LCD
......
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