![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
10/25/2015
Dependencies: PID mbed MaxSonar eeprom iSerial Fork_Boss_Communication_Robot
Diff: main.cpp
- Revision:
- 5:68b740d113e6
- Parent:
- 4:e6ab360e7de6
- Child:
- 6:9ed82a812ece
diff -r e6ab360e7de6 -r 68b740d113e6 main.cpp --- a/main.cpp Fri Oct 23 18:40:26 2015 +0000 +++ b/main.cpp Sun Oct 25 12:03:21 2015 +0000 @@ -15,7 +15,7 @@ Serial pc(SERIAL_TX,SERIAL_RX); int Encoderpos = 0; - float valocity =0,pulse=0,count=0; + float valocity =0,pulse=0,count=0,r=0.01,velocityreal=0; float outPID =0; //double Input,Output,setp,Kp=0.005,Ki=0.005,Kd=0; @@ -30,8 +30,10 @@ // valocity+=1; // pc.printf("%d \n",Encoderpos); pulse+=1; - if(pulse>=128) - {count+=1;pulse=0;} + //pc.printf("pulse=%f \n",pulse); + // if(pulse==128) + //{count+=1;pulse=0; pc.printf("count=%f \n",count);} + } @@ -43,41 +45,46 @@ { Encoderpos = Encoderpos -1;} pc.printf("%d",Encoderpos); }*/ -void getRPM() +void getvelo() { - valocity=count; + valocity=pulse+((2*3.14*r)/128); pc.printf("%f \n",valocity); count=0; timerStart.reset(); } +void getveloreal(int velo) +{ + velocityreal=velo; + +} int main() { - - pc.baud(115200); - encoderA.rise(&EncoderA); - timerStart.start(); - - + int times=0; + pc.baud(115200); + encoderA.rise(&EncoderA); + timerStart.start(); P1.setMode(1); - - P1.setSetPoint(20); + getveloreal(50); + P1.setSetPoint(velocityreal);//setpont P1.setBias(0); pc.printf("READY \n"); led1=1; while(1) { - - if(timerStart.read()==60) - { - getRPM(); + times=timerStart.read(); + if(times==1)// m/s + { + getvelo(); + //pc.printf("TIME \n"); + times=0; } //timecount.attach(&getRPM, 60); P1.setProcessValue(valocity); // m1.movespeed(1,1.0); outPID=P1.compute(); - m1.movespeed(1,outPID); + m1.movespeed(1,velocityreal,outPID); wait(0.1);