![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Six crescent shaped legs
Diff: main.cpp
- Revision:
- 1:8b0322a353f4
- Parent:
- 0:0b7259fdb68a
- Child:
- 2:cf0147952fb9
--- a/main.cpp Thu Mar 24 11:01:18 2016 +0000 +++ b/main.cpp Mon Mar 28 12:23:38 2016 +0000 @@ -6,51 +6,66 @@ DigitalOut dir1(PC_0); DigitalOut dir2(PC_1); InterruptIn encA(PA_0); +//InterruptIn encB(PA_1); InterruptIn bt(USER_BUTTON); Serial pc(SERIAL_TX, SERIAL_RX); -int iLoe = 0; -int isItTime = 0; -int iUus = 0; int iAeg = 0; -//int iVan[2] = {0,0}; -double dPwm = 0.01; -int lastB= bt; +//int iDir; +//int iTime = 0; +unsigned long long int iSum = 0; +double dPwm = 0.2; +double newPwm = dPwm; +double miss = 0; +double lastMiss = 0; +double chPwm = 0; +double totMiss = 0; +double minPwm = 0.1; +double maxPwm = 0.7; +double dSpeed = 0.5; + +/*int getDir(){ + if ((dAeg/(double)iDir > 0.5){ + return (1);} + else return 0; + }*/ void start(){ - iUus = timer.read_us(); timer.reset(); } +/*void dir(){ + iDir = timer.read_us(); + }*/ void stop(){ iAeg = timer.read_us(); - } - -void button(){ - isItTime = 1; + //iDir = getDir(); } int main(){ + timer.start(); encA.rise(&start); encA.fall(&stop); - bt.fall(&button); - timer.start(); + //encB.rise(&dir); + double real = (1-dSpeed)*1000; mypwm.write(dPwm); - //mypwm.period_ms(10); - //mypwm.pulsewidth_ms(4); dir1 = 1; dir2 = 0; - - while(1) { - if (isItTime){ - isItTime = 0; - dPwm = dPwm + 0.1; - if (dPwm>=1){ - dPwm--; + while(1){ + if (iAeg != 0){ + miss = iAeg - real; + totMiss = totMiss + miss; + chPwm = totMiss/200000; + if (chPwm > -0.0001 && chPwm < 0.0001) { + pc.printf("%f,%f\n",totMiss,chPwm);} + newPwm = dPwm + chPwm; + if (newPwm < minPwm){ + newPwm = minPwm; + } + else if (newPwm > maxPwm){ + newPwm = maxPwm; + } + mypwm.write(newPwm); + iAeg = 0; } - mypwm.write(dPwm); } - else { - pc.printf("%f: %d/%d\n",dPwm,iUus,iAeg); - } - } -} + } \ No newline at end of file