added homing options
authorArthur Wolf <wolf.arthur@gmail.com>
Fri, 9 Nov 2012 18:56:00 +0000 (19:56 +0100)
committerArthur Wolf <wolf.arthur@gmail.com>
Fri, 9 Nov 2012 18:56:00 +0000 (19:56 +0100)
src/modules/tools/endstops/Endstops.cpp
src/modules/tools/endstops/Endstops.h

index ce3aa83..4d4b355 100644 (file)
@@ -37,6 +37,15 @@ void Endstops::on_config_reload(void* argument){
     this->pins[0]                    = this->kernel->config->value(alpha_min_endstop_checksum          )->by_default("nc" )->as_pin()->as_input();
     this->pins[1]                    = this->kernel->config->value(beta_min_endstop_checksum           )->by_default("nc" )->as_pin()->as_input();
     this->pins[2]                    = this->kernel->config->value(gamma_min_endstop_checksum          )->by_default("nc" )->as_pin()->as_input();
+    this->fast_rates[0]              = this->kernel->config->value(alpha_fast_homing_rate_checksum     )->by_default("100" )->as_number();
+    this->fast_rates[1]              = this->kernel->config->value(beta_fast_homing_rate_checksum      )->by_default("100" )->as_number();
+    this->fast_rates[2]              = this->kernel->config->value(gamma_fast_homing_rate_checksum     )->by_default("100" )->as_number();
+    this->slow_rates[0]              = this->kernel->config->value(alpha_slow_homing_rate_checksum     )->by_default("10" )->as_number();
+    this->slow_rates[1]              = this->kernel->config->value(beta_slow_homing_rate_checksum      )->by_default("10" )->as_number();
+    this->slow_rates[2]              = this->kernel->config->value(gamma_slow_homing_rate_checksum     )->by_default("10" )->as_number();
+    this->retract_steps[0]           = this->kernel->config->value(alpha_homing_retract_checksum       )->by_default("10" )->as_number();
+    this->retract_steps[1]           = this->kernel->config->value(beta_homing_retract_checksum        )->by_default("10" )->as_number();
+    this->retract_steps[2]           = this->kernel->config->value(gamma_homing_retract_checksum       )->by_default("10" )->as_number();
 }
 
 // Start homing sequences by response to GCode commands
@@ -60,7 +69,7 @@ void Endstops::on_gcode_received(void* argument){
             for( char c = 'X'; c <= 'Z'; c++ ){
                 if( ( axes_to_move >> ( c - 'X' ) ) & 1 ){
                     this->steppers[c - 'X']->move(0,10000000); 
-                    this->steppers[c - 'X']->set_speed(10000); 
+                    this->steppers[c - 'X']->set_speed(this->fast_rates[c -'X']); 
                 }
             }
 
@@ -89,8 +98,8 @@ void Endstops::on_gcode_received(void* argument){
             this->status = MOVING_BACK; 
             for( char c = 'X'; c <= 'Z'; c++ ){
                 if( ( axes_to_move >> ( c - 'X' ) ) & 1 ){
-                    this->steppers[c - 'X']->move(1,1000); 
-                    this->steppers[c - 'X']->set_speed(1000); 
+                    this->steppers[c - 'X']->move(1,this->retract_steps[c - 'X']); 
+                    this->steppers[c - 'X']->set_speed(this->slow_rates[c - 'X']); 
                 }
             }
 
@@ -105,6 +114,35 @@ void Endstops::on_gcode_received(void* argument){
 
             printf("test c\r\n");
 
+            // Start moving the axes to the origin slowly
+            this->status = MOVING_TO_ORIGIN_SLOW; 
+            for( char c = 'X'; c <= 'Z'; c++ ){
+                if( ( axes_to_move >> ( c - 'X' ) ) & 1 ){
+                    this->steppers[c - 'X']->move(0,10000000); 
+                    this->steppers[c - 'X']->set_speed(this->slow_rates[c -'X']); 
+                }
+            }
+
+            // Wait for all axes to have homed
+            running = true;
+            while(running){
+                running = false; 
+                for( char c = 'X'; c <= 'Z'; c++ ){
+                    if( ( axes_to_move >> ( c - 'X' ) ) & 1 ){
+                         if( this->pins[c - 'X']->get() ){
+                            // The endstop was hit, stop moving
+                            if( this->steppers[c - 'X']->moving ){ 
+                                this->steppers[c - 'X']->move(0,0); 
+                            }  
+                        }else{
+                            // The endstop was not hit yet
+                            running = true;
+                         }
+                    }
+                }
+            }
+
+
             // Homing is done
             this->status = NOT_HOMING;
         
index ca84711..0e37095 100644 (file)
 #define NOT_HOMING 0
 #define MOVING_TO_ORIGIN_FAST 1
 #define MOVING_BACK 2
+#define MOVING_TO_ORIGIN_SLOW 3
 
 #define alpha_min_endstop_checksum       28684 
 #define beta_min_endstop_checksum        23457  
 #define gamma_min_endstop_checksum       16137 
+#define alpha_fast_homing_rate_checksum  19720 
+#define beta_fast_homing_rate_checksum   9373
+#define gamma_fast_homing_rate_checksum  3333  
+#define alpha_slow_homing_rate_checksum  45599  
+#define beta_slow_homing_rate_checksum   35252 
+#define gamma_slow_homing_rate_checksum  29212
+#define alpha_homing_retract_checksum    4419
+#define beta_homing_retract_checksum     48344 
+#define gamma_homing_retract_checksum    54848
+
 
 class Endstops : public Module{
     public:
@@ -35,6 +46,9 @@ class Endstops : public Module{
 
         StepperMotor* steppers[3];
         Pin*          pins[3];
+        unsigned int  slow_rates[3];
+        unsigned int  fast_rates[3];
+        unsigned int  retract_steps[3];
         char status;
 };