Libary for Strpper motor controller, eg: Rep-Rap smart stick Catering for both, Phisical 'PIN' endstops, and PORT Expander end stops . ** BOTH IN TEST ** ** Phisical PIN tested (minimal) **** PORT PIN NOT TESTED ****

Files at this revision

API Documentation at this revision

Comitter:
ceri
Date:
Thu Jul 18 09:05:15 2013 +0000
Child:
1:66e95666c3b5
Commit message:
Going to remove all discreet stepper code

Changed in this revision

Stepper.cpp Show annotated file Show diff for this revision Revisions of this file
Stepper.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Stepper.cpp	Thu Jul 18 09:05:15 2013 +0000
@@ -0,0 +1,230 @@
+
+
+
+#include "mbed.h"
+#include "Stepper.h"
+
+
+/* .......................................
+
+    ? Pars Expanded Byte(s)
+    
+    Assuming Port expander is used;
+    
+    then on ISR, read chip registors ..
+    -> code -> 
+  ........................................  */
+
+
+
+Stepper::Stepper(PinName Step, PinName Dir, PinName En, 
+                 PinName Endstop_Left, 
+                 PinName Endstop_Right, 
+                 
+                 bool Invert_Dir, 
+                 bool Invert_ESL, 
+                 bool Invert_ESR)
+
+
+            : _Step (Step),  _Dir(Dir), _En(En), _Endstop_Left(Endstop_Left), _Endstop_Right(Endstop_Right)
+{            
+
+                // Assume End Stop Left is MIN,
+                // and End Stop Right is MAX endstop.
+                
+                 _Invert_Dir = Invert_Dir, 
+                 _Invert_ESL = Invert_ESL, 
+                 _Invert_ESR = Invert_ESR;            
+           
+    {
+    //  bool read_1();
+        if (Endstop_Left   != NC) ESL = true; else ESL = false;
+        if (Endstop_Right  != NC) ESR = true; else ESR = false;
+    
+    } 
+}  
+
+// ------------------------------------------------------------------------------------
+
+
+bool Stepper::Pulse()
+{
+//    if (Step == NC)
+//    {
+//        return false;
+//    }
+//    else
+        // Enable motor .. if not enabled .. short delay befor moveing ..
+        
+        if (!_En) 
+        {
+            _En = 1;
+            wait (0.005);   // 5 mSec.
+        }
+        
+        _En = 1;
+        
+        
+        {
+            _Step = 1;
+            wait_us (2);
+            _Step = 0;
+            return true;
+        }
+}
+
+// ------------------------------------------------------------------------------------
+
+bool Stepper::Set_Dir (bool Dir2Set)
+{
+//    if (Dir == NC)
+//    {
+//        return false;
+//    }
+//    else
+    {
+        if (Dir2Set)
+        {
+            _Invert_Dir ? _Dir = 0 : _Dir = 1;
+        }
+        else
+        {
+            _Invert_Dir ? _Dir = 1 : _Dir = 0;
+        }
+        
+        return true;
+    }
+}
+
+
+// ------------------------------------------------------------------------------------
+
+// test if ENDSTOP is enabled ....  _Endstop_Left
+
+bool Stepper::ESL_Fitted()
+{
+//    (ESL) ? return true : return false;
+    if (ESL) 
+    return true;
+    else
+    return false;
+}
+
+//
+
+bool Stepper::ESR_Fitted()
+{
+    //ESR ? return true : return false;
+    if (ESR)
+    return true;
+    else
+    return false;
+}
+
+// ...............................................................................
+
+bool Stepper::ESL_Activeated()
+{
+    bool retval;
+    
+    if (_Invert_ESL)
+    {
+        if (_Endstop_Left)  retval = true; else retval = false;
+    }
+    else
+    {
+        if (_Endstop_Left)  retval = false; else retval = true; // 
+    }
+    
+    if (retval)
+    {
+        StepCount = 0;  // might be very bad for H-BOT
+    }
+     
+    return retval;
+}
+
+//
+
+bool Stepper::ESR_Activeated()
+{
+    if (_Invert_ESR)
+    {
+        if(_Endstop_Right) return true; else return false;
+    }
+    else
+    {
+        if(_Endstop_Right) return false; else return true;
+    }
+}
+// ------------------------------------------------------------------------------------
+
+// test if endstop is triggerd.
+// ** will return false if not triggerd AND false if pin is NC
+// ** user should test if connected befor in a nested routeen from MAIN !!
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+/*  **********************************************************************
+
+**
+*   `   want an entity for a SINGLE Stepper motor, and assosiated things ..
+
+        PINS:
+            step,
+            Direction,
+            Enable,
+            
+            endstop_left
+            endstop_right
+            
+            Direction_Invert (T/F)
+            
+        calls:
+            step
+            Endstop_Detected           
+**
+*
+*
+        Vars:
+            Number of steps to take
+*
+*
+**
+*       also need to be able to tell if endstops are defined
+*
+*
+
+    if (ESR  != NC) ESR_En = true; else ESR_En = false; // 44;
+    
+    // got 340 with g1 defined ..
+    // got 44 with NO define :)
+
+***************************
+
+        if (Endstop_Right_Enabled)
+        {
+        
+        }
+        else
+        {
+        
+        }
+
+* ********************************************************************* */
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Stepper.h	Thu Jul 18 09:05:15 2013 +0000
@@ -0,0 +1,44 @@
+
+
+#ifndef _stepper_h_
+#define _stepper_h_
+
+#include "mbed.h"
+
+class Stepper {
+
+public:
+
+    Stepper(PinName Step, PinName Dir, PinName En, PinName Endstop_Left, PinName Endstop_Right, bool Invert_Dir, bool Invert_ESL, bool Invert_ESR);
+    
+    bool Pulse();
+    bool Set_Dir (bool Dir2Set);
+    bool ESL_Activeated();
+    bool ESR_Activeated();
+    bool ESL_Fitted();
+    bool ESR_Fitted();
+
+protected:
+    DigitalOut  _Step;    
+    DigitalOut  _Dir;
+    DigitalOut  _En;
+    
+    DigitalIn _Endstop_Left;    
+    DigitalIn _Endstop_Right;
+    
+    
+    bool _Invert_Dir;
+    bool _Invert_ESL;
+    bool _Invert_ESR;
+    bool _g4;
+    
+    bool ESL; 
+    
+private:
+       
+    int ESR; 
+    int Set; 
+    
+    };
+
+#endif // _stepper_h_
\ No newline at end of file