Thursday, March 3, 2016

Lab 4: Controlled Actuation using the PID 


Design a PID controller for position control and implementation of virtual wall!

lab partner: Salma Kashani,


Twiddler haptic knob can be considered as an integrator system in which by applying constant input voltage the system knobe rotates and sum up the rotating angle.  We can simply find the parameters of a integral system model as    

                                                      K          -Td s
                                    G(S) =  ----------- e
                                                      S
and design a PID controller with ziegler nichols or other control methods; however, for this lab we try to do it manually.

Q1. Run the code and try out the P controller. How does it feel? What happens when you change the target position? What does changing the P parameter do? Do you notice any problems? 

We have started our experiment with P=0,  which means that we bypassed the controlling system and therefore we can rotate the knob freely.. by having small values  of P =~0.4 we could see that our system starts to track the target, however the response was so slow and error was high  e=~400.We observed that by changing the target position our system by increasing the P value system responds much faster but becomes unstable. by having large P=~100 even being so close to the target point system starts fluctuating and diverging from target point.    





Q 2. Add the D component to your controller. Tip: you’ll need to modify a parameter in Lab4Arduino.ino, and work it up/down to find an effective value. How does this change the behaviour of the Twiddlerino? Are there any problems?

D can work similar to adding a  damper to our system. first of all it could make our system stable. second by having large value of D system response was slow with no overshoot while decreasing this value can lead to faster responses and generating some overshoot. Third, in order to have small error value we needed to have large P constant and then designing D which can increase the amount of control effort and error was never completely 0,

3. Add the I component to your controller. How does this change the behaviour of the Twiddlerino? Can you create a stable system that reaches the target?

By adding the integrator to our controller we can design a PID with moderate values with no overshoot that can make the error value to 0. Our final values are P=10, I = 5, and D=1,


4. Implement a virtual wall, as a one-sided spring (like Step 1) but active only for θ>0.) What happens? By adding/tweaking PID parameters, can you make it more wall-like?

In our design to have only one sided spring as a wall, we decided to make our controller to be active only when (Theta>0) and for (Theta<0) we set the output of PWM to 0,  by having large P constant we can make a large spring representing our wall. applying small torques to our knob we could definitely see that our controller resists to small disturbance and doesn't let us rotate the knob. by applying larger torque to our system we could eventually rotate the knob but when we suddenly decrease the torque it push us out of the wall and since it had some overshoot which means that our virtual wall was extending out which was incorrect. Then we added large damping effect to our system when we are going inside the wall to a have viscoelasticity in our wall and reduce this damping effect when the wall pushes our finger out. The only reason that we keep some small  D value was to make the overshoot zero. To differentiate between going inside and outside we introduced new position term which keeps the previous value of position after reading the new value.


    pos = ReadEncoder();
   if (pos>=0){
                        p=100;
                          i=2;
                         d=5;
                             if (pos>pos1){
                                                   p=128;
                                                    i=2;
                                                     d=100;}
                                              else {
                                                   p=100;
                                                   i=2;
                                                  d=5;   } 
       
                          myPID.SetTunings(p, i, d);
                         SetPWMOut(PWMOut);}
                    else{
                           p=10;
                            i=0;
                           d=0;
                           myPID.SetTunings(p, i, d);
                            SetPWMOut(0);
                           }
     pos1 =pos;


VID1 - The implementation of  virtual wall



Q5. Play with the controller update rates, and with introducing delays. Hint: use the PID’s SetSamplingRate() command. How does this change the system? What happens if you sample faster or slower? Can you make the interrupt service routine run faster, and see better performance that way

The graph below can explain the behaviour of SetSampleTime. When T1 is switching and T2 and T3 are closed.At this point, we can obtain the error at high speed but our controller cannot generate proper output based on real value of error and works based on previous acquired sample. basically, this value can determine how often The PID algorithm runs and generates output. The default value was set at 1 millisecond which was the minimum. by increasing this value we could see system overshoots and becomes unstable.


Fig1 - Sampling time and controlling diagram 

VID 2 - 10 ms update rate for PID

Q6. Think about different ways of timing the loop (polling “run as fast as you can”, vs. clocked “wake up at a specified time”). Hint: Look at the following Arduino examples: Blink (01 Basics), BlinkWithoutDelay (02 Digital), and FlashLED (MsTimer2). What are the impact of each of these? Which method is implemented in the sample code? Can you make a theory about impact on the
Twiddlerino sketch, and test it?

At this point we are changing the sampling rate and this is similar to the case when  is switching and  are closed. Although our controller is working at high speed sampling rate the value of error is not a real-time value and therefore the control effort is not valid and lead to system instability so the values of our primary PID controller are not useful anymore and we need to design a new controller.

The function of  updateinterval is to send the value of position to screen through processing software. This timing can be present in our control diagram as T2. Different interval time will not affect the performance of controller and our accordingly our feeling, but higher timing will update the visual display at  slower rate and subsequently sudden jump and steps in position display.
In flash Led  example we have an adjustable timer interrupt. By using this timer we can control the sampling rate of the system so we don't need to read it in main loop of the system. To do that we have added the following codes to our arduino:
 void read(){
                     pos=ReadEncoder();
                  }
void setup()
{
                       Serial.begin(115200);
                        TwiddlerinoInit();
                        target = 0;
                        myPID.SetOutputLimits(-255, 255); //for PWM
                         myPID.SetMode(AUTOMATIC); //compute() and things will work
                         myPID.SetSampleTime(1); //every 1 ms
                          last_time = millis();
                           MsTimer2::set(10,read);
                           MsTimer2::start();
       }
This will help us to make sure that our heavy computation in main loop of the system will no affect our sampling rate and controller's performance. 

Vid3, Sampling rate of 100 ms

This case T3 is switching and T1, T2 are closed. Although our controller is working at 100ms sampling rate the value of error is not a real-time value and therefore the control effort is not valid and lead to system instability so the values of our primary PID controller are not useful anymore and we need to design a new controller. 

Conclusion :
We observed that by having any sampling in control loop our first design of controller for (high speed sampling =continues)should be changed based on sampling time. If we introduce both sampling at sensing and updating the control the maximum time will be dominant and should be considered. The sampling time outside of control loop will not affect on mechanical response of the system and only make step like visual graph of position.  


No comments:

Post a Comment