A simple stepper motor driver library, supporting micro-stepping drivers.

Dependents:   Test_LCDTS_UI_StepperMove

Files at this revision

API Documentation at this revision

Comitter:
Abdel64
Date:
Sat Nov 14 11:44:18 2020 +0000
Parent:
1:d453a05ce39e
Commit message:
Compile OK incl. Table class

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
Table.cpp Show annotated file Show diff for this revision Revisions of this file
Table.h Show annotated file Show diff for this revision Revisions of this file
diff -r d453a05ce39e -r 97b1bc1f0b5f Stepper.cpp
--- a/Stepper.cpp	Wed Nov 11 11:10:28 2020 +0000
+++ b/Stepper.cpp	Sat Nov 14 11:44:18 2020 +0000
@@ -1,5 +1,4 @@
 #include "Stepper.h"
-#include "mbed.h"
 
 stepper::stepper(PinName _en, PinName _stepPin, PinName _dir):
     en(_en),
@@ -12,10 +11,6 @@
     stepper(_en,_stepPin,_dirG),
     dirD(_dirD)
 {}
-
-/*void stepper::move(float pos_current, float pos_togo, float speed)
-{
-    if ( */
     
 void stepper::step(int direction, float speed)
 {
diff -r d453a05ce39e -r 97b1bc1f0b5f Stepper.h
--- a/Stepper.h	Wed Nov 11 11:10:28 2020 +0000
+++ b/Stepper.h	Sat Nov 14 11:44:18 2020 +0000
@@ -1,18 +1,17 @@
 #ifndef MBED_STEPPER_H
 #define MBED_STEPPER_H
-#endif
 
 #include "mbed.h"
 
 class stepper
 {
 public:
+    stepper();
     stepper(PinName _en, PinName _stepPin, PinName _dir);
-    //void move(float pos_current, float pos_togo, float speed);
+    void step (int direction, float speed);
     void enable();
     void disable();
 protected:
-    void step (int direction, float speed);
     DigitalOut en;
     DigitalOut stepPin;
     DigitalOut dir;
@@ -25,4 +24,6 @@
     void step (int direction, float speed);
 protected:
     DigitalOut dirD;
-};
\ No newline at end of file
+};
+
+#endif // DEFINE MBED_STEPPER_H
diff -r d453a05ce39e -r 97b1bc1f0b5f Table.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Table.cpp	Sat Nov 14 11:44:18 2020 +0000
@@ -0,0 +1,28 @@
+#include "Table.h"
+
+table::table(table_pins tablepin):stepper_X(0),steppers_Y(0)
+{  
+   stepper_X = new stepper(tablepin.X_en,tablepin.X_stepPin,tablepin.X_dir);
+   steppers_Y = new steppers(tablepin.Y_en,tablepin.Y_stepPin,tablepin.Y_dirG,tablepin.Y_dirD);
+}
+
+void table::move(position pos_current, position pos_togo, float speed)
+{
+    while (pos_current == pos_togo)
+    {
+        if (pos_current.X > pos_togo.X) {
+            stepper_X->step(1,speed);
+            pos_current.X = pos_current.X - 0.25; 
+        } else if (pos_current.X < pos_togo.X) {
+            stepper_X->step(0,speed);
+            pos_current.X = pos_current.X + 0.25; 
+        }
+        if (pos_current.Y > pos_togo.Y) {
+            steppers_Y->step(1,speed);
+            pos_current.Y = pos_current.Y - 0.25; 
+        } else if (pos_current.Y < pos_togo.Y) {
+            steppers_Y->step(0,speed);
+            pos_current.Y = pos_current.Y + 0.25;
+        }
+    }
+}
\ No newline at end of file
diff -r d453a05ce39e -r 97b1bc1f0b5f Table.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Table.h	Sat Nov 14 11:44:18 2020 +0000
@@ -0,0 +1,36 @@
+#ifndef MBED_TABLE_H
+#define MBED_TABLE_H
+
+#include "Stepper.h"
+
+struct table_pins
+{
+    PinName X_en;
+    PinName X_stepPin;
+    PinName X_dir;
+    PinName Y_en;
+    PinName Y_stepPin;
+    PinName Y_dirG;
+    PinName Y_dirD;
+};
+
+struct position 
+{
+    float X;
+    float Y;
+};
+
+bool operator == (const position &pos1, const position &pos2){ 
+    return (pos1.X == pos2.X) && (pos1.Y == pos2.Y); }
+
+class table
+{
+public:
+    table(table_pins _tablepin) ;
+    void move(position pos_current, position pos_togo, float speed);   
+private:
+    stepper *stepper_X;
+    steppers *steppers_Y;
+};
+
+#endif // MBED_TABLE_H
\ No newline at end of file