David Vasquez
/
R5_StepperDrive
3-26-2015 DSV
Fork of R5_StepperDrive by
StepperDrive.h@0:266a770a17e9, 2015-11-22 (annotated)
- Committer:
- jmar11
- Date:
- Sun Nov 22 19:27:47 2015 +0000
- Revision:
- 0:266a770a17e9
- Child:
- 1:909572175aad
First. Library to control drive stepper motors for TX state IEEE team 1.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jmar11 | 0:266a770a17e9 | 1 | #ifndef _STEPPER_DRIVE_ |
jmar11 | 0:266a770a17e9 | 2 | #define _STEPPER_DRIVE_ |
jmar11 | 0:266a770a17e9 | 3 | |
jmar11 | 0:266a770a17e9 | 4 | #include "mbed.h" |
jmar11 | 0:266a770a17e9 | 5 | |
jmar11 | 0:266a770a17e9 | 6 | #define Ustep 16 //microstepping setup: 1, 2, 4, 8, or 16 |
jmar11 | 0:266a770a17e9 | 7 | |
jmar11 | 0:266a770a17e9 | 8 | class StepperDrive{ |
jmar11 | 0:266a770a17e9 | 9 | public: |
jmar11 | 0:266a770a17e9 | 10 | StepperDrive(PinName in1, PinName in2, bool in3, PinName in4, PinName in5, bool in6, float in7, float in8, float in9 = 1000); |
jmar11 | 0:266a770a17e9 | 11 | //(stepPinLeft, dirPinLeft, invertLeft, stepPinRight, dirPinRight, invertRight, wheelCircum, wheelSepar, periodUs) |
jmar11 | 0:266a770a17e9 | 12 | int move(float distance, float angle); |
jmar11 | 0:266a770a17e9 | 13 | bool isMoveDone(); |
jmar11 | 0:266a770a17e9 | 14 | |
jmar11 | 0:266a770a17e9 | 15 | private: |
jmar11 | 0:266a770a17e9 | 16 | Ticker pit; //periodic interrupt timer |
jmar11 | 0:266a770a17e9 | 17 | |
jmar11 | 0:266a770a17e9 | 18 | void pitCallback(); |
jmar11 | 0:266a770a17e9 | 19 | |
jmar11 | 0:266a770a17e9 | 20 | void stepRight(bool dir); |
jmar11 | 0:266a770a17e9 | 21 | void stepLeft(bool dir); |
jmar11 | 0:266a770a17e9 | 22 | |
jmar11 | 0:266a770a17e9 | 23 | DigitalOut leftStep; |
jmar11 | 0:266a770a17e9 | 24 | DigitalOut leftDir; |
jmar11 | 0:266a770a17e9 | 25 | DigitalOut rightStep; |
jmar11 | 0:266a770a17e9 | 26 | DigitalOut rightDir; |
jmar11 | 0:266a770a17e9 | 27 | |
jmar11 | 0:266a770a17e9 | 28 | float wheelCircum; //wheel circumference |
jmar11 | 0:266a770a17e9 | 29 | float wheelSepar; //distance between wheels |
jmar11 | 0:266a770a17e9 | 30 | bool invertLeft; //software wheel direction inversion |
jmar11 | 0:266a770a17e9 | 31 | bool invertRight; //software wheel direction inversion |
jmar11 | 0:266a770a17e9 | 32 | bool moveComplete; |
jmar11 | 0:266a770a17e9 | 33 | |
jmar11 | 0:266a770a17e9 | 34 | int leftSteps; |
jmar11 | 0:266a770a17e9 | 35 | int rightSteps; |
jmar11 | 0:266a770a17e9 | 36 | float leftStepsPC; |
jmar11 | 0:266a770a17e9 | 37 | float rightStepsPC; |
jmar11 | 0:266a770a17e9 | 38 | float leftError; |
jmar11 | 0:266a770a17e9 | 39 | float rightError; |
jmar11 | 0:266a770a17e9 | 40 | }; |
jmar11 | 0:266a770a17e9 | 41 | |
jmar11 | 0:266a770a17e9 | 42 | #endif |