vor bas

Dependencies:   Encoder mbed

Committer:
wiesdat
Date:
Fri Oct 31 10:15:16 2014 +0000
Revision:
1:d157905a98d1
Parent:
0:b48b8c18b1bd
Child:
2:2b64e8a0a075
nu in functie

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 1:d157905a98d1 23 void batposition(int y)
wiesdat 0:b48b8c18b1bd 24 {
wiesdat 0:b48b8c18b1bd 25 switch(y) {
wiesdat 0:b48b8c18b1bd 26 case 1:
wiesdat 0:b48b8c18b1bd 27 cout<<"links"<<endl;
wiesdat 1:d157905a98d1 28 dir.write(1);
wiesdat 0:b48b8c18b1bd 29 pwm.write(0.4);
wiesdat 1:d157905a98d1 30 wait(0.03);
wiesdat 0:b48b8c18b1bd 31 pwm.write(0);
wiesdat 0:b48b8c18b1bd 32 break;
wiesdat 0:b48b8c18b1bd 33 case 2:
wiesdat 0:b48b8c18b1bd 34 cout<<"rechts"<<endl;
wiesdat 1:d157905a98d1 35 dir.write(0);
wiesdat 0:b48b8c18b1bd 36 pwm.write(0.4);
wiesdat 1:d157905a98d1 37 wait(0.03);
wiesdat 0:b48b8c18b1bd 38 pwm.write(0);
wiesdat 0:b48b8c18b1bd 39 break;
wiesdat 1:d157905a98d1 40
wiesdat 0:b48b8c18b1bd 41 }
wiesdat 1:d157905a98d1 42
wiesdat 0:b48b8c18b1bd 43 }
wiesdat 0:b48b8c18b1bd 44
wiesdat 1:d157905a98d1 45 int main()
wiesdat 1:d157905a98d1 46 {
wiesdat 1:d157905a98d1 47 while(1) {
wiesdat 1:d157905a98d1 48 cout<<"typ 1 voor links, 2 voor rechts: "<<endl;
wiesdat 1:d157905a98d1 49 cin>>y;
wiesdat 1:d157905a98d1 50 batposition(y);
wiesdat 0:b48b8c18b1bd 51
wiesdat 1:d157905a98d1 52 }
wiesdat 0:b48b8c18b1bd 53 }