Quellcode durchsuchen

M206: always use homing ("homeing") offsets

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 a new home_pos[] which includes the adjustment.  We also have to
adjust the uses of [XYZ]_{MIN,MAX}_POS similarly - see below.


To allow axis_is_at_home to be written as a function taking an axis
index rather than a macro taking an axis letter, we provide
constant arrays in program memory containing the values of
[XYZ]_{MIN,MAX,HOME}_POS from the compiled-in configuration.

This is done with some helper macros to deal with the declaration
(XYZ_CONSTS_FROM_CONFIG) and definition of the inline function which
does the program memory access.

We also introduce the overloaded function read_pgm_any, whose
instances are produced with DEFINE_PGM_READ_ANY, which allows the
access functions to automatically produce the correct type.

The type- and pointer-massaging code in the access function boils
down, when compiled, to a simple program memory access.


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 ?

The documentation in Configuration.h describes these limits as:
    // Travel limits after homing
Since this is a file containing physical limits, and actual suggested
values for these configuration parameters appear to include a certain
amount of slop, I've taken the view that these should be regarded as
nominal physical distances from the limit switches, and that the
permissible travel should be unaffected by M206.

So for example with the (rather unrealistic)
  #define X_HOME_DIR -1
  #define X_MIN_POS -20
  #define X_HOME_POS 0
  #define X_MAX_POS 100
no matter the setting of M206 X, the machine would be permitted
to move from 20mm "beyond" the limit switch trigger point in
the negative X direction and 100mm away from the limit switch in
the positive X direction, for a total travel of 120mm.

With M206 X-10 that would be considered to correspond to X coordinates
-30 to +90.  With M206 X+10 that would be considered to correspond to
X coordinates -10 to +110.


fixes #200 (in ErikZalm/Marlin).

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
Ian Jackson vor 12 Jahren
Ursprung
Commit
957e966d2d
3 geänderte Dateien mit 37 neuen und 10 gelöschten Zeilen
  1. 2
    0
      Marlin/Marlin.h
  2. 34
    10
      Marlin/Marlin.pde
  3. 1
    0
      README.md

+ 2
- 0
Marlin/Marlin.h Datei anzeigen

@@ -184,6 +184,8 @@ extern float homing_feedrate[];
184 184
 extern bool axis_relative_modes[];
185 185
 extern float current_position[NUM_AXIS] ;
186 186
 extern float add_homeing[3];
187
+extern float min_pos[3];
188
+extern float max_pos[3];
187 189
 extern unsigned char FanSpeed;
188 190
 
189 191
 // Handling multiple extruders pins

+ 34
- 10
Marlin/Marlin.pde Datei anzeigen

@@ -143,6 +143,8 @@ volatile bool feedmultiplychanged=false;
143 143
 volatile int extrudemultiply=100; //100->1 200->2
144 144
 float current_position[NUM_AXIS] = { 0.0, 0.0, 0.0, 0.0 };
145 145
 float add_homeing[3]={0,0,0};
146
+float min_pos[3] = { X_MIN_POS, Y_MIN_POS, Z_MIN_POS };
147
+float max_pos[3] = { X_MAX_POS, Y_MAX_POS, Z_MAX_POS };
146 148
 uint8_t active_extruder = 0;
147 149
 unsigned char FanSpeed=0;
148 150
 
@@ -543,6 +545,28 @@ bool code_seen(char code)
543 545
   return (strchr_pointer != NULL);  //Return True if a character was found
544 546
 }
545 547
 
