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;
#endif
#endif //ULTIPANEL
#ifdef SCARA // Build size scaling
float axis_scaling[3]={1,1,1}; // Build size scaling, default to 1
#ifdef SCARA
float axis_scaling[3] = { 1, 1, 1 }; // Build size scaling, default to 1
#endif //SCARA
bool cancel_heatup = false;
......@@ -432,6 +432,7 @@ static bool fromsd[BUFSIZE];
static int bufindr = 0;
static int bufindw = 0;
static int buflen = 0;
static char serial_char;
static int serial_count = 0;
static boolean comment_mode = false;
......@@ -577,6 +578,16 @@ void setup_photpin()
#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()
{
#if defined(SUICIDE_PIN) && SUICIDE_PIN > -1
......@@ -636,8 +647,8 @@ void servo_init()
}
void setup()
{
void setup() {
setup_killpin();
setup_pausepin();
......@@ -686,15 +697,9 @@ void setup()
watchdog_init();
st_init(); // Initialize stepper, this enables interrupts!
setup_photpin();
#ifdef LASERBEAM // Initialize Laser beam
SET_OUTPUT(LASER_PWR_PIN);
WRITE(LASER_PWR_PIN, LOW);
SET_OUTPUT(LASER_TTL_PIN);
WRITE(LASER_TTL_PIN, LOW);
#endif
setup_laserbeampin(); // Initialize Laserbeam
servo_init();
lcd_init();
_delay_ms(1000); // wait 1sec to display the splash screen
......@@ -716,38 +721,30 @@ void setup()
}
void loop()
{
if(buflen < (BUFSIZE-1))
get_command();
void loop() {
if (buflen < (BUFSIZE-1)) get_command();
#ifdef SDSUPPORT
card.checkautostart(false);
#endif
if(buflen)
{
if(buflen) {
#ifdef SDSUPPORT
if(card.saving)
{
if(strstr_P(cmdbuffer[bufindr], PSTR("M29")) == NULL)
{
if(card.saving) {
if(strstr_P(cmdbuffer[bufindr], PSTR("M29")) == NULL) {
card.write_command(cmdbuffer[bufindr]);
if(card.logging)
{
if(card.logging) {
process_commands();
}
else
{
else {
SERIAL_PROTOCOLLNPGM(MSG_OK);
}
}
else
{
else {
card.closefile();
SERIAL_PROTOCOLLNPGM(MSG_FILE_SAVED);
}
}
else
{
else {
process_commands();
}
#else
......@@ -763,8 +760,8 @@ void loop()
lcd_update();
}
void get_command()
{
void get_command() {
while( MYSERIAL.available() > 0 && buflen < BUFSIZE) {
serial_char = MYSERIAL.read();
if(serial_char == '\n' ||
......@@ -777,11 +774,10 @@ void get_command()
return;
}
cmdbuffer[bufindw][serial_count] = 0; //terminate string
if(!comment_mode){
if(!comment_mode) {
comment_mode = false; //for new command
fromsd[bufindw] = false;
if(strchr(cmdbuffer[bufindw], 'N') != NULL)
{
if(strchr(cmdbuffer[bufindw], 'N') != NULL) {
strchr_pointer = strchr(cmdbuffer[bufindw], 'N');
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) ) {
......@@ -794,8 +790,7 @@ void get_command()
return;
}
if(strchr(cmdbuffer[bufindw], '*') != NULL)
{
if(strchr(cmdbuffer[bufindw], '*') != NULL) {
byte checksum = 0;
byte count = 0;
while(cmdbuffer[bufindw][count] != '*') checksum = checksum^cmdbuffer[bufindw][count++];
......@@ -826,8 +821,7 @@ void get_command()
}
else // if we don't receive 'N' but still see '*'
{
if((strchr(cmdbuffer[bufindw], '*') != NULL))
{
if((strchr(cmdbuffer[bufindw], '*') != NULL)) {
SERIAL_ERROR_START;
SERIAL_ERRORPGM(MSG_ERR_NO_LINENUMBER_WITH_CHECKSUM);
SERIAL_ERRORLN(gcode_LastN);
......@@ -835,7 +829,7 @@ void get_command()
return;
}
}
if((strchr(cmdbuffer[bufindw], 'G') != NULL)){
if((strchr(cmdbuffer[bufindw], 'G') != NULL)) {
strchr_pointer = strchr(cmdbuffer[bufindw], 'G');
switch((int)((strtod(&cmdbuffer[bufindw][strchr_pointer - cmdbuffer[bufindw] + 1], NULL)))){
case 0:
......@@ -850,12 +844,10 @@ void get_command()
default:
break;
}
}
//If command was e-stop process now
if(strcmp(cmdbuffer[bufindw], "M112") == 0)
kill();
if(strcmp(cmdbuffer[bufindw], "M112") == 0) kill();
bufindw = (bufindw + 1)%BUFSIZE;
buflen += 1;
......@@ -1248,17 +1240,19 @@ static void retract_z_probe() {
}
/// 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
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]);
#ifndef Z_PROBE_SLED
if ((retract_action==0) || (retract_action==1))
engage_z_probe(); // Engage Z Servo endstop if available
#endif // Z_PROBE_SLED
run_z_probe();
float measured_z = current_position[Z_AXIS];
#ifndef Z_PROBE_SLED
if ((retract_action==0) || (retract_action==3))
retract_z_probe();
#endif // Z_PROBE_SLED
......@@ -1800,8 +1794,7 @@ void refresh_cmd_timeout(void)
}
#ifdef FWRETRACT
void retract(bool retracting, bool swapretract = false)
{
void retract(bool retracting, bool swapretract = false) {
if(retracting && !retracted[active_extruder]) {
destination[X_AXIS]=current_position[X_AXIS];
destination[Y_AXIS]=current_position[Y_AXIS];
......@@ -1817,6 +1810,7 @@ void retract(bool retracting, bool swapretract = false)
feedrate=retract_feedrate*60;
retracted[active_extruder]=true;
prepare_move();
if(retract_zlift > 0.01) {
current_position[Z_AXIS]-=retract_zlift;
#ifdef DELTA
calculate_delta(current_position); // change cartesian kinematic to delta kinematic;
......@@ -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]);
#endif
prepare_move();
}
feedrate = oldFeedrate;
} else if(!retracting && retracted[active_extruder]) {
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(retract_zlift > 0.01) {
current_position[Z_AXIS]+=retract_zlift;
#ifdef DELTA
calculate_delta(current_position); // change cartesian kinematic to delta kinematic;
......@@ -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]);
#endif
//prepare_move();
}
if (swapretract) {
current_position[E_AXIS]-=(retract_length_swap+retract_recover_length_swap)/volumetric_multiplier[active_extruder];
} else {
......@@ -1891,89 +1888,93 @@ static void dock_sled(bool dock, int offset=0)
}
#endif //Z_PROBE_SLED
void process_commands()
{
unsigned long codenum; //throw away variable
char *starpos = NULL;
#ifdef ENABLE_AUTO_BED_LEVELING
float x_tmp, y_tmp, z_tmp, real_z;
#endif
if(code_seen('G')) {
switch((int)code_value()) {
case 0: // G0 -> G1
case 1: // G1
if(Stopped == false) {
/******************************************************************************
* G-Code Functions
*******************************************************************************/
/**
* G0 / G1: Coordinated movement of X Y Z E axes
*/
void gcode_G0_G1() {
if (!Stopped) {
get_coordinates(); // For X Y Z E F
#ifdef FWRETRACT
if(autoretract_enabled)
if( !(code_seen('X') || code_seen('Y') || code_seen('Z')) && code_seen('E')) {
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
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
#ifdef FWRETRACT
if (autoretract_enabled)
if (!(code_seen('X') || code_seen('Y') || code_seen('Z')) && code_seen('E')) {
float echange = destination[E_AXIS] - current_position[E_AXIS];
// Is this move an attempt to retract or recover?
if ((echange < -MIN_RETRACT && !retracted) || (echange > MIN_RETRACT && retracted)) {
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);
return;
}
}
#endif //FWRETRACT
#endif //FWRETRACT
prepare_move();
//ClearToSend();
}
break;
}
#ifndef SCARA //disable arc support
case 2: // G2 - CW ARC
if(Stopped == false) {
get_arc_coordinates();
prepare_arc_move(true);
}
break;
case 3: // G3 - CCW ARC
if(Stopped == false) {
/**
* G2: Clockwise Arc
* G3: Counterclockwise Arc
*/
void gcode_G2_G3(bool clockwise) {
if (!Stopped) {
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);
codenum = 0;
if(code_seen('P')) codenum = code_value(); // milliseconds to wait
if(code_seen('S')) codenum = code_value() * 1000; // seconds to wait
if (code_seen('P')) codenum = code_value(); // milliseconds to wait
if (code_seen('S')) codenum = code_value() * 1000; // seconds to wait
st_synchronize();
codenum += millis(); // keep track of when we started waiting
refresh_cmd_timeout();
previous_millis_cmd = millis();
while(millis() < codenum) {
manage_heater();
manage_inactivity();
lcd_update();
}
break;
}
#ifdef FWRETRACT
case 10: // G10 retract
#if EXTRUDERS > 1
retracted_swap[active_extruder]=(code_seen('S') && code_value_long() == 1); // checks for swap retract argument
retract(true,retracted_swap[active_extruder]);
#else
retract(true);
#endif
break;
case 11: // G11 retract_recover
#if EXTRUDERS > 1
retract(false,retracted_swap[active_extruder]);
#else
retract(false);
#endif
break;
/**
* G10 - Retract filament according to settings of M207
* G11 - Recover filament according to settings of M208
*/
void gcode_G10_G11(bool doRetract=false) {
#if EXTRUDERS > 1
if (doRetract) {
retracted_swap[active_extruder] = (code_seen('S') && code_value_long() == 1); // checks for swap retract argument
}
#endif
retract (doRetract
#if EXTRUDERS > 1
, retracted_swap[active_extruder]
#endif
);
}
#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)
#endif //ENABLE_AUTO_BED_LEVELING
#endif //ENABLE_AUTO_BED_LEVELING
saved_feedrate = feedrate;
saved_feedmultiply = feedmultiply;
......@@ -1982,14 +1983,13 @@ void process_commands()
enable_endstops(true);
for(int8_t i=0; i < NUM_AXIS; i++) {
destination[i] = current_position[i];
}
for(int8_t i=0; i < NUM_AXIS; i++) destination[i] = current_position[i];
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])));
#ifdef NPR2
#ifdef NPR2
if((home_all_axis) || (code_seen(axis_codes[E_AXIS]))) {
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);
......@@ -1997,29 +1997,24 @@ void process_commands()
old_color = 99;
active_driver = active_extruder = 0;
}
#endif
#endif
#ifdef DELTA
#ifdef DELTA
// A delta can only safely home all axis at the same time
// all axis have to home at the same time
// Move all carriages up together until the first endstop is hit.
current_position[X_AXIS] = 0;
current_position[Y_AXIS] = 0;
current_position[Z_AXIS] = 0;
for (int i = X_AXIS; i <= Z_AXIS; i++) current_position[i] = 0;
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];
destination[Y_AXIS] = 3 * max_length[Z_AXIS];
destination[Z_AXIS] = 3 * max_length[Z_AXIS];
for (int i = X_AXIS; i <= Z_AXIS; i++) destination[i] = 3 * max_length[Z_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);
st_synchronize();
endstops_hit_on_purpose();
current_position[X_AXIS] = destination[X_AXIS];
current_position[Y_AXIS] = destination[Y_AXIS];
current_position[Z_AXIS] = destination[Z_AXIS];
// Destination reached
for (int i = X_AXIS; i <= Z_AXIS; i++) current_position[i] = destination[i];
// take care of back off and rehome now we are all at the top
HOMEAXIS(X);
......@@ -2029,32 +2024,30 @@ void process_commands()
calculate_delta(current_position);
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]))) {
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
current_position[X_AXIS] = 0;
current_position[Y_AXIS] = 0;
current_position[X_AXIS] = current_position[Y_AXIS] = 0;
#ifndef DUAL_X_CARRIAGE
#ifndef DUAL_X_CARRIAGE
int x_axis_home_dir = home_dir(X_AXIS);
#else
#else
int x_axis_home_dir = x_home_dir(active_extruder);
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]);
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);
feedrate = homing_feedrate[X_AXIS];
if(homing_feedrate[Y_AXIS]<feedrate)
feedrate = homing_feedrate[Y_AXIS];
if(homing_feedrate[Y_AXIS]<feedrate) feedrate = homing_feedrate[Y_AXIS];
if (max_length(X_AXIS) > max_length(Y_AXIS)) {
feedrate *= sqrt(pow(max_length(Y_AXIS) / max_length(X_AXIS), 2) + 1);
}
......@@ -2076,14 +2069,14 @@ void process_commands()
current_position[X_AXIS] = destination[X_AXIS];
current_position[Y_AXIS] = destination[Y_AXIS];
#ifndef SCARA
#ifndef SCARA
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]))) {
#ifdef DUAL_X_CARRIAGE
#ifdef DUAL_X_CARRIAGE
int tmp_extruder = active_extruder;
extruder_duplication_enabled = false;
active_extruder = !active_extruder;
......@@ -2095,39 +2088,35 @@ void process_commands()
memcpy(raised_parked_position, current_position, sizeof(raised_parked_position));
delayed_move_time = 0;
active_extruder_parked = true;
#else
#else
HOMEAXIS(X);
#endif // DUAL_X_CARRIAGE
#endif // DUAL_X_CARRIAGE
}
if((home_all_axis) || (code_seen(axis_codes[Y_AXIS]))) {
HOMEAXIS(Y);
}
if((home_all_axis) || (code_seen(axis_codes[Y_AXIS]))) HOMEAXIS(Y);
if(code_seen(axis_codes[X_AXIS])) {
if(code_value_long() != 0) {
#ifdef SCARA
#ifdef SCARA
current_position[X_AXIS]=code_value();
#else
#else
current_position[X_AXIS]=code_value()+add_homing[X_AXIS];
#endif
#endif
}
}
if(code_seen(axis_codes[Y_AXIS])) {
if(code_value_long() != 0) {
#ifdef SCARA
if (code_seen(axis_codes[Y_AXIS]) && code_value_long() != 0) {
#ifdef SCARA
current_position[Y_AXIS]=code_value();
#else
#else
current_position[Y_AXIS]=code_value()+add_homing[Y_AXIS];
#endif
}
#endif
}
#if Z_HOME_DIR < 0 // If homing towards BED do Z last
#ifndef Z_SAFE_HOMING
#if Z_HOME_DIR < 0 // If homing towards BED do Z last
#ifndef Z_SAFE_HOMING
if (code_seen('M')) { // Manual G28
#ifdef ULTIPANEL
#ifdef ULTIPANEL
if(home_all_axis) {
boolean zig = true;
int xGridSpacing = (RIGHT_PROBE_BED_POSITION - LEFT_PROBE_BED_POSITION);
......@@ -2163,19 +2152,18 @@ void process_commands()
manage_inactivity();
lcd_update();
if(beepbutton) {
#if BEEPER > 0
#if BEEPER > 0
SET_OUTPUT(BEEPER);
WRITE(BEEPER,HIGH);
delay(100);
WRITE(BEEPER,LOW);
delay(3);
#else
#if !defined(LCD_FEEDBACK_FREQUENCY_HZ) || !defined(LCD_FEEDBACK_FREQUENCY_DURATION_MS)
#else
#if !defined(LCD_FEEDBACK_FREQUENCY_HZ) || !defined(LCD_FEEDBACK_FREQUENCY_DURATION_MS)
lcd_buzz(1000/6,100);
#else
lcd_buzz(LCD_FEEDBACK_FREQUENCY_DURATION_MS,LCD_FEEDBACK_FREQUENCY_HZ);
#endif
#endif
#else lcd_buzz(LCD_FEEDBACK_FREQUENCY_DURATION_MS,LCD_FEEDBACK_FREQUENCY_HZ);
#endif
#endif
beepbutton=false;
}
}
......@@ -2188,18 +2176,18 @@ void process_commands()
enquecommand("G4 P0");
enquecommand("G4 P0");
}
#endif // ULTIPANEL
#endif // ULTIPANEL
}
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
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
#endif
HOMEAXIS(Z);
}
#else // Z Safe mode activated.
#else // Z Safe mode activated.
if(home_all_axis) {
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);
......@@ -2217,83 +2205,84 @@ void process_commands()
}
// Let's see if X and Y are homed and probe is inside bed area.
if(code_seen(axis_codes[Z_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)) {
if (axis_known_position[X_AXIS] && axis_known_position[Y_AXIS]) {
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;
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
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();
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 {
LCD_MESSAGEPGM(MSG_ZPROBE_OUT);
SERIAL_ECHO_START;
SERIAL_ECHOLNPGM(MSG_ZPROBE_OUT);
}
}
#endif // Z_SAFE_HOMING
#endif // Z_HOME_DIR < 0
if(code_seen(axis_codes[Z_AXIS])) {
if(code_value_long() != 0) {
current_position[Z_AXIS]=code_value()+add_homing[Z_AXIS];
else {
LCD_MESSAGEPGM(MSG_POSITION_UNKNOWN);
SERIAL_ECHO_START;
SERIAL_ECHOLNPGM(MSG_POSITION_UNKNOWN);
}
}
#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]))) {
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]);
#endif // else DELTA
#endif // else DELTA
#ifdef SCARA
#ifdef SCARA
calculate_delta(current_position);
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);
#endif
#endif
feedrate = saved_feedrate;
feedmultiply = saved_feedmultiply;
refresh_cmd_timeout();
endstops_hit_on_purpose();
break;
}
#ifdef ENABLE_AUTO_BED_LEVELING
case 29: // G29 Detailed Z-Probe, probes the bed at 3 or more points.
{
#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
/**
* G29: Detailed Z-Probe, probes the bed at 3 or more points.
* Will fail if the printer has not been homed with G28.
*/
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
if (! (axis_known_position[X_AXIS] && axis_known_position[Y_AXIS]) ) {
LCD_MESSAGEPGM(MSG_POSITION_UNKNOWN);
SERIAL_ECHO_START;
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);
#endif // Z_PROBE_SLED
#endif // Z_PROBE_SLED
st_synchronize();
// make sure the bed_level_rotation_matrix is identity or the planner will get it incorectly
......@@ -2309,48 +2298,26 @@ void process_commands()
setup_for_endstop_move();
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 l_probe_bed_position = LEFT_PROBE_BED_POSITION;
int f_probe_bed_position = FRONT_PROBE_BED_POSITION;
int b_probe_bed_position = BACK_PROBE_BED_POSITION;
int a_bed_leveling_points = AUTO_BED_LEVELING_GRID_POINTS;
if(code_seen('R'))
{
r_probe_bed_position = 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 (code_seen('R')) r_probe_bed_position = 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_ERRORLNPGM(MSG_EMPTY_PLANE);
break;
return;
}
// probe at the points of a lattice grid
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);
......@@ -2368,11 +2335,9 @@ void process_commands()
int probePointCounter = 0;
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;
if (zig)
{
if (zig) {
xProbe = l_probe_bed_position;
//xEnd = RIGHT_PROBE_BED_POSITION;
xInc = xGridSpacing;
......@@ -2386,24 +2351,19 @@ void process_commands()
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;
if (probePointCounter == 0)
{
if (probePointCounter == 0) {
// raise before probing
z_before = Z_RAISE_BEFORE_PROBING;
}
else
{
else {
// raise extruder
z_before = current_position[Z_AXIS] + Z_RAISE_BETWEEN_PROBINGS;
}
float measured_z = probe_pt(xProbe, yProbe, z_before);
eqnBVector[probePointCounter] = measured_z;
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 + 2*a_bed_leveling_points*a_bed_leveling_points] = 1;
......@@ -2423,12 +2383,10 @@ void process_commands()
SERIAL_PROTOCOLPGM(" d: ");
SERIAL_PROTOCOLLN(plane_equation_coefficients[2]);
set_bed_level_equation_lsq(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 1
......@@ -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);
clean_up_after_endstop_move();
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();
// The following code correct the Z height difference from z-probe position and hotend tip position.
......@@ -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
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]);
#ifdef Z_PROBE_SLED
#ifdef Z_PROBE_SLED
dock_sled(true, -SLED_DOCKING_OFFSET); // correct for over travel.
#endif // Z_PROBE_SLED
}
break;
#endif // 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
st_synchronize();
// TODO: make sure the bed_level_rotation_matrix is identity or the planner will get set incorectly
......@@ -2486,21 +2442,16 @@ void process_commands()
clean_up_after_endstop_move();
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 // ENABLE_AUTO_BED_LEVELING
#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')){
SERIAL_ECHOLN("Current bed level array values:");
SERIAL_ECHOLN("");
......@@ -2511,25 +2462,26 @@ void process_commands()
}
SERIAL_ECHOLN("");
}
break;
return;
}
saved_feedrate = feedrate;
saved_feedmultiply = feedmultiply;
feedmultiply = 100;
deploy_z_probe();
calibrate_print_surface(z_probe_offset[Z_AXIS] +
(code_seen(axis_codes[Z_AXIS]) ? code_value() : 0.0));
calibrate_print_surface(z_probe_offset[Z_AXIS] + (code_seen(axis_codes[Z_AXIS]) ? code_value() : 0.0));
retract_z_probe();
feedrate = saved_feedrate;
feedmultiply = saved_feedmultiply;
refresh_cmd_timeout();
endstops_hit_on_purpose();
break;
}
case 30: //G30 Delta AutoCalibration
/**
* G30: Delta AutoCalibration
*/
void gcode_G30() {
int iterations;
//Zero the bed level array
......@@ -2551,7 +2503,7 @@ void process_commands()
SERIAL_ECHO(saved_positions[i][Z_AXIS]);
SERIAL_ECHOLN("]");
}
break;
return;
}
if (code_seen('F')) {
probing_feedrate=code_value();
......@@ -2580,7 +2532,7 @@ void process_commands()
SERIAL_ECHO(saved_position[Z_AXIS]);
SERIAL_ECHOLN("]");
retract_z_probe();
break;
return;
}
saved_feedrate = feedrate;
......@@ -2656,7 +2608,7 @@ void process_commands()
//Restore saved variables
feedrate = saved_feedrate;
feedmultiply = saved_feedmultiply;
break;
return;
}
if (code_seen('D')) {
......@@ -2800,7 +2752,7 @@ void process_commands()
if ((radiusErrorC >= (radiusErrorA - 0.02)) and (radiusErrorC <= (radiusErrorA + 0.02))) equalCA = true;
else equalCA = false;
#ifdef DEBUG_MESSAGES
#ifdef DEBUG_MESSAGES
if (equalAB == true) {
SERIAL_ECHOPAIR("Tower AB Equal (A=",radiusErrorA);
SERIAL_ECHOPAIR(" B=",radiusErrorB);
......@@ -2821,13 +2773,13 @@ void process_commands()
SERIAL_ECHOLN(")");
}
else SERIAL_ECHOLN("equalCA=false");
#endif // DEBUG_MESSAGES
#endif // DEBUG_MESSAGES
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
#ifdef DEBUG_MESSAGES
#ifdef DEBUG_MESSAGES
SERIAL_ECHOLN("All tower radius errors equal");
#endif
#endif
adj_RadiusA = adj_RadiusB = adj_RadiusC = 0;
}
......@@ -2837,10 +2789,10 @@ void process_commands()
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;
#ifdef DEBUG_MESSAGES
#ifdef DEBUG_MESSAGES
SERIAL_ECHOPAIR("adj_RadiusC set to ",adj_RadiusC);
SERIAL_ECHOLN("");
#endif
#endif
}
}
if ((equalBC == true) and (equalAB == false) and (equalCA == false)) {
......@@ -2849,10 +2801,10 @@ void process_commands()
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;
#ifdef DEBUG_MESSAGES
#ifdef DEBUG_MESSAGES
SERIAL_ECHOPAIR("adj_RadiusA set to ",adj_RadiusA);
SERIAL_ECHOLN("");
#endif
#endif
}
}
if ((equalCA == true) and (equalAB == false) and (equalBC == false)) {
......@@ -2861,10 +2813,10 @@ void process_commands()
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;
#ifdef DEBUG_MESSAGES
#ifdef DEBUG_MESSAGES
SERIAL_ECHOPAIR("adj_RadiusB set to ",adj_RadiusB);
SERIAL_ECHOLN("");
#endif
#endif
}
}
......@@ -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;
else adj_dr_done = false;
#ifdef DEBUG_MESSAGES
#ifdef DEBUG_MESSAGES
SERIAL_ECHOPAIR("c: ", bed_level_c);
SERIAL_ECHOPAIR(" x: ", bed_level_x);
SERIAL_ECHOPAIR(" y: ", bed_level_y);
......@@ -2927,8 +2879,7 @@ void process_commands()
SERIAL_ECHOLN("");
SERIAL_ECHOPAIR("DeltaAlphaC: ",adj_AlphaC);
SERIAL_ECHOLN("");
#endif
#endif
}
while (((adj_r_done == false) or (adj_dr_done = false)) and (loopcount < iterations));
}
......@@ -2962,7 +2913,6 @@ void process_commands()
and (bed_level_c >= -ac_prec) and (bed_level_c <= ac_prec)) loopcount = iterations;
}
}
loopcount ++;
}
while(loopcount < iterations);
......@@ -2986,10 +2936,14 @@ void process_commands()
//Restore saved variables
feedrate = saved_feedrate;
feedmultiply = saved_feedmultiply;
break;
}
#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[Y_AXIS]=current_position[Y_AXIS];
lastpos[Z_AXIS]=current_position[Z_AXIS];
......@@ -2999,16 +2953,17 @@ void process_commands()
//SERIAL_ECHOPAIR(" Lastpos Z: ", lastpos[Z_AXIS]);
//SERIAL_ECHOPAIR(" Lastpos E: ", lastpos[E_AXIS]);
//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++) {
if(code_seen(axis_codes[i]))
{
if(code_seen(axis_codes[i])) {
destination[i] = (float)code_value() + lastpos[i];
}
else
{
else {
destination[i] = current_position[i];
}
}
......@@ -3025,43 +2980,131 @@ void process_commands()
//finish moves
prepare_move();
}
break;
case 90: // G90
relative_mode = false;
break;
case 91: // G91
relative_mode = true;
break;
case 92: // G92
if(!code_seen(axis_codes[E_AXIS]))
}
/**
* G92: Set current position to given X Y Z E
*/
void gcode_G92() {
if (!code_seen(axis_codes[E_AXIS]))
st_synchronize();
for(int8_t i=0; i < NUM_AXIS; i++) {
if(code_seen(axis_codes[i])) {
if(i == E_AXIS) {
for (int i=0; i < NUM_AXIS; i++) {
if (code_seen(axis_codes[i])) {
if (i == E_AXIS) {
current_position[i] = code_value();
plan_set_e_position(current_position[E_AXIS]);
}
else {
#ifdef SCARA
if (i == X_AXIS || i == Y_AXIS) {
current_position[i] = code_value();
}
else {
current_position[i] = code_value()+add_homing[i];
}
#else
current_position[i] = code_value()+add_homing[i];
#endif
current_position[i] = code_value() +
#ifdef SCARA
((i != X_AXIS && i != Y_AXIS) ? add_homing[i] : 0)
#else
add_homing[i]
#endif
;
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;
}
}
else if(code_seen('M')){
switch((int)code_value()){
else if(code_seen('M')) {
switch((int)code_value()) {
#ifdef ULTIPANEL
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