
Control of VoiceCoil Lab#7
Dependencies: mbed
Diff: main.cpp
- Revision:
- 2:91678e836872
- Parent:
- 1:92f175969d90
--- a/main.cpp Fri May 10 14:25:24 2019 +0000 +++ b/main.cpp Fri May 24 10:06:51 2019 +0000 @@ -35,9 +35,11 @@ void updateLoop(void); // loop for State machine (via interrupt) float Ts = 0.0005f; // sample time of main loop uint16_t k = 0; +float w = 0.50; // initiate PIDT1 controller objects -// ??? -// ??? +PID_Cntrl dt1(0.0,0.0,0.0116,0.000625,Ts,-4.0,4.0); +PID_Cntrl pi1(3.59,13.5,0.0,1.0,Ts,-4.0,4.0); + //****************************************************************************** //---------- main loop ------------- //****************************************************************************** @@ -61,12 +63,13 @@ float i_des = 0.0f; // default: set motor current to zero (will be overwritten) if(controller_active) { // controller update - // ??? + i_des = pi1(w-x)-dt1(x); } out.write(i2u(i_des)); if(++k>1000) { pc.printf("x: %1.3f, i: %1.4f\r\n",x,i_des); k = 0; + w = -w; } } // END OF updateLoop(void) @@ -91,7 +94,8 @@ if(controller_active) { pc.printf("Controller actived\r\n"); // reset controller here!!! - // ??? + dt1.reset(0.0); + pi1.reset(0.0); } else pc.printf("Controller disabled\r\n"); }