Justin Jordan
/
R5_StepperDrive
update 1/27/16
Fork of R5_StepperDrive by
StepperDrive.h@4:754c74beef20, 2016-03-25 (annotated)
- Committer:
- j_j205
- Date:
- Fri Mar 25 19:50:38 2016 +0000
- Revision:
- 4:754c74beef20
- Parent:
- 3:97bea13f40a9
3/25/16 2:50 JJ
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: |
j_j205 | 1:909572175aad | 10 | StepperDrive(Serial &pc1, PinName in1, PinName in2, bool in3, PinName in4, PinName in5, bool in6, float in7, float in8, float in9 = 1000); |
j_j205 | 2:80c0b2a5adc0 | 11 | //(serisl &, 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(); |
j_j205 | 4:754c74beef20 | 14 | void pauseMove(); |
j_j205 | 4:754c74beef20 | 15 | void resumeMove(); |
j_j205 | 3:97bea13f40a9 | 16 | |
j_j205 | 1:909572175aad | 17 | Serial &pc; |
j_j205 | 1:909572175aad | 18 | int getRightSteps() { return rightSteps; } |
j_j205 | 1:909572175aad | 19 | int getLeftSteps() { return leftSteps; } |
j_j205 | 3:97bea13f40a9 | 20 | |
jmar11 | 0:266a770a17e9 | 21 | private: |
jmar11 | 0:266a770a17e9 | 22 | Ticker pit; //periodic interrupt timer |
j_j205 | 3:97bea13f40a9 | 23 | |
jmar11 | 0:266a770a17e9 | 24 | void pitCallback(); |
j_j205 | 3:97bea13f40a9 | 25 | |
jmar11 | 0:266a770a17e9 | 26 | void stepRight(bool dir); |
jmar11 | 0:266a770a17e9 | 27 | void stepLeft(bool dir); |
j_j205 | 3:97bea13f40a9 | 28 | |
jmar11 | 0:266a770a17e9 | 29 | DigitalOut leftStep; |
jmar11 | 0:266a770a17e9 | 30 | DigitalOut leftDir; |
jmar11 | 0:266a770a17e9 | 31 | DigitalOut rightStep; |
jmar11 | 0:266a770a17e9 | 32 | DigitalOut rightDir; |
j_j205 | 3:97bea13f40a9 | 33 | |
jmar11 | 0:266a770a17e9 | 34 | float wheelCircum; //wheel circumference |
jmar11 | 0:266a770a17e9 | 35 | float wheelSepar; //distance between wheels |
jmar11 | 0:266a770a17e9 | 36 | bool invertLeft; //software wheel direction inversion |
jmar11 | 0:266a770a17e9 | 37 | bool invertRight; //software wheel direction inversion |
jmar11 | 0:266a770a17e9 | 38 | bool moveComplete; |
j_j205 | 3:97bea13f40a9 | 39 | |
jmar11 | 0:266a770a17e9 | 40 | int leftSteps; |
jmar11 | 0:266a770a17e9 | 41 | int rightSteps; |
jmar11 | 0:266a770a17e9 | 42 | float leftStepsPC; |
jmar11 | 0:266a770a17e9 | 43 | float rightStepsPC; |
jmar11 | 0:266a770a17e9 | 44 | float leftError; |
jmar11 | 0:266a770a17e9 | 45 | float rightError; |
j_j205 | 4:754c74beef20 | 46 | int leftStepsPause; // for holding steps left during pause |
j_j205 | 4:754c74beef20 | 47 | int rightStepsPause; // for holding steps right during pause |
jmar11 | 0:266a770a17e9 | 48 | }; |
jmar11 | 0:266a770a17e9 | 49 | |
jmar11 | 0:266a770a17e9 | 50 | #endif |