vor bas

Dependencies:   Encoder mbed

Committer:
wiesdat
Date:
Fri Oct 31 10:27:11 2014 +0000
Revision:
2:2b64e8a0a075
Parent:
1:d157905a98d1
ding

Who changed what in which revision?

UserRevisionLine numberNew contents of line
wiesdat 0:b48b8c18b1bd 1 #include "mbed.h"
wiesdat 0:b48b8c18b1bd 2 #include "mbed.h"
wiesdat 0:b48b8c18b1bd 3 #include "encoder.h"
wiesdat 0:b48b8c18b1bd 4 #define K_P (0.1)
wiesdat 0:b48b8c18b1bd 5 #define K_I (0.1)
wiesdat 0:b48b8c18b1bd 6 #define K_D (0.0005 /TSAMP)
wiesdat 0:b48b8c18b1bd 7 #define TSAMP 0.001
wiesdat 0:b48b8c18b1bd 8 #define I_LIMIT 1.
wiesdat 0:b48b8c18b1bd 9 #include <iostream>
wiesdat 0:b48b8c18b1bd 10
wiesdat 0:b48b8c18b1bd 11 Encoder encoderA(PTD5,PTA13);
wiesdat 0:b48b8c18b1bd 12
wiesdat 0:b48b8c18b1bd 13 PwmOut pwm(PTC8);
wiesdat 0:b48b8c18b1bd 14 DigitalOut dir(PTC9);
wiesdat 0:b48b8c18b1bd 15
wiesdat 0:b48b8c18b1bd 16 int32_t enc = 0,enca2 =0,enca1=0, encp=0, counts =0;
wiesdat 0:b48b8c18b1bd 17 float speed = 0.1, out =0;
wiesdat 0:b48b8c18b1bd 18 int pos =0,zero =0, fout;
wiesdat 0:b48b8c18b1bd 19 float v=0;
wiesdat 0:b48b8c18b1bd 20 float out_i = 0;
wiesdat 0:b48b8c18b1bd 21 int y;
wiesdat 0:b48b8c18b1bd 22
wiesdat 2:2b64e8a0a075 23
wiesdat 2:2b64e8a0a075 24 int main()
wiesdat 0:b48b8c18b1bd 25 {
wiesdat 2:2b64e8a0a075 26 while(1){
wiesdat 2:2b64e8a0a075 27 cout<<"typ 1 voor links, 2 voor rechts: "<<endl;
wiesdat 2:2b64e8a0a075 28 cin>>y;
wiesdat 0:b48b8c18b1bd 29 switch(y) {
wiesdat 0:b48b8c18b1bd 30 case 1:
wiesdat 0:b48b8c18b1bd 31 cout<<"links"<<endl;
wiesdat 2:2b64e8a0a075 32 dir = 1;
wiesdat 0:b48b8c18b1bd 33 pwm.write(0.4);
wiesdat 2:2b64e8a0a075 34 wait(0.01);
wiesdat 0:b48b8c18b1bd 35 pwm.write(0);
wiesdat 0:b48b8c18b1bd 36 break;
wiesdat 0:b48b8c18b1bd 37 case 2:
wiesdat 0:b48b8c18b1bd 38 cout<<"rechts"<<endl;
wiesdat 2:2b64e8a0a075 39 dir = 0;
wiesdat 0:b48b8c18b1bd 40 pwm.write(0.4);
wiesdat 2:2b64e8a0a075 41 wait(0.01);
wiesdat 0:b48b8c18b1bd 42 pwm.write(0);
wiesdat 0:b48b8c18b1bd 43 break;
wiesdat 2:2b64e8a0a075 44 case 3:
wiesdat 2:2b64e8a0a075 45 cout<<encoderA.getPosition()<<endl;
wiesdat 2:2b64e8a0a075 46 break;
wiesdat 2:2b64e8a0a075 47 case 4:
wiesdat 2:2b64e8a0a075 48 encoderA.setPosition(0);
wiesdat 2:2b64e8a0a075 49 break;
wiesdat 0:b48b8c18b1bd 50 }
wiesdat 0:b48b8c18b1bd 51 }
wiesdat 0:b48b8c18b1bd 52
wiesdat 0:b48b8c18b1bd 53
wiesdat 0:b48b8c18b1bd 54 }