As included in Thesis report.

Dependencies:   Encoder MODSERIAL mbed

Committer:
Socrates
Date:
Tue Jun 17 08:24:18 2014 +0000
Revision:
0:210b81f6c5b6
Child:
1:79c4c5746a33
Statische Wrijving

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Socrates 0:210b81f6c5b6 1 #include "mbed.h"
Socrates 0:210b81f6c5b6 2 #include "encoder.h"
Socrates 0:210b81f6c5b6 3 #include "MODSERIAL.h"
Socrates 0:210b81f6c5b6 4
Socrates 0:210b81f6c5b6 5 MODSERIAL pc(USBTX,USBRX);
Socrates 0:210b81f6c5b6 6 Encoder Enc(PTA1,PTA2);
Socrates 0:210b81f6c5b6 7 PwmOut motorplus(PTD3);
Socrates 0:210b81f6c5b6 8 PwmOut motormin(PTC3);
Socrates 0:210b81f6c5b6 9
Socrates 0:210b81f6c5b6 10 double deliver, ts, pos, pos1, move;
Socrates 0:210b81f6c5b6 11 volatile bool flag, loop;
Socrates 0:210b81f6c5b6 12 double Move[25];
Socrates 0:210b81f6c5b6 13 int n;
Socrates 0:210b81f6c5b6 14
Socrates 0:210b81f6c5b6 15 void setflag(void)
Socrates 0:210b81f6c5b6 16 {
Socrates 0:210b81f6c5b6 17 flag=true;
Socrates 0:210b81f6c5b6 18 }
Socrates 0:210b81f6c5b6 19
Socrates 0:210b81f6c5b6 20
Socrates 0:210b81f6c5b6 21 int main()
Socrates 0:210b81f6c5b6 22 {
Socrates 0:210b81f6c5b6 23 pc.baud(115200);
Socrates 0:210b81f6c5b6 24
Socrates 0:210b81f6c5b6 25 Ticker Loop;
Socrates 0:210b81f6c5b6 26
Socrates 0:210b81f6c5b6 27 ts=1.0/5000.0;
Socrates 0:210b81f6c5b6 28
Socrates 0:210b81f6c5b6 29 motorplus.period(1.0/60000.0);
Socrates 0:210b81f6c5b6 30 motormin.period(1.0/60000.0);
Socrates 0:210b81f6c5b6 31 flag=true;
Socrates 0:210b81f6c5b6 32 loop=true;
Socrates 0:210b81f6c5b6 33 wait(3);
Socrates 0:210b81f6c5b6 34 Loop.attach(setflag,ts);
Socrates 0:210b81f6c5b6 35 while(loop==true) {
Socrates 0:210b81f6c5b6 36 while(flag !=true) {
Socrates 0:210b81f6c5b6 37 }
Socrates 0:210b81f6c5b6 38 flag=false;
Socrates 0:210b81f6c5b6 39 motorplus.write(-deliver);
Socrates 0:210b81f6c5b6 40 motormin.write(deliver);
Socrates 0:210b81f6c5b6 41 pos=Enc.getPosition()/1024.0;
Socrates 0:210b81f6c5b6 42 Move[n]=pos-pos1;
Socrates 0:210b81f6c5b6 43 n += 1;
Socrates 0:210b81f6c5b6 44 if (n >24) {
Socrates 0:210b81f6c5b6 45 n=0;
Socrates 0:210b81f6c5b6 46 }
Socrates 0:210b81f6c5b6 47 move=Move[24]-Move[0];
Socrates 0:210b81f6c5b6 48 if (abs(move)>0.002) {
Socrates 0:210b81f6c5b6 49 loop=false;
Socrates 0:210b81f6c5b6 50 motorplus.write(0.0);
Socrates 0:210b81f6c5b6 51 motormin.write(0.0);
Socrates 0:210b81f6c5b6 52 pc.printf("Fr %f\n\r",deliver);
Socrates 0:210b81f6c5b6 53 return 0;
Socrates 0:210b81f6c5b6 54 }
Socrates 0:210b81f6c5b6 55 pc.printf("del %f mo %f\n\r",deliver, move);
Socrates 0:210b81f6c5b6 56
Socrates 0:210b81f6c5b6 57 deliver=deliver+ts/10;
Socrates 0:210b81f6c5b6 58
Socrates 0:210b81f6c5b6 59 }
Socrates 0:210b81f6c5b6 60
Socrates 0:210b81f6c5b6 61
Socrates 0:210b81f6c5b6 62
Socrates 0:210b81f6c5b6 63 }