practice for PID control
Dependencies: PID QEI USBDevice mbed
Diff: main.cpp
- Revision:
- 1:6d5c35b995fb
- Parent:
- 0:b2973a157cb6
- Child:
- 2:b46f1a4c42fb
--- a/main.cpp Tue Apr 15 02:02:38 2014 +0000 +++ b/main.cpp Tue Apr 15 02:10:03 2014 +0000 @@ -17,8 +17,6 @@ SPI spi(P0_21, NC, P1_20); DigitalOut cs(P1_23); -//Ticker flip; - Timer timer; PID controller(kc, ti, td, PIDRATE); @@ -52,40 +50,12 @@ union MCP4922 dac = {0xF7F}; - -//void tick() -//{ -// static int tcnt, efpls; -// int epls; -// float etmppls; -// tcnt++; -// if(SW == 0) -// { -// wheel.reset(); -// } -// if(tcnt == 40) -// { -// tcnt = 0; -// epls = wheel.getPulses(); -// etmppls = (float)(epls - efpls); -// efpls = epls; -// vcom.printf("\033[%d;%dH", 0, 0); -// vcom.printf("count :%9d\n", epls); -// vcom.printf("rev/sec:%3.6f\n", (etmppls / 3600)); -// vcom.printf("DAC.bit:%09d\n", dac.bit.D); -// } -//// cs = 0; -//// spi.write(dac.command); -//// cs = 1; -//} - int main() { uint8_t i = 0; int epls[2] = {0, 0}; float rps = 0; -// flip.attach(tick, (PIDRATE / 2)); SW.mode(PullUp); mdrv = CW; cs = 1; @@ -179,38 +149,41 @@ vcom.printf("\033[%d;%dH", 0, 0); //Output bias - vcom.printf("Input the bias for the controller output\n"); - vcom.printf("within 15 figures.\n"); - vcom.scanf("%s", str); - tmp[0] = strtof(str, &erstr); - controller.setBias(tmp[0]); - vcom.printf("Output bias : %15f\n", tmp[0]); +// vcom.printf("Input the bias for the controller output\n"); +// vcom.printf("within 15 figures.\n"); +// vcom.scanf("%s", str); +// tmp[0] = strtof(str, &erstr); +// controller.setBias(tmp[0]); +// vcom.printf("Output bias : %15f\n", tmp[0]); + controller.setBias(200); //Input limits - vcom.printf("Input the minimum inputlimit\n"); - vcom.printf("within 15 figures.\n"); - vcom.scanf("%s", str); - tmp[0] = strtof(str, &erstr); - vcom.printf("Minimum input limit : %15f\n", tmp[0]); +// vcom.printf("Input the minimum inputlimit\n"); +// vcom.printf("within 15 figures.\n"); +// vcom.scanf("%s", str); +// tmp[0] = strtof(str, &erstr); +// vcom.printf("Minimum input limit : %15f\n", tmp[0]); vcom.printf("Input the maximum inputlimit\n"); vcom.printf("within 15 figures.\n"); vcom.scanf("%s", str); tmp[1] = strtof(str, &erstr); vcom.printf("Maximum input limit : %15f\n", tmp[1]); - controller.setInputLimits(tmp[0], tmp[1]); +// controller.setInputLimits(tmp[0], tmp[1]); + controller.setInputLimits(0,tmp[1]); //Output limits - vcom.printf("Input the minimum outputlimit\n"); - vcom.printf("within 15 figures.\n"); - vcom.scanf("%s", str); - tmp[0] = strtof(str, &erstr); - vcom.printf("Minimum output limit : %15f\n", tmp[0]); - vcom.printf("Input the maximum outputlimit\n"); - vcom.printf("within 15 figures.\n"); - vcom.scanf("%s", str); - tmp[1] = strtof(str, &erstr); - vcom.printf("Maximum output limit : %15f\n", tmp[1]); - controller.setOutputLimits(tmp[0], tmp[1]); +// vcom.printf("Input the minimum outputlimit\n"); +// vcom.printf("within 15 figures.\n"); +// vcom.scanf("%s", str); +// tmp[0] = strtof(str, &erstr); +// vcom.printf("Minimum output limit : %15f\n", tmp[0]); +// vcom.printf("Input the maximum outputlimit\n"); +// vcom.printf("within 15 figures.\n"); +// vcom.scanf("%s", str); +// tmp[1] = strtof(str, &erstr); +// vcom.printf("Maximum output limit : %15f\n", tmp[1]); +// controller.setOutputLimits(tmp[0], tmp[1]); + controller.setOutputLimits(0, 4095); //Setpoint vcom.printf("Input the setpoint\n");