debounce is now debounce_ms and the old debounce_count is ignored for zprobe but...
authorJim Morris <morris@wolfman.com>
Sat, 18 Jun 2016 01:08:23 +0000 (18:08 -0700)
committerJim Morris <morris@wolfman.com>
Sat, 18 Jun 2016 01:08:23 +0000 (18:08 -0700)
  as the switches are now polled every millisecond that is usually enough for a debounce, so is set to 0 by default, but if set should be in ms and far less than it used to be

src/modules/tools/endstops/Endstops.cpp
src/modules/tools/endstops/Endstops.h
src/modules/tools/zprobe/ZProbe.cpp
src/modules/tools/zprobe/ZProbe.h

index ee38233..ff102e9 100644 (file)
@@ -84,6 +84,7 @@
 #define gamma_homing_retract_mm_checksum    CHECKSUM("gamma_homing_retract_mm")
 
 #define endstop_debounce_count_checksum  CHECKSUM("endstop_debounce_count")
+#define endstop_debounce_ms_checksum     CHECKSUM("endstop_debounce_ms")
 
 #define alpha_homing_direction_checksum  CHECKSUM("alpha_homing_direction")
 #define beta_homing_direction_checksum   CHECKSUM("beta_homing_direction")
@@ -177,6 +178,8 @@ void Endstops::load_config()
     this->retract_mm[1] = THEKERNEL->config->value(beta_homing_retract_mm_checksum    )->by_default(this->retract_mm[1])->as_number();
     this->retract_mm[2] = THEKERNEL->config->value(gamma_homing_retract_mm_checksum   )->by_default(this->retract_mm[2])->as_number();
 
+    // NOTE the debouce count is in milliseconds so probably does not need to beset anymore
+    this->debounce_ms     = THEKERNEL->config->value(endstop_debounce_ms_checksum       )->by_default(0)->as_number();
     this->debounce_count  = THEKERNEL->config->value(endstop_debounce_count_checksum    )->by_default(100)->as_number();
 
     // get homing direction and convert to boolean where true is home to min, and false is home to max
