Samenwerking Groep 12
Dependencies: Encoder MODSERIAL HIDScope mbed
Foo
main.cpp@17:6b91c3549301, 2015-09-21 (annotated)
- Committer:
- ThomasBNL
- Date:
- Mon Sep 21 15:13:22 2015 +0000
- Revision:
- 17:6b91c3549301
- Parent:
- 14:7603d7f1dbe9
- Child:
- 18:dfdc44cbcb3b
P controller - werkend while loop
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 | 17:6b91c3549301 | 18 | while(button = 0) |
ThomasBNL | 17:6b91c3549301 | 19 | |
ThomasBNL | 17:6b91c3549301 | 20 | while(true) { |
bscheltinga | 14:7603d7f1dbe9 | 21 | double R = (reference - motor2.getPosition()); |
ThomasBNL | 17:6b91c3549301 | 22 | pc.printf("error R = %d \r\n", R); |
bscheltinga | 14:7603d7f1dbe9 | 23 | |
bscheltinga | 14:7603d7f1dbe9 | 24 | if (R>1) { |
bscheltinga | 14:7603d7f1dbe9 | 25 | motor2direction = 1; //CW |
ThomasBNL | 10:e923f51f18c4 | 26 | motor2speed = 0.5f; |
ThomasBNL | 10:e923f51f18c4 | 27 | pc.printf("positie = %d \r\n", motor2.getPosition()); |
bscheltinga | 14:7603d7f1dbe9 | 28 | } else { |
bscheltinga | 14:7603d7f1dbe9 | 29 | motor2direction = 0; //CCW |
bscheltinga | 14:7603d7f1dbe9 | 30 | motor2speed = 0.5f; |
ThomasBNL | 10:e923f51f18c4 | 31 | pc.printf("positie = %d \r\n", motor2.getPosition()); |
ThomasBNL | 10:e923f51f18c4 | 32 | } |
ThomasBNL | 10:e923f51f18c4 | 33 | } |
bscheltinga | 14:7603d7f1dbe9 | 34 | } |