548
+#define DEFINE_PGM_READ_ANY(type, reader)		\
549
+    static inline type pgm_read_any(const type *p)	\
550
+	{ return pgm_read_##reader##_near(p); }
551
+
552
+DEFINE_PGM_READ_ANY(float,       float);
553
+
554
+#define XYZ_CONSTS_FROM_CONFIG(type, array, CONFIG)	\
555
+static const PROGMEM type array##_P[3] =		\
556
+    { X_##CONFIG, Y_##CONFIG, Z_##CONFIG };		\
557
+static inline type array(int axis)			\
558
+    { return pgm_read_any(&array##_P[axis]); }
559
+
560
+XYZ_CONSTS_FROM_CONFIG(float, base_min_pos,    MIN_POS);
561
+XYZ_CONSTS_FROM_CONFIG(float, base_max_pos,    MAX_POS);
562
+XYZ_CONSTS_FROM_CONFIG(float, base_home_pos,   HOME_POS);
563
+
564
+static void axis_is_at_home(int axis) {
565
+  current_position[axis] = base_home_pos(axis) + add_homeing[axis];
566
+  min_pos[axis] =          base_min_pos(axis) + add_homeing[axis];
567
+  max_pos[axis] =          base_max_pos(axis) + add_homeing[axis];
568
+}
569
+
546 570
 #define HOMEAXIS(LETTER) \
547 571
   if ((LETTER##_MIN_PIN > -1 && LETTER##_HOME_DIR==-1) || (LETTER##_MAX_PIN > -1 && LETTER##_HOME_DIR==1))\
548 572
     { \
@@ -564,8 +588,8 @@ bool code_seen(char code)
564 588
     plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder); \
565 589
     st_synchronize();\
566 590
     \
567
-    current_position[LETTER##_AXIS] = LETTER##_HOME_POS;\
568
-    destination[LETTER##_AXIS] = current_position[LETTER##_AXIS];\
591
+    axis_is_at_home(LETTER##_AXIS);					\
592
+    destination[LETTER##_AXIS] = current_position[LETTER##_AXIS]; \
569 593
     feedrate = 0.0;\
570 594
     endstops_hit_on_purpose();\
571 595
   }
@@ -678,8 +702,8 @@ void process_commands()
678 702
         plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder);
679 703
         st_synchronize();
680 704
     
681
-        current_position[X_AXIS] = X_HOME_POS;
682
-        current_position[Y_AXIS] = Y_HOME_POS;
705
+        axis_is_at_home(X_AXIS);
706
+        axis_is_at_home(Y_AXIS);
683 707
         plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
684 708
         destination[X_AXIS] = current_position[X_AXIS];
685 709
         destination[Y_AXIS] = current_position[Y_AXIS];
@@ -1544,15 +1568,15 @@ void get_arc_coordinates()
1544 1568
 void clamp_to_software_endstops(float target[3])
1545 1569
 {
1546 1570
   if (min_software_endstops) {
1547
-    if (target[X_AXIS] < X_MIN_POS) target[X_AXIS] = X_MIN_POS;
1548
-    if (target[Y_AXIS] < Y_MIN_POS) target[Y_AXIS] = Y_MIN_POS;
1549
-    if (target[Z_AXIS] < Z_MIN_POS) target[Z_AXIS] = Z_MIN_POS;
1571
+    if (target[X_AXIS] < min_pos[X_AXIS]) target[X_AXIS] = min_pos[X_AXIS];
1572
+    if (target[Y_AXIS] < min_pos[Y_AXIS]) target[Y_AXIS] = min_pos[Y_AXIS];
1573
+    if (target[Z_AXIS] < min_pos[Z_AXIS]) target[Z_AXIS] = min_pos[Z_AXIS];
1550 1574
   }
1551 1575
 
1552 1576
   if (max_software_endstops) {
1553
-    if (target[X_AXIS] > X_MAX_POS) target[X_AXIS] = X_MAX_POS;
1554
-    if (target[Y_AXIS] > Y_MAX_POS) target[Y_AXIS] = Y_MAX_POS;
1555
-    if (target[Z_AXIS] > Z_MAX_POS) target[Z_AXIS] = Z_MAX_POS;
1577
+    if (target[X_AXIS] > max_pos[X_AXIS]) target[X_AXIS] = max_pos[X_AXIS];
1578
+    if (target[Y_AXIS] > max_pos[Y_AXIS]) target[Y_AXIS] = max_pos[Y_AXIS];
1579
+    if (target[Z_AXIS] > max_pos[Z_AXIS]) target[Z_AXIS] = max_pos[Z_AXIS];
1556 1580
   }
1557 1581
 }
1558 1582
 

+ 1
- 0
README.md Datei anzeigen

@@ -152,6 +152,7 @@ Movement variables:
152 152
 *   M202 - Set max acceleration in units/s^2 for travel moves (M202 X1000 Y1000) Unused in Marlin!!
153 153
 *   M203 - Set maximum feedrate that your machine can sustain (M203 X200 Y200 Z300 E10000) in mm/sec
154 154
 *   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
155
+*   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)
155 156
 *   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.
156 157
 *   M221 - set the extrude multiplying S:factor in percent
157 158
 *   M400 - Finish all buffered moves.

Laden…
Abbrechen
Speichern