@@ -395,7 +398,7 @@ uint32_t Endstops::read_endstops(uint32_t dummy)
             if(STEPPER[m]->is_moving()) {
                 // if it is moving then we check the associated endstop, and debounce it
                 if(this->pins[m + (this->home_direction[m] ? 0 : 3)].get()) {
-                    if(debounce[m] < debounce_count) {
+                    if(debounce[m] < debounce_ms) {
                         debounce[m]++;
                     } else {
                         // we signal the motor to stop, which will preempt any moves on that axis
@@ -415,7 +418,7 @@ uint32_t Endstops::read_endstops(uint32_t dummy)
         for ( int m = X_AXIS; m <= Z_AXIS; m++ ) {
             if(axis_to_home[m]) {
                 if(this->pins[m + (this->home_direction[m] ? 0 : 3)].get()) {
-                    if(debounce[m] < debounce_count) {
+                    if(debounce[m] < debounce_ms) {
                         debounce[m]++;
                     } else {
                         // we signal all the motors to stop, as on corexy X and Y motors will move for X and Y axis homing and we only hom eone axis at a time
@@ -448,7 +451,7 @@ void Endstops::home(std::bitset<3> a)
     THEROBOT->disable_segmentation= true; // we must disable segmentation as this won't work with it enabled
     if(axis_to_home[X_AXIS] && axis_to_home[Y_AXIS]) {
         // Home XY first so as not to slow them down by homing Z at the same time
-        float delta[3] {alpha_max, beta_max, 0};
+        float delta[3] {alpha_max*2, beta_max*2, 0};
         if(this->home_direction[X_AXIS]) delta[X_AXIS]= -delta[X_AXIS];
         if(this->home_direction[Y_AXIS]) delta[Y_AXIS]= -delta[Y_AXIS];
         float feed_rate = std::min(fast_rates[X_AXIS], fast_rates[Y_AXIS]);
@@ -459,7 +462,7 @@ void Endstops::home(std::bitset<3> a)
 
     } else if(axis_to_home[X_AXIS]) {
         // now home X only
-        float delta[3] {alpha_max, 0, 0};
+        float delta[3] {alpha_max*2, 0, 0};
         if(this->home_direction[X_AXIS]) delta[X_AXIS]= -delta[X_AXIS];
         THEROBOT->solo_move(delta, fast_rates[X_AXIS]);
         // wait for X
@@ -467,7 +470,7 @@ void Endstops::home(std::bitset<3> a)
 
     } else if(axis_to_home[Y_AXIS]) {
         // now home Y only
-        float delta[3] {0, beta_max, 0};
+        float delta[3] {0, beta_max*2, 0};
         if(this->home_direction[Y_AXIS]) delta[Y_AXIS]= -delta[Y_AXIS];
         THEROBOT->solo_move(delta, fast_rates[Y_AXIS]);
         // wait for Y
@@ -476,7 +479,7 @@ void Endstops::home(std::bitset<3> a)
 
     if(axis_to_home[Z_AXIS]) {
         // now home z
-        float delta[3] {0, 0, gamma_max};
+        float delta[3] {0, 0, gamma_max*2}; // we go twice the maxz just in case it was set incorrectly
         if(this->home_direction[Z_AXIS]) delta[Z_AXIS]= -delta[Z_AXIS];
         THEROBOT->solo_move(delta, fast_rates[Z_AXIS]);
         // wait for Z
index c7f23d4..9ab7a8f 100644 (file)
@@ -40,7 +40,8 @@ class Endstops : public Module{
         float saved_position[3]{0}; // save G28 (in grbl mode)
         float alpha_max, beta_max, gamma_max;
 
-        unsigned int  debounce_count;
+        uint32_t debounce_count;
+        uint32_t  debounce_ms;
         float  retract_mm[3];
         float  trim_mm[3];
         float  fast_rates[3];
index b79ec84..01f84b7 100644 (file)
@@ -35,7 +35,7 @@
 
 #define enable_checksum          CHECKSUM("enable")
 #define probe_pin_checksum       CHECKSUM("probe_pin")
-#define debounce_count_checksum  CHECKSUM("debounce_count")
+#define debounce_ms_checksum     CHECKSUM("debounce_ms")
 #define slow_feedrate_checksum   CHECKSUM("slow_feedrate")
 #define fast_feedrate_checksum   CHECKSUM("fast_feedrate")
 #define return_feedrate_checksum CHECKSUM("return_feedrate")
@@ -79,7 +79,7 @@ void ZProbe::on_module_loaded()
 void ZProbe::config_load(void *argument)
 {
     this->pin.from_string( THEKERNEL->config->value(zprobe_checksum, probe_pin_checksum)->by_default("nc" )->as_string())->as_input();
-    this->debounce_count = THEKERNEL->config->value(zprobe_checksum, debounce_count_checksum)->by_default(0  )->as_number();
+    this->debounce_ms    = THEKERNEL->config->value(zprobe_checksum, debounce_ms_checksum)->by_default(0  )->as_number();
 
     // get strategies to load
     vector<uint16_t> modules;
@@ -142,7 +142,7 @@ uint32_t ZProbe::read_probe(uint32_t dummy)
     if(STEPPER[Z_AXIS]->is_moving()) {
         // if it is moving then we check the probe, and debounce it
         if(this->pin.get()) {
-            if(debounce < debounce_count) {
+            if(debounce < debounce_ms) {
                 debounce++;
             } else {
                 // we signal the motors to stop, which will preempt any moves on that axis
@@ -179,13 +179,15 @@ bool ZProbe::run_probe(float& mm, float feedrate, float max_dist, bool reverse)
     };
 
     // move Z down
+    THEROBOT->disable_segmentation= true; // we must disable segmentation as this won't work with it enabled
     bool dir= (!reverse_z != reverse); // xor
     float delta[3]= {0,0,0};
-    delta[Z_AXIS]= dir ? maxz : -maxz;
+    delta[Z_AXIS]= dir ? -maxz : maxz;
     THEROBOT->solo_move(delta, feedrate);
 
     // wait until finished
     THECONVEYOR->wait_for_empty_queue();
+    THEROBOT->disable_segmentation= false;
 
     // now see how far we moved, get delta in z we moved
     mm= start_pos[2] - THEROBOT->actuators[2]->get_current_position();
@@ -198,6 +200,12 @@ bool ZProbe::run_probe(float& mm, float feedrate, float max_dist, bool reverse)
             mm,
             probe_detected?1:0));
 
+    probing= false;
+
+    if(probe_detected) {
+        // if the probe stopped the move we need to correct the last_milestone as it did not reach where it thought
+        THEROBOT->reset_position_from_current_actuator_position();
+    }
 
     return probe_detected;
 }
@@ -217,7 +225,7 @@ bool ZProbe::return_probe(float mm, bool reverse)
     if(reverse) dir= !dir;
 
     float delta[3]= {0,0,0};
-    delta[Z_AXIS]= dir ? mm : -mm;
+    delta[Z_AXIS]= dir ? -mm : mm;
     THEROBOT->solo_move(delta, fr);
 
     // wait until finished
@@ -267,10 +275,10 @@ void ZProbe::on_gcode_received(void *argument)
             // first wait for an empty queue i.e. no moves left
             THEKERNEL->conveyor->wait_for_empty_queue();
 
-            float mm;
             bool probe_result;
             bool reverse= (gcode->has_letter('R') && gcode->get_value('R') != 0); // specify to probe in reverse direction
             float rate= gcode->has_letter('F') ? gcode->get_value('F') / 60 : this->slow_feedrate;
+            float mm;
             probe_result = run_probe(mm, rate, -1, reverse);
 
             if(probe_result) {
index 28903d1..8f2a9ba 100644 (file)
@@ -60,7 +60,7 @@ private:
 
     Pin pin;
     std::vector<LevelingStrategy*> strategies;
-    uint16_t debounce_count, debounce;
+    uint16_t debounce_ms, debounce;
 
     volatile struct {
         bool is_delta:1;