Samenwerking Groep 12

Dependencies:   Encoder MODSERIAL HIDScope mbed

Foo

Committer:
bscheltinga
Date:
Mon Sep 21 15:01:38 2015 +0000
Revision:
14:7603d7f1dbe9
Parent:
10:e923f51f18c4
Child:
17:6b91c3549301
P-controller (not tested)

Who changed what in which revision?

UserRevisionLine numberNew 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);
bscheltinga 14:7603d7f1dbe9 17 double R = (reference - motor2.getPosition());
bscheltinga 14:7603d7f1dbe9 18 pc.printf("error R=%d \r\n", R);
bscheltinga 14:7603d7f1dbe9 19
ThomasBNL 10:e923f51f18c4 20 while(true) {
bscheltinga 14:7603d7f1dbe9 21 if (R>1) {
bscheltinga 14:7603d7f1dbe9 22 motor2direction = 1; //CW
ThomasBNL 10:e923f51f18c4 23 motor2speed = 0.5f;
ThomasBNL 10:e923f51f18c4 24 pc.printf("positie = %d \r\n", motor2.getPosition());
bscheltinga 14:7603d7f1dbe9 25 } else {
bscheltinga 14:7603d7f1dbe9 26 motor2direction = 0; //CCW
bscheltinga 14:7603d7f1dbe9 27 motor2speed = 0.5f;
ThomasBNL 10:e923f51f18c4 28 pc.printf("positie = %d \r\n", motor2.getPosition());
ThomasBNL 10:e923f51f18c4 29 }
ThomasBNL 10:e923f51f18c4 30 }
bscheltinga 14:7603d7f1dbe9 31 }