![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
10/25/2015
Dependencies: PID mbed MaxSonar eeprom iSerial Fork_Boss_Communication_Robot
main.cpp
- Committer:
- palmdotax
- Date:
- 2015-10-22
- Revision:
- 2:933d3edf38da
- Parent:
- 1:7c3dbf140bfc
- Child:
- 3:365615fa646e
File content as of revision 2:933d3edf38da:
#include"mbed.h" #include "move.h" #include "PID.h" //#include "pidmotor.h" InterruptIn encoderA(D6); InterruptIn encoderB(D5); Timer timerStart; move m1; PID P1(0.001,0,0,0.1); //DigitalIn encoderB(D5); Serial pc(SERIAL_TX,SERIAL_RX); int Encoderpos = 0; float valocity =0; float outPID =0,i=0; double Input,Output,setp,Kp=0.005,Ki=0.005,Kd=0; // pid1 p(&Input,&Output,&setp,Kp,Ki,Kd,1); void EncoderA() { if(encoderB==0) { Encoderpos = Encoderpos + 1;} else { Encoderpos = Encoderpos -1;} //Encoderpos = Encoderpos + 1; valocity+=1; // pc.printf("%d \n",Encoderpos); } void EncoderB() { if(encoderA==1) { Encoderpos = Encoderpos + 1;} else { Encoderpos = Encoderpos -1;} pc.printf("%d",Encoderpos); } int main() { pc.baud(115200); encoderA.rise(&EncoderA); timerStart.start(); P1.setMode(1); P1.setProcessValue(0.7); P1.setSetPoint(0.8); P1.setBias(0); while(1) { m1.movespeed(1,1.0); outPID=P1.compute(); pc.printf("%f \n",outPID); wait(0.1); // pc.printf("%d \n",Encoderpos); } }