Add homing order to config
authorJim Morris <morris@wolfman.com>
Sat, 2 Aug 2014 07:35:01 +0000 (00:35 -0700)
committerJim Morris <morris@wolfman.com>
Sat, 2 Aug 2014 07:35:01 +0000 (00:35 -0700)
ConfigSamples/Smoothieboard/config
src/modules/tools/endstops/Endstops.cpp
src/modules/tools/endstops/Endstops.h
src/modules/tools/zprobe/ThreePointStrategy.cpp

index c8f662b..9022b1f 100644 (file)
@@ -206,6 +206,10 @@ gamma_homing_direction                       home_to_min      #
 gamma_min                                    0                #
 gamma_max                                    200              #
 
+# optional order in which axis will home, default is they all home at the same time,
+# if this is set it will force each axis to home one at a time in the specified order
+#homing_order                                 XYZ              # x axis followed by y then z last
+
 # optional enable limit switches, actions will stop if any enabled limit switch is triggered
 #alpha_limit_enable                          false            # set to true to enable X min and max limit switches
 #beta_limit_enable                           false            # set to true to enable Y min and max limit switches
index 727408d..cb45e74 100644 (file)
@@ -28,6 +28,8 @@
 #include "StreamOutputPool.h"
 #include "Pauser.h"
 
+#include <ctype.h>
+
 #define ALPHA_AXIS 0
 #define BETA_AXIS  1
 #define GAMMA_AXIS 2
@@ -97,6 +99,8 @@
 #define beta_limit_enable_checksum       CHECKSUM("beta_limit_enable")
 #define gamma_limit_enable_checksum      CHECKSUM("gamma_limit_enable")
 
+#define homing_order_checksum            CHECKSUM("homing_order")
+
 #define STEPPER THEKERNEL->robot->actuators
 #define STEPS_PER_MM(a) (STEPPER[a]->get_steps_per_mm())
 
@@ -186,6 +190,22 @@ void Endstops::on_config_reload(void *argument)
     this->is_corexy                 =  THEKERNEL->config->value(corexy_homing_checksum)->by_default(false)->as_bool();
     this->is_delta                  =  THEKERNEL->config->value(delta_homing_checksum)->by_default(false)->as_bool();
 
+    // see if an order has been specified, must be three characters, XYZ or YXZ etc
+    string order= THEKERNEL->config->value(homing_order_checksum)->by_default("")->as_string();
+    this->homing_order= 0;
+    if(order.size() == 3 && !this->is_delta) {
+        int shift= 0;
+        for(auto c : order) {
+            uint8_t i= toupper(c) - 'X';
+            if(i > 2) { // bad value
+                this->homing_order= 0;
+                break;
+            }
+            homing_order |= (i << shift);
+            shift += 2;
+        }
+    }
+
     // endstop trim used by deltas to do soft adjusting
     // on a delta homing to max, a negative trim value will move the carriage down, and a positive will move it up
     this->trim_mm[0] = THEKERNEL->config->value(alpha_trim_checksum )->by_default(0  )->as_number();
@@ -280,9 +300,15 @@ void Endstops::wait_for_homed(char axes_to_move)
     }
 }
 
-// this homing works for cartesian and delta printers, not for HBots/CoreXY
 void Endstops::do_homing(char axes_to_move)
 {
+    if (is_corexy){
+        // do corexy/HBot homing
+        do_homing_corexy(axes_to_move);
+        return;
+    }
+
+    // this homing works for cartesian and delta printers
     // Start moving the axes to the origin
     this->status = MOVING_TO_ORIGIN_FAST;
     for ( int c = X_AXIS; c <= Z_AXIS; c++ ) {
@@ -517,10 +543,19 @@ void Endstops::on_gcode_received(void *argument)
             THEKERNEL->stepper->turn_enable_pins_on();
 
             // do the actual homing
-            if (is_corexy)
-                do_homing_corexy(axes_to_move);
-            else
+            if(homing_order != 0){
+                // if an order has been specified do it in the specified order
+                // homing order is 0b00ccbbaa where aa is 0,1,2 to specify the first axis, bb is the second and cc is the third
+                // eg 0b00100001 would be Y X Z, 0b00100100 would be X Y Z
+                for (uint8_t m = homing_order; m != 0; m >>= 2) {
+                    int a= (1 << (m & 0x03)); // axis to move
+                    if((a & axes_to_move) != 0)
+                        do_homing(a);
+                }
+            }else {
+                // they all home at the same time
                 do_homing(axes_to_move);
+            }
 
             // Zero the ax(i/e)s position, add in the home offset
             for ( int c = X_AXIS; c <= Z_AXIS; c++ ) {
index 86866e0..5163501 100644 (file)
@@ -36,6 +36,7 @@ class Endstops : public Module{
 
         float homing_position[3];
         float home_offset[3];
+        uint8_t homing_order;
         std::bitset<3> home_direction;
         std::bitset<3> limit_enable;
 
index 7530d9e..cde5912 100644 (file)
@@ -106,6 +106,7 @@ bool ThreePointStrategy::doProbing(StreamOutput *stream)
         }
     }
 
+    // TODO allow for manual homing
     // home X & Y
     homeXY();
 
@@ -135,8 +136,11 @@ bool ThreePointStrategy::doProbing(StreamOutput *stream)
         v[i].set(x, y, z);
     }
 
+    // TODO if first point is not within toloerance of of probe height report it.
+
     // define the plane
     delete this->plane;
+    // TODO set a tolerance level here default 0.03mm
     if(v[0][2] == v[1][2] && v[1][2] == v[2][2]) {
         this->plane= nullptr; // plane is flat no need to do anything
         stream->printf("DEBUG: flat plane\n");