Script voor aansturen motoren
Dependencies: Encoder HIDScope MODSERIAL mbed-dsp mbed
main.cpp@7:697293226e5e, 2014-10-23 (annotated)
- Committer:
- jessekaiser
- Date:
- Thu Oct 23 10:47:35 2014 +0000
- Revision:
- 7:697293226e5e
- Parent:
- 6:f260176f704b
- Child:
- 8:0bbbe93bd1c4
- Child:
- 18:fb85c58a4106
Volgens mij is HIDScope nu goed af te lezen (volgens script Daan met aanpassingen). Dit is nu alleen voor motor1 (25D).
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jessekaiser | 0:d5d3b731340c | 1 | #include "mbed.h" |
jessekaiser | 0:d5d3b731340c | 2 | #include "encoder.h" |
jessekaiser | 0:d5d3b731340c | 3 | #include "HIDScope.h" |
jessekaiser | 0:d5d3b731340c | 4 | |
jessekaiser | 6:f260176f704b | 5 | #define TSAMP 0.005 |
jessekaiser | 0:d5d3b731340c | 6 | #define K_P (0.1) |
jessekaiser | 0:d5d3b731340c | 7 | #define K_I (0.03 *TSAMP) |
jessekaiser | 0:d5d3b731340c | 8 | #define K_D (0.001 /TSAMP) |
jessekaiser | 0:d5d3b731340c | 9 | #define I_LIMIT 1. |
jessekaiser | 0:d5d3b731340c | 10 | |
jessekaiser | 7:697293226e5e | 11 | #define M1_PWM PTC8 |
jessekaiser | 7:697293226e5e | 12 | #define M1_DIR PTC9 |
jessekaiser | 7:697293226e5e | 13 | #define M2_PWM PTA5 |
jessekaiser | 7:697293226e5e | 14 | #define M2_DIR PTA4 |
jessekaiser | 7:697293226e5e | 15 | |
jessekaiser | 7:697293226e5e | 16 | //Groene kabel moet op de GROUND en blauw op de 3.3v aansluiting |
jessekaiser | 0:d5d3b731340c | 17 | |
jessekaiser | 3:dcc4cebba0d7 | 18 | Serial pc(USBTX, USBRX); |
jessekaiser | 4:db3dad7e53e3 | 19 | DigitalOut led1(LED_RED); |
jessekaiser | 5:e4b9cc904928 | 20 | HIDScope scope(2); |
jessekaiser | 0:d5d3b731340c | 21 | |
jessekaiser | 7:697293226e5e | 22 | //motor 25D |
jessekaiser | 7:697293226e5e | 23 | Encoder motor1(PTD3,PTD5); //wit, geel |
jessekaiser | 7:697293226e5e | 24 | PwmOut pwm_motor1(M2_PWM); |
jessekaiser | 7:697293226e5e | 25 | DigitalOut motordir1(M2_DIR); |
jessekaiser | 3:dcc4cebba0d7 | 26 | |
jessekaiser | 7:697293226e5e | 27 | //motor2 37D |
jessekaiser | 7:697293226e5e | 28 | Encoder motor2(PTD2, PTD0); //wit, geel |
jessekaiser | 7:697293226e5e | 29 | PwmOut pwm_motor2(M1_PWM); |
jessekaiser | 7:697293226e5e | 30 | DigitalOut motordir2(M1_DIR); |
jessekaiser | 7:697293226e5e | 31 | |
jessekaiser | 7:697293226e5e | 32 | bool flip=false; |
jessekaiser | 7:697293226e5e | 33 | |
jessekaiser | 7:697293226e5e | 34 | void attime() |
jessekaiser | 0:d5d3b731340c | 35 | { |
jessekaiser | 7:697293226e5e | 36 | flip = !flip; |
jessekaiser | 0:d5d3b731340c | 37 | } |
jessekaiser | 0:d5d3b731340c | 38 | |
jessekaiser | 7:697293226e5e | 39 | void looper() |
jessekaiser | 7:697293226e5e | 40 | { |
jessekaiser | 7:697293226e5e | 41 | motordir1=0; |
jessekaiser | 7:697293226e5e | 42 | pwm_motor1.write(1); |
jessekaiser | 7:697293226e5e | 43 | scope.set(0, motor1.getPosition()); |
jessekaiser | 7:697293226e5e | 44 | scope.set(1, motor2.getPosition()); |
jessekaiser | 7:697293226e5e | 45 | scope.send(); |
jessekaiser | 7:697293226e5e | 46 | } |
jessekaiser | 3:dcc4cebba0d7 | 47 | |
jessekaiser | 3:dcc4cebba0d7 | 48 | |
jessekaiser | 0:d5d3b731340c | 49 | int main() |
jessekaiser | 3:dcc4cebba0d7 | 50 | { |
jessekaiser | 7:697293226e5e | 51 | Ticker log_timer; |
jessekaiser | 7:697293226e5e | 52 | Ticker timer; |
jessekaiser | 7:697293226e5e | 53 | log_timer.attach(looper, TSAMP); |
jessekaiser | 7:697293226e5e | 54 | timer.attach(&attime, 7); |
jessekaiser | 0:d5d3b731340c | 55 | while(1) { |
jessekaiser | 6:f260176f704b | 56 | |
jessekaiser | 6:f260176f704b | 57 | } |
jessekaiser | 0:d5d3b731340c | 58 | } |