Adam Resnick / StepperMotors

Dependents:   CNCAirbrushCode

Committer:
stretch
Date:
Fri May 04 06:25:41 2012 +0000
Revision:
1:cf60b60a1b5b
Parent:
0:3058939fa37c

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
stretch 0:3058939fa37c 1 /* mbed Stepper Library
stretch 0:3058939fa37c 2 * Copyright (c) 2012 Steven Rhodes
stretch 0:3058939fa37c 3 *
stretch 0:3058939fa37c 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
stretch 0:3058939fa37c 5 * of this software and associated documentation files (the "Software"), to deal
stretch 0:3058939fa37c 6 * in the Software without restriction, including without limitation the rights
stretch 0:3058939fa37c 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
stretch 0:3058939fa37c 8 * copies of the Software, and to permit persons to whom the Software is
stretch 0:3058939fa37c 9 * furnished to do so, subject to the following conditions:
stretch 0:3058939fa37c 10 *
stretch 0:3058939fa37c 11 * The above copyright notice and this permission notice shall be included in
stretch 0:3058939fa37c 12 * all copies or substantial portions of the Software.
stretch 0:3058939fa37c 13 *
stretch 0:3058939fa37c 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
stretch 0:3058939fa37c 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
stretch 0:3058939fa37c 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
stretch 0:3058939fa37c 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
stretch 0:3058939fa37c 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
stretch 0:3058939fa37c 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
stretch 0:3058939fa37c 20 * THE SOFTWARE.
stretch 0:3058939fa37c 21 */
stretch 0:3058939fa37c 22
stretch 0:3058939fa37c 23 #ifndef LINEARMOTION_H
stretch 0:3058939fa37c 24 #define LINEARMOTION_H
stretch 0:3058939fa37c 25
stretch 0:3058939fa37c 26 #include "mbed.h"
stretch 0:3058939fa37c 27 #include "Stepper.h"
stretch 0:3058939fa37c 28 #include "Bitmap.h"
stretch 0:3058939fa37c 29
stretch 0:3058939fa37c 30 typedef struct {
stretch 0:3058939fa37c 31 long x;
stretch 0:3058939fa37c 32 long y;
stretch 0:3058939fa37c 33 long z;
stretch 0:3058939fa37c 34 } Vector;
stretch 0:3058939fa37c 35
stretch 0:3058939fa37c 36 typedef struct {
stretch 0:3058939fa37c 37 Vector one;
stretch 0:3058939fa37c 38 Vector two;
stretch 0:3058939fa37c 39 } TwoVectors;
stretch 0:3058939fa37c 40
stretch 0:3058939fa37c 41 class LinearMotion {
stretch 0:3058939fa37c 42
stretch 0:3058939fa37c 43 public:
stretch 0:3058939fa37c 44
stretch 0:3058939fa37c 45 /** Interpolate to point specified by the vector (relative to current position)
stretch 0:3058939fa37c 46 *
stretch 0:3058939fa37c 47 * @param Stepper * s1 The x stepper motor
stretch 0:3058939fa37c 48 * @param Stepper * s2 The y stepper motor
stretch 0:3058939fa37c 49 * @param Stepper * s3 The z stepper motor
stretch 0:3058939fa37c 50 * @param DigitalOut * solenoid The solenoid
stretch 0:3058939fa37c 51 * @param bool * pause The variable for pausing
stretch 0:3058939fa37c 52 * @param bool * stop The variable for stopping
stretch 0:3058939fa37c 53 */
stretch 0:3058939fa37c 54 void setStepMotors(Stepper * s1, Stepper * s2, Stepper * s3, DigitalOut * solenoid, bool * pause, bool * stop);
stretch 0:3058939fa37c 55
stretch 0:3058939fa37c 56 /** Interpolate to point specified by the vector (relative to current position)
stretch 0:3058939fa37c 57 *
stretch 0:3058939fa37c 58 * @param Vector length The vector specifying where to go
stretch 0:3058939fa37c 59 * @param int maxSpeed Max speed used to get to position
stretch 0:3058939fa37c 60 * @param bool solenoidOn Whether to have the solenoid on
stretch 0:3058939fa37c 61 */
stretch 0:3058939fa37c 62 void interpolate(Vector length, int maxSpeed, bool solenoidOn);
stretch 0:3058939fa37c 63 void interpolate(Vector length, int maxSpeed);
stretch 0:3058939fa37c 64
stretch 0:3058939fa37c 65 /** Interpolate to square specified by the vector (relative to current position)
stretch 0:3058939fa37c 66 *
stretch 0:3058939fa37c 67 * @param Vector basePos Position defining the base of the square
stretch 0:3058939fa37c 68 * @param Vector heightPos Position defining the height of the square
stretch 0:3058939fa37c 69 * @param int maxSpeed Max speed used to get to position
stretch 0:3058939fa37c 70 * @param bool solenoidOn Whether to have the solenoid on
stretch 0:3058939fa37c 71 */
stretch 0:3058939fa37c 72 void interpolateSquare(Vector basePos, Vector heightPos, int maxSpeed, bool solenoidOn);
stretch 1:cf60b60a1b5b 73
stretch 1:cf60b60a1b5b 74 /** Set various settings for how we do linear motion
stretch 1:cf60b60a1b5b 75 *
stretch 1:cf60b60a1b5b 76 * @param long steps_per_pixel The number of steps to go per pixel
stretch 1:cf60b60a1b5b 77 * @param long initial_delay The initial speed for linear acceleration
stretch 1:cf60b60a1b5b 78 * @param long step_buffer steps_per_pixel/step_buffer is the size of the gap on either side of a pixel
stretch 1:cf60b60a1b5b 79 */
stretch 1:cf60b60a1b5b 80 void updateSettings(long steps_per_pixel, long initial_delay, long step_buffer);
stretch 0:3058939fa37c 81
stretch 0:3058939fa37c 82 private:
stretch 0:3058939fa37c 83 void doLinearSideways(Vector delta, Vector nextRow, Stepper ** stepMotor, int maxSpeed, bool solenoidOn);
stretch 0:3058939fa37c 84 void doLinear(Vector delta, Stepper** stepMotor, int maxSpeed, bool solenoidOn);
stretch 0:3058939fa37c 85 void enableSteppers(bool en);
stretch 0:3058939fa37c 86 int delayTime (int oldDelay, int stepNumber);
stretch 0:3058939fa37c 87 Stepper * StepMotor[3];
stretch 0:3058939fa37c 88 DigitalOut * _sol;
stretch 0:3058939fa37c 89 Bitmap _bmp;
stretch 0:3058939fa37c 90 bool reversing;
stretch 0:3058939fa37c 91 volatile bool * _paused;
stretch 0:3058939fa37c 92 volatile bool * _stopped;
stretch 0:3058939fa37c 93 bool _z, _z_slantways;
stretch 1:cf60b60a1b5b 94
stretch 1:cf60b60a1b5b 95 long _steps_per_pixel;
stretch 1:cf60b60a1b5b 96 long _z_steps_per_pixel;
stretch 1:cf60b60a1b5b 97 long _step_buffer; // Make a gap of _steps_per_pixel/_step_buffer between each pixel
stretch 1:cf60b60a1b5b 98 long _initial_delay; // in us
stretch 0:3058939fa37c 99 };
stretch 0:3058939fa37c 100
stretch 0:3058939fa37c 101 #endif