Adam Resnick / StepperMotors

Dependents:   CNCAirbrushCode

Committer:
stretch
Date:
Sat Apr 28 21:08:58 2012 +0000
Revision:
0:3058939fa37c
Child:
1:cf60b60a1b5b
Initial Public Release

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 0:3058939fa37c 73
stretch 0:3058939fa37c 74 private:
stretch 0:3058939fa37c 75 void doLinearSideways(Vector delta, Vector nextRow, Stepper ** stepMotor, int maxSpeed, bool solenoidOn);
stretch 0:3058939fa37c 76 void doLinear(Vector delta, Stepper** stepMotor, int maxSpeed, bool solenoidOn);
stretch 0:3058939fa37c 77 void enableSteppers(bool en);
stretch 0:3058939fa37c 78 int delayTime (int oldDelay, int stepNumber);
stretch 0:3058939fa37c 79 Stepper * StepMotor[3];
stretch 0:3058939fa37c 80 DigitalOut * _sol;
stretch 0:3058939fa37c 81 Bitmap _bmp;
stretch 0:3058939fa37c 82 bool reversing;
stretch 0:3058939fa37c 83 volatile bool * _paused;
stretch 0:3058939fa37c 84 volatile bool * _stopped;
stretch 0:3058939fa37c 85 bool _z, _z_slantways;
stretch 0:3058939fa37c 86 };
stretch 0:3058939fa37c 87
stretch 0:3058939fa37c 88 #endif