wheee, basic homing
authorArthur Wolf <wolf.arthur@gmail.com>
Sun, 8 Jul 2012 21:22:21 +0000 (23:22 +0200)
committerArthur Wolf <wolf.arthur@gmail.com>
Sun, 8 Jul 2012 21:22:21 +0000 (23:22 +0200)
src/libs/ConfigSources/FileConfigSource.cpp
src/libs/Pin.h
src/modules/tools/endstops/Endstops.cpp
src/modules/tools/endstops/Endstops.h

index 8807a2d..e67771e 100644 (file)
@@ -42,7 +42,12 @@ void FileConfigSource::transfer_values_to_cache( ConfigCache* cache ){
             size_t begin_value = buffer.find_first_not_of(" ", buffer.find_first_of(" ", begin_key));
             string key = buffer.substr(begin_key,  buffer.find_first_of(" ", begin_key) - begin_key).append(" ");
             vector<uint16_t> check_sums = get_checksums(key);
-            
+           
+            //for( uint16_t i = 0; i < check_sums.size(); i++ ){
+            //    printf("%u ", check_sums.at(i));
+            //}
+            //printf("\r\n");
+
             result = new ConfigValue;
             result->found = true;
             result->check_sums = check_sums;
index 5d133d9..cb845e9 100644 (file)
@@ -13,19 +13,31 @@ class Pin{
 
         Pin* from_string(std::string value){
             LPC_GPIO_TypeDef* gpios[5] ={LPC_GPIO0,LPC_GPIO1,LPC_GPIO2,LPC_GPIO3,LPC_GPIO4};
-            this->port_number =  atoi(value.substr(0,1).c_str());  
-            this->port = gpios[this->port_number]; 
-            this->inverting = ( value.find_first_of("!")!=string::npos ? true : false );
-            this->pin  = atoi( value.substr(2, value.size()-2-(this->inverting?1:0)).c_str() );
+            if( value.find_first_of("n")!=string::npos ? true : false ){
+                this->port_number = 0;  
+                this->port = gpios[this->port_number]; 
+                this->inverting = false;
+                this->pin = 255;;
+            }else{
+                this->port_number =  atoi(value.substr(0,1).c_str());  
+                this->port = gpios[this->port_number]; 
+                this->inverting = ( value.find_first_of("!")!=string::npos ? true : false );
+                this->pin  = atoi( value.substr(2, value.size()-2-(this->inverting?1:0)).c_str() );
+            } 
             return this;
         }
 
-        inline Pin*  as_output(){
+        inline bool connected(){
+            if( this->pin == 255 ){ return false; }
+            return true;
+        }
+
+        inline Pin* as_output(){
             this->port->FIODIR |= 1<<this->pin;
             return this;
         }  
 
-        inline Pin*  as_input(){
+        inline Pin* as_input(){
             this->port->FIODIR &= ~(1<<this->pin);
             return this;
         }  
index 84c4b3a..076ff5e 100644 (file)
@@ -11,6 +11,7 @@
 #include "modules/robot/Player.h"
 #include "Endstops.h"
 #include "libs/nuts_bolts.h"
+#include "libs/Pin.h"
 #include "libs/StepperMotor.h"
 #include "wait_api.h" // mbed.h lib
 
@@ -26,8 +27,17 @@ void Endstops::on_module_loaded() {
     this->steppers[1] = this->kernel->robot->beta_stepper_motor;
     this->steppers[2] = this->kernel->robot->gamma_stepper_motor;
 
+    // Settings
+    this->on_config_reload(this);
+    
 }
 
+// Get config
+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();
+}
 
 // Start homing sequences by response to GCode commands
 void Endstops::on_gcode_received(void* argument){
@@ -46,13 +56,30 @@ void Endstops::on_gcode_received(void* argument){
             // Start moving the axes to the origin
             this->status = MOVING_TO_ORIGIN_FAST; 
             for( char c = 'X'; c <= 'Z'; c++ ){
-                if( home_all_axes || gcode->has_letter(c) ){
+                if( ( home_all_axes || gcode->has_letter(c) ) && this->pins[c - 'X']->connected() ){
                     this->steppers[c - 'X']->move(0,10000000); 
-                    this->steppers[c - 'X']->set_speed(1); 
+                    this->steppers[c - 'X']->set_speed(10000); 
                 }
             }
 
             // Wait for all axes to have homed
+            bool running = true;
+            while(running){
+                running = false; 
+                for( char c = 'X'; c <= 'Z'; c++ ){
+                    if( ( home_all_axes || gcode->has_letter(c) ) && this->pins[c - 'X']->connected() ){
+                         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;
+                         }
+                    }
+                }
+            }
 
 
 
index 9fb10e6..cf364e4 100644 (file)
@@ -12,6 +12,7 @@
 #include "libs/Kernel.h"
 #include "modules/communication/utils/Gcode.h"
 #include "libs/StepperMotor.h"
+#include "libs/Pin.h"
 
 #define ALPHA_AXIS 0
 #define BETA_AXIS  1
 #define NOT_HOMING 0
 #define MOVING_TO_ORIGIN_FAST 1
 
+#define alpha_min_endstop_checksum       28684 
+#define beta_min_endstop_checksum        23457  
+#define gamma_min_endstop_checksum       16137 
+
 class Endstops : public Module{
     public:
         Endstops();
         void on_module_loaded();
         void on_gcode_received(void* argument);
+        void on_config_reload(void* argument);
 
         StepperMotor* steppers[3];
+        Pin*          pins[3];
+        char status;
 };