Romain Ame
/
Stressed
coucou
Fork of Robot2016_2-0 by
StepperMotor/Stepper.cpp@58:02dc8328975a, 2016-05-04 (annotated)
- Committer:
- Jagang
- Date:
- Wed May 04 19:55:03 2016 +0000
- Revision:
- 58:02dc8328975a
- Child:
- 71:5590dbe8393a
Adding ControlleurPince
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Jagang | 58:02dc8328975a | 1 | #include "defines.h" |
Jagang | 58:02dc8328975a | 2 | #include "Stepper.h" |
Jagang | 58:02dc8328975a | 3 | #include "mbed.h" |
Jagang | 58:02dc8328975a | 4 | |
Jagang | 58:02dc8328975a | 5 | Stepper::Stepper(PinName _en, PinName _stepPin, PinName _dir, PinName _minEndStop, float step_per_mm):en(_en), |
Jagang | 58:02dc8328975a | 6 | stepPin(_stepPin), |
Jagang | 58:02dc8328975a | 7 | direction(_dir), |
Jagang | 58:02dc8328975a | 8 | minEndStop(_minEndStop) |
Jagang | 58:02dc8328975a | 9 | { |
Jagang | 58:02dc8328975a | 10 | Step_Per_MM = step_per_mm; |
Jagang | 58:02dc8328975a | 11 | } |
Jagang | 58:02dc8328975a | 12 | |
Jagang | 58:02dc8328975a | 13 | void Stepper::step(int number, int dir, float speed) |
Jagang | 58:02dc8328975a | 14 | { |
Jagang | 58:02dc8328975a | 15 | if (dir == HAUT) { |
Jagang | 58:02dc8328975a | 16 | direction = 0; |
Jagang | 58:02dc8328975a | 17 | } else if (dir == BAS) { |
Jagang | 58:02dc8328975a | 18 | direction = 1; |
Jagang | 58:02dc8328975a | 19 | } |
Jagang | 58:02dc8328975a | 20 | |
Jagang | 58:02dc8328975a | 21 | // Step... |
Jagang | 58:02dc8328975a | 22 | for(int i=0; i<number && !(minEndStop.read() == 0 && dir == BAS); i++) |
Jagang | 58:02dc8328975a | 23 | { |
Jagang | 58:02dc8328975a | 24 | stepPin = 1; |
Jagang | 58:02dc8328975a | 25 | wait_us(5); |
Jagang | 58:02dc8328975a | 26 | stepPin = 0; |
Jagang | 58:02dc8328975a | 27 | wait_us(5); |
Jagang | 58:02dc8328975a | 28 | wait(speed); |
Jagang | 58:02dc8328975a | 29 | } |
Jagang | 58:02dc8328975a | 30 | } |
Jagang | 58:02dc8328975a | 31 | |
Jagang | 58:02dc8328975a | 32 | void Stepper::mm(int number, int dir) |
Jagang | 58:02dc8328975a | 33 | { |
Jagang | 58:02dc8328975a | 34 | step(number*Step_Per_MM, dir, DELAY-0.001); |
Jagang | 58:02dc8328975a | 35 | } |
Jagang | 58:02dc8328975a | 36 | |
Jagang | 58:02dc8328975a | 37 | void Stepper::mm(float distance) |
Jagang | 58:02dc8328975a | 38 | { |
Jagang | 58:02dc8328975a | 39 | step(abs(distance*Step_Per_MM), (distance>0?HAUT:BAS), DELAY-0.001); |
Jagang | 58:02dc8328975a | 40 | } |
Jagang | 58:02dc8328975a | 41 | |
Jagang | 58:02dc8328975a | 42 | void Stepper::enable() |
Jagang | 58:02dc8328975a | 43 | { |
Jagang | 58:02dc8328975a | 44 | en = 0; |
Jagang | 58:02dc8328975a | 45 | } |
Jagang | 58:02dc8328975a | 46 | |
Jagang | 58:02dc8328975a | 47 | void Stepper::disable() |
Jagang | 58:02dc8328975a | 48 | { |
Jagang | 58:02dc8328975a | 49 | en = 1; |
Jagang | 58:02dc8328975a | 50 | } |