chiark / gitweb /
M206: always use homing ("homeing") offsets
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 1 Aug 2012 20:12:14 +0000 (21:12 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 9 Aug 2012 18:20:23 +0000 (19:20 +0100)
Previously the parameters set in M206 would only be used if a G82
command was sent with specific axis home values.  This limits its
usefulness.

Really, we should have a way to adjust the XYZ homing of a machine in
the eeprom.  So as the first stage of this, make M206 affect every
home command.  The values set using M206 are now added to the
configuration variables [XYZ]_HOME_POS.

This is achieved by replacing all uses of [XYZ]_HOME_POS in the code
by [XYZ]_HOME_POS_A which is a macro which includes the adjustment.

A question arises: if the M206 offset is set, should this adjustment
to the home position shift or change the possible range of movement
permitted by the software endstops ?

I have taken the view that the software endstops are a backstop safety
feature which is not necessarily entirely accurate, and that reducing
the scope of movement, at either end, is not desirable.  I have
therefore arranged that nonzero values for M206 increase the total
range of movement.

So for example with
  #define X_MIN_POS 0
  #define X_HOME_POS 0
  #define X_MAX_POS 100

M206 X-10 would permit the machine to move from the endstop
(considered X=-10) 110mm in the positive X direction (considered
X=+100).

M206 X+10 would permit the machine to move from the endstop
(considered X=-10) 110mm in the positive X direction (considered
X=+110).

fixes #200 (in ErikZalm/Marlin).

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
Marlin/Marlin.h
Marlin/Marlin.pde
README.md

index 75b57d0b913075a5645dd8246a112b36853ce2da..b465d8535ad41b6f9131ef8d76861da21bfe08d5 100644 (file)
@@ -184,6 +184,8 @@ extern float homing_feedrate[];
 extern bool axis_relative_modes[];
 extern float current_position[NUM_AXIS] ;
 extern float add_homeing[3];
+extern float min_pos[3];
+extern float max_pos[3];
 extern unsigned char FanSpeed;
 
 // Handling multiple extruders pins
index d471d49c600ebb8ce5ba160b1fcbc6e864d99789..be91124e760e92c876110b32c64e41e02abf57bb 100644 (file)
@@ -143,6 +143,8 @@ volatile bool feedmultiplychanged=false;
 volatile int extrudemultiply=100; //100->1 200->2
 float current_position[NUM_AXIS] = { 0.0, 0.0, 0.0, 0.0 };
 float add_homeing[3]={0,0,0};
+float min_pos[3] = { X_MIN_POS, Y_MIN_POS, Z_MIN_POS };
+float max_pos[3] = { X_MAX_POS, Y_MAX_POS, Z_MAX_POS };
 uint8_t active_extruder = 0;
 unsigned char FanSpeed=0;
 
@@ -543,6 +545,18 @@ bool code_seen(char code)
   return (strchr_pointer != NULL);  //Return True if a character was found
 }
 
+static const PROGMEM float base_min_pos[3] = { X_MIN_POS, Y_MIN_POS, Z_MIN_POS };
+static const PROGMEM float base_max_pos[3] = { X_MAX_POS, Y_MAX_POS, Z_MAX_POS };
+static const PROGMEM float base_home_pos[3] = { X_HOME_POS, Y_HOME_POS, Z_HOME_POS };
+
+static void axis_is_at_home(int axis) {
+  current_position[axis] = base_home_pos[axis] + add_homeing[axis];
+  min_pos[axis] = base_min_pos[axis];
+  max_pos[axis] = base_max_pos[axis];
+  if (add_homeing[axis] < 0) min_pos[axis] += add_homeing[axis];
+  else max_pos[axis] += add_homeing[axis];
+}
+
 #define HOMEAXIS(LETTER) \
   if ((LETTER##_MIN_PIN > -1 && LETTER##_HOME_DIR==-1) || (LETTER##_MAX_PIN > -1 && LETTER##_HOME_DIR==1))\
     { \
@@ -564,8 +578,8 @@ bool code_seen(char code)
     plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder); \
     st_synchronize();\
     \
-    current_position[LETTER##_AXIS] = LETTER##_HOME_POS;\
-    destination[LETTER##_AXIS] = current_position[LETTER##_AXIS];\
+    axis_is_at_home(LETTER##_AXIS);                                    \
+    destination[LETTER##_AXIS] = current_position[LETTER##_AXIS]; \
     feedrate = 0.0;\
     endstops_hit_on_purpose();\
   }
@@ -678,8 +692,8 @@ void process_commands()
         plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder);
         st_synchronize();
     
-        current_position[X_AXIS] = X_HOME_POS;
-        current_position[Y_AXIS] = Y_HOME_POS;
+        axis_is_at_home(X_AXIS);
+        axis_is_at_home(Y_AXIS);
         plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
         destination[X_AXIS] = current_position[X_AXIS];
         destination[Y_AXIS] = current_position[Y_AXIS];
@@ -1544,15 +1558,15 @@ void get_arc_coordinates()
 void clamp_to_software_endstops(float target[3])
 {
   if (min_software_endstops) {
-    if (destination[X_AXIS] < X_MIN_POS) destination[X_AXIS] = X_MIN_POS;
-    if (destination[Y_AXIS] < Y_MIN_POS) destination[Y_AXIS] = Y_MIN_POS;
-    if (destination[Z_AXIS] < Z_MIN_POS) destination[Z_AXIS] = Z_MIN_POS;
+    if (destination[X_AXIS] < min_pos[X_AXIS]) destination[X_AXIS] = min_pos[X_AXIS];
+    if (destination[Y_AXIS] < min_pos[Y_AXIS]) destination[Y_AXIS] = min_pos[Y_AXIS];
+    if (destination[Z_AXIS] < min_pos[Z_AXIS]) destination[Z_AXIS] = min_pos[Z_AXIS];
   }
 
   if (max_software_endstops) {
-    if (destination[X_AXIS] > X_MAX_POS) destination[X_AXIS] = X_MAX_POS;
-    if (destination[Y_AXIS] > Y_MAX_POS) destination[Y_AXIS] = Y_MAX_POS;
-    if (destination[Z_AXIS] > Z_MAX_POS) destination[Z_AXIS] = Z_MAX_POS;
+    if (destination[X_AXIS] > max_pos[X_AXIS]) destination[X_AXIS] = max_pos[X_AXIS];
+    if (destination[Y_AXIS] > max_pos[Y_AXIS]) destination[Y_AXIS] = max_pos[Y_AXIS];
+    if (destination[Z_AXIS] > max_pos[Z_AXIS]) destination[Z_AXIS] = max_pos[Z_AXIS];
   }
 }
 
index 86dd93de952da7086db17b215378dd78dd3a6422..fb2c18968c4f8ad5a298331c5b19fbfd451dcd21 100644 (file)
--- a/README.md
+++ b/README.md
@@ -152,6 +152,7 @@ Movement variables:
 *   M202 - Set max acceleration in units/s^2 for travel moves (M202 X1000 Y1000) Unused in Marlin!!\r
 *   M203 - Set maximum feedrate that your machine can sustain (M203 X200 Y200 Z300 E10000) in mm/sec\r
 *   M204 - Set default acceleration: S normal moves T filament only moves (M204 S3000 T7000) im mm/sec^2  also sets minimum segment time in ms (B20000) to prevent buffer underruns and M20 minimum feedrate\r
+*   M206 - set home offsets.  This sets the X,Y,Z coordinates of the endstops (and is added to the {X,Y,Z}_HOME_POS configuration options (and is also added to the coordinates, if any, provided to G82, as with earlier firmware)\r
 *   M220 - set build speed mulitplying S:factor in percent ; aka "realtime tuneing in the gcode". So you can slow down if you have islands in one height-range, and speed up otherwise.\r
 *   M221 - set the extrude multiplying S:factor in percent\r
 *   M400 - Finish all buffered moves.\r