sfbsg

Dependencies:   mbed

Committer:
borlanic
Date:
Tue Apr 03 15:17:11 2018 +0000
Revision:
0:8ab621116ccd
fg

Who changed what in which revision?

UserRevisionLine numberNew contents of line
borlanic 0:8ab621116ccd 1 #include "mbed.h"
borlanic 0:8ab621116ccd 2 #include "math.h"
borlanic 0:8ab621116ccd 3 //------------------------------------------
borlanic 0:8ab621116ccd 4 #define PI 3.1415927f
borlanic 0:8ab621116ccd 5 //------------------------------------------
borlanic 0:8ab621116ccd 6 #include "EncoderCounter.h"
borlanic 0:8ab621116ccd 7 #include "DiffCounter.h"
borlanic 0:8ab621116ccd 8 #include "IIR_filter.h"
borlanic 0:8ab621116ccd 9 #include "LinearCharacteristics.h"
borlanic 0:8ab621116ccd 10
borlanic 0:8ab621116ccd 11 PwmOut pwm1(PA_5);
borlanic 0:8ab621116ccd 12
borlanic 0:8ab621116ccd 13 float inc2rad = 2.0f*3.1415927f/(4.0f*6400.0);
borlanic 0:8ab621116ccd 14
borlanic 0:8ab621116ccd 15 int main()
borlanic 0:8ab621116ccd 16 {
borlanic 0:8ab621116ccd 17
borlanic 0:8ab621116ccd 18 EncoderCounter counter1(PB_6, PB_7);
borlanic 0:8ab621116ccd 19 DiffCounter diffc(0.9f,0.05f);
borlanic 0:8ab621116ccd 20
borlanic 0:8ab621116ccd 21
borlanic 0:8ab621116ccd 22 pwm1.period(0.00005f);
borlanic 0:8ab621116ccd 23
borlanic 0:8ab621116ccd 24 while(1) {
borlanic 0:8ab621116ccd 25 short inc = counter1.read();
borlanic 0:8ab621116ccd 26 float velocity = diffc(inc);
borlanic 0:8ab621116ccd 27 printf("angle = %.2f velocity = %.2f\r\n",inc*inc2rad,velocity);
borlanic 0:8ab621116ccd 28
borlanic 0:8ab621116ccd 29 pwm1.write(0.5f);
borlanic 0:8ab621116ccd 30 wait(0.05f);
borlanic 0:8ab621116ccd 31 }
borlanic 0:8ab621116ccd 32 }
borlanic 0:8ab621116ccd 33
borlanic 0:8ab621116ccd 34