Samenwerking Groep 12
Dependencies: Encoder MODSERIAL HIDScope mbed
Foo
main.cpp@18:dfdc44cbcb3b, 2015-09-21 (annotated)
- Committer:
- ThomasBNL
- Date:
- Mon Sep 21 15:24:52 2015 +0000
- Revision:
- 18:dfdc44cbcb3b
- Parent:
- 17:6b91c3549301
laatste versie P controller laatste der revisies, foo, ohnee blijf constructieve namen gebruiken
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ThomasBNL | 10:e923f51f18c4 | 1 | #include "mbed.h" |
ThomasBNL | 10:e923f51f18c4 | 2 | #include "encoder.h" |
ThomasBNL | 10:e923f51f18c4 | 3 | #include "MODSERIAL.h" |
ThomasBNL | 10:e923f51f18c4 | 4 | |
ThomasBNL | 10:e923f51f18c4 | 5 | //Motor 2 |
ThomasBNL | 10:e923f51f18c4 | 6 | DigitalOut motor2direction(D4); //D4 en D5 zijn motor 2 (op het motorshield) |
ThomasBNL | 10:e923f51f18c4 | 7 | PwmOut motor2speed(D5); |
ThomasBNL | 10:e923f51f18c4 | 8 | DigitalIn button(PTA4); |
ThomasBNL | 10:e923f51f18c4 | 9 | Encoder motor2(D13,D12); |
ThomasBNL | 10:e923f51f18c4 | 10 | MODSERIAL pc(USBTX,USBRX); |
bscheltinga | 14:7603d7f1dbe9 | 11 | double reference = 2000; |
bscheltinga | 14:7603d7f1dbe9 | 12 | |
ThomasBNL | 10:e923f51f18c4 | 13 | int main() |
ThomasBNL | 10:e923f51f18c4 | 14 | { |
ThomasBNL | 10:e923f51f18c4 | 15 | pc.baud(9600); |
ThomasBNL | 10:e923f51f18c4 | 16 | motor2.setPosition(0); |
ThomasBNL | 17:6b91c3549301 | 17 | |
ThomasBNL | 18:dfdc44cbcb3b | 18 | while(button.read()< 0.5) |
ThomasBNL | 18:dfdc44cbcb3b | 19 | {motor2direction = 1; |
ThomasBNL | 18:dfdc44cbcb3b | 20 | motor2speed = 0.5f;} |
ThomasBNL | 17:6b91c3549301 | 21 | |
ThomasBNL | 17:6b91c3549301 | 22 | while(true) { |
bscheltinga | 14:7603d7f1dbe9 | 23 | double R = (reference - motor2.getPosition()); |
ThomasBNL | 17:6b91c3549301 | 24 | pc.printf("error R = %d \r\n", R); |
bscheltinga | 14:7603d7f1dbe9 | 25 | |
bscheltinga | 14:7603d7f1dbe9 | 26 | if (R>1) { |
bscheltinga | 14:7603d7f1dbe9 | 27 | motor2direction = 1; //CW |
ThomasBNL | 10:e923f51f18c4 | 28 | motor2speed = 0.5f; |
ThomasBNL | 10:e923f51f18c4 | 29 | pc.printf("positie = %d \r\n", motor2.getPosition()); |
bscheltinga | 14:7603d7f1dbe9 | 30 | } else { |
bscheltinga | 14:7603d7f1dbe9 | 31 | motor2direction = 0; //CCW |
bscheltinga | 14:7603d7f1dbe9 | 32 | motor2speed = 0.5f; |
ThomasBNL | 10:e923f51f18c4 | 33 | pc.printf("positie = %d \r\n", motor2.getPosition()); |
ThomasBNL | 10:e923f51f18c4 | 34 | } |
ThomasBNL | 10:e923f51f18c4 | 35 | } |
bscheltinga | 14:7603d7f1dbe9 | 36 | } |