Adam Resnick / StepperMotors

Dependents:   CNCAirbrushCode

Files at this revision

API Documentation at this revision

Comitter:
stretch
Date:
Fri May 04 06:25:41 2012 +0000
Parent:
0:3058939fa37c
Commit message:

Changed in this revision

Bitmap.h Show annotated file Show diff for this revision Revisions of this file
LinearMotion.cpp Show annotated file Show diff for this revision Revisions of this file
LinearMotion.h Show annotated file Show diff for this revision Revisions of this file
diff -r 3058939fa37c -r cf60b60a1b5b Bitmap.h
--- a/Bitmap.h	Sat Apr 28 21:08:58 2012 +0000
+++ b/Bitmap.h	Fri May 04 06:25:41 2012 +0000
@@ -34,10 +34,6 @@
 public:
     /**
     * Constructor to deal with bitmap
-    *
-    * @param tx mbed pin to use for tx line of Serial interface
-    * @param rx mbed pin to use for rx line of Serial interface
-    * @param ssid ssid of the adhoc network which will be created
     */
     Bitmap ();
 
diff -r 3058939fa37c -r cf60b60a1b5b LinearMotion.cpp
--- a/LinearMotion.cpp	Sat Apr 28 21:08:58 2012 +0000
+++ b/LinearMotion.cpp	Fri May 04 06:25:41 2012 +0000
@@ -1,8 +1,5 @@
 #include  "LinearMotion.h"
-#define STEPS_PER_PIXEL 600
-#define Z_STEPS_PER_PIXEL 960
-#define STEP_BUFFER 4 // Make a gap of STEPS_PER_PIXEL/STEP_BUFFER  between each pixel
-#define INITIAL_DELAY 1200 // in us
+
 
 void LinearMotion::setStepMotors(Stepper * s1, Stepper * s2, Stepper * s3, DigitalOut * solenoid, bool * pause, bool * stop) {
     _sol = solenoid;
@@ -93,12 +90,12 @@
                      Stepper ** stepMotor, int maxSpeed, bool solenoidOn) {
     int fxy,fxz;
     int rowLoc = 0;
-    int delay = INITIAL_DELAY;
+    int delay = _initial_delay;
     int delayPos = 0;
     Vector lastRow = {-nextRow.x, -nextRow.y, -nextRow.z};
     Vector dir = {1, 1, 1};
     long stepsPerPixel;
-    _z_slantways ? stepsPerPixel = Z_STEPS_PER_PIXEL : stepsPerPixel = STEPS_PER_PIXEL;
+    _z_slantways ? stepsPerPixel = _z_steps_per_pixel : stepsPerPixel = _steps_per_pixel;
     
     if(delta.x < 0)
         dir.x = 0; //towards motor
@@ -160,11 +157,11 @@
 void LinearMotion::doLinear(Vector delta, Stepper** stepMotor, int maxSpeed, bool solenoidOn) {
     int fxy,fxz;
     int pixelLoc = 0;
-    int delay = INITIAL_DELAY;
+    int delay = _initial_delay;
     int farthestDelay = 0;
     Vector dir = {1, 1, 1};
     long stepsPerPixel;
-    _z ? stepsPerPixel = Z_STEPS_PER_PIXEL : stepsPerPixel = STEPS_PER_PIXEL;
+    _z ? stepsPerPixel = _z_steps_per_pixel : stepsPerPixel = _steps_per_pixel;
     
     if(delta.x < 0)
         dir.x = 0; //towards motor
@@ -184,11 +181,11 @@
     curPos.z = 0;
     while (!(*_stopped) && (curPos.x<=delta.x)&&(curPos.y<=delta.y)&&(curPos.z<=delta.z)){
         if (solenoidOn) {
-            if ((reversing && ((delta.x - curPos.x - stepsPerPixel / STEP_BUFFER) % stepsPerPixel == 0)) ||
-               (!reversing && ((curPos.x + stepsPerPixel / STEP_BUFFER) % stepsPerPixel == 0)))
+            if ((reversing && ((delta.x - curPos.x - stepsPerPixel / _step_buffer) % stepsPerPixel == 0)) ||
+               (!reversing && ((curPos.x + stepsPerPixel / _step_buffer) % stepsPerPixel == 0)))
                 *_sol = _bmp.isPixel(pixelLoc++, reversing);
-            else if ((reversing &&  ((delta.x - curPos.x + stepsPerPixel / STEP_BUFFER) % stepsPerPixel == 0)) ||
-                    (!reversing &&  ((curPos.x - stepsPerPixel / STEP_BUFFER) % stepsPerPixel == 0)) )
+            else if ((reversing &&  ((delta.x - curPos.x + stepsPerPixel / _step_buffer) % stepsPerPixel == 0)) ||
+                    (!reversing &&  ((curPos.x - stepsPerPixel / _step_buffer) % stepsPerPixel == 0)) )
                 *_sol = 0;
         }
         ++curPos.x;
@@ -218,11 +215,20 @@
         wait_us(delay);  //Implement linear accelleration!
         if (*_paused) {
             enableSteppers(false);
+            *_sol = 0;
             while(*_paused){printf("Pausing!\n\r");}
             enableSteppers(true);
         }
     }
+    *_sol = 0;
 }
+
+void LinearMotion::updateSettings(long steps_per_pixel, long initial_delay, long step_buffer) {
+    _steps_per_pixel = steps_per_pixel;
+    _z_steps_per_pixel = (steps_per_pixel * 8) / 5;
+    _step_buffer = step_buffer; // Make a gap of _steps_per_pixel/_step_buffer  between each pixel
+    _initial_delay = initial_delay; // in us
+} 
       
 int LinearMotion::delayTime (int oldDelay, int stepNumber) {
     return oldDelay - (2*oldDelay)/(4*stepNumber + 1);
diff -r 3058939fa37c -r cf60b60a1b5b LinearMotion.h
--- a/LinearMotion.h	Sat Apr 28 21:08:58 2012 +0000
+++ b/LinearMotion.h	Fri May 04 06:25:41 2012 +0000
@@ -70,6 +70,14 @@
      * @param bool solenoidOn Whether to have the solenoid on
      */
     void interpolateSquare(Vector basePos, Vector heightPos, int maxSpeed, bool solenoidOn);
+    
+    /** Set various settings for how we do linear motion
+     * 
+     * @param long steps_per_pixel The number of steps to go per pixel
+     * @param long initial_delay The initial speed for linear acceleration
+     * @param long step_buffer steps_per_pixel/step_buffer is the size of the gap on either side of a pixel
+     */
+     void updateSettings(long steps_per_pixel, long initial_delay, long step_buffer);
   
 private:
     void doLinearSideways(Vector delta, Vector nextRow, Stepper ** stepMotor, int maxSpeed, bool solenoidOn);
@@ -83,6 +91,11 @@
     volatile bool * _paused;
     volatile bool * _stopped;
     bool _z, _z_slantways;
+    
+    long _steps_per_pixel;
+    long _z_steps_per_pixel;
+    long _step_buffer; // Make a gap of _steps_per_pixel/_step_buffer  between each pixel
+    long _initial_delay; // in us
 };
  
  #endif
\ No newline at end of file