Wednesday, May 1, 2013

Manually Installing Intel's Graphics Drivers in Ubuntu 13.04


Intel’s graphics installer didn’t work for me in 13.04 (as shown below)... However I was able to find out how to install these same drivers from the command line.  

  1. Run the utility and you’ll get the error. The utility loads a file that defines the packages that need to be installed in the home directory. Open the file named “.ilg-config” in a text editor .
  2. Scroll until you find the most recent distribution.. in my case 12.10.  We see this file gives the source and all of the packages to be installed. So now we have to add the source either by adding it to /etc/apt/sources.list or from the gui add it like so:

  1. Then do an update of the sources (sudo apt-get update)
  2. Now install all of the packages listed, for me it was:

sudo apt-get install libcairo2 libcairo-gobject2 libcairo-script-interpreter2 libdrm2 libdrm-intel1 libkms1 libva1 libva-x11-1 libva-glx1 libva-tpi1 libva-egl1 vainfo libxatracker1 libgbm1 libegl1-mesa libegl1-mesa-drivers libopenvg1-mesa libgles1-mesa libgles2-mesa libglapi-mesa libgl1-mesa-glx libgl1-mesa-dri libgl1-mesa-dri-experimental libosmesa6 libglu1-mesa i965-va-driver libva-intel-vaapi-driver xserver-xorg-video-intel libdrm-nouveau2 libwayland0

but it may be different for you.

Now if we run glxinfo we see direct 3D rendering is enabled using the Intel Open Source drivers!

...

Thanks! Please note, i’m not responsable if this doesn’t work... or messes things up. It worked fine for me but do it at your own risk (or just wait for them to update the app).

Sunday, March 31, 2013

Control Systems in Python - Phase Lag Compensator Design

Here's a problem I had to do for homework. Some of the equation formatting didn't copy over, sorry...

Given an system G(s) = 10/(s(s+4)) and it’s open loop bode plots, design an appropriate compensator so that the closed loop phase margin is at least 45o and the velocity constant is 50.
The bode plot shows that the PM for the open loop system is 64.2o at ω = 1.931rad/s, at the same frequency, we see that the P.M. of the closed loop system is 129o. The velocity constant indicates the steady state error to a ramp input must be ess =1/Kv = 1/50 = 0.02.  First, the velocity constant of the uncompensated system is:

Kv=limit as s->0 of sG(s) =limit as s->0 of s10/s(s+4)=10/4=2.5

since we want Kv  50, the compensator must have a gain of at least 50/2.5 = 20.  

If our compensator Gc(s) = Kc = 20, we get the following new responses by simply shifting the open loop bode up by about 26dB. Thus the new open loop 0dB crossing is at  ω = 13.83 rad/s and the open and closed loop phase margins are 16.12o and  23.2o respectively.  


However since the specification states that the closed loop phase margin be at least 45o, this simple controller will not work.

Since we are trying to adjust the steady state error of the system instead of transient response, a phase-lag controller of the form Gc(s) = K(s+z)/(s+p) will be used. Following the phase lag design procedure for bode plots, the controller gain must be 20 or more, thus we have the condition that:
(1) Kz/p = 20

The desired crossover point will give a 45o phase margin, and the controller will add about  5o and decrease the gain by 10log(20)   13dB. So i’ll pick the frequency where the open loop phase is about 130o, at around ωc = 3 rad/s.  

Then z =  ωc/10 = 0.3 and p becomes

p=0.3*20/|G(3j)|= 0.0225.
then using (1) K becomes,  20*0.0225/0.3=1.5.  The controller is then:
Gc(s) =

the response then becomes:
which shows that the P.M. of the open loop system is 47.8o and the P.M. of the closed loop system is 82.6o which is well above the desired amount of 45o

Recalculating the velocity constant with the compensator we get:

Kv=limit as s->0 of sGc(s)G(s)=limit as s->0 of s*1.5(s+0.3)/(s+0.0225) 10/s(s+4) =0.45*10/(0.0225*0.4)=50

which is the desired value.

Saturday, March 9, 2013

Control Systems in Python - Part 3 - Root Locus Plots

In this post we can see how to make root locus plots in python. This requires the setup from part 1.

The problem is from Dorf's modern control systems AP 10.1. A three-axis pick-and-place application requires the precise movement of a robotic arm in three-dimensional space. The overshoot for a step input should be less than 13%.
a) Let Gc(s) = K, and determine the gain K that satisfies the requirement. Determine the resulting settling time (with a 2% criterion). First we compute the Routh Hurwitz table to determine the valid
range of K.

We see 0<K<20 so If we let K = 2, then the step response becomes:
which shows the settling time is 8.68 seconds and overshoot is less than 13%.

b) Use a lead network and reduce the settling time to less than 3 seconds. Since we are dealing with time response parameters the root-locus method will be used.

The new controller is:

the overshoot and settling time criteria lead to a damping ratio of 0.545 or more and the real part of the dominant poles must be to the left of -1.33 respectively.  

If we choose our dominant poles to be at s1 = -2 +- 2j they fall in the correct region on the root locus and should get the desired response. The angle of the system L(s) at s1 is Ls 63.4o.  So letting m=0,
∠Gc(s1) =180 - 63.4 = 116.6o
the controller must add this amount. If we pick our zero to be at ½ , then using the relationship:
∠( s1+ z ) -∠(s1+p)  = 106.26o
we find p = 6.34 and K = 34.19.  This leads to the step response of:
from which we can see the settling time has been reduced but not enough to meet the specifications. Let's move it closer to the system pole at -1. 

Reiterating through the root locus design procedure, if we move our zero out to z=¾ and recalculate p=5.86 and K=32.9, the response now is:
which shows another good improvement in the settling time but the zero still needs moved closer to the pole at -1.

Lastly let’s set our z=0.9, then p=5.63 and K=32.5. The root locus is computed using:def rootLocus(Ts,*args,**kwargs):    num = Poly(Ts.as_numer_denom()[0],s).all_coeffs()    den = Poly(Ts.as_numer_denom()[1],s).all_coeffs()    tf = matlab.tf(map(float,num),map(float,den))    r,k = matlab.rlocus(tf,*args,**kwargs)    plt.title("Root Locus")    #plt.plot(k,r)    plt.grid()    plt.show()and the output is:resulting in the final controller of:who's step response is:which shows the controller has reduced the overshoot and settling time to within the specifications (the settling time is less than 3 seconds).

Tuesday, February 12, 2013

Fix Pithos not playing an not showing any error

So for some reason my Pithos wasn't working for the past two weeks, it would simply open and not load any songs, show a blank window, and not give any errors. This is how I *fixed* it:

1. Remove it and purge all user settings

sudo apt-get purge pithos

2. Reinstall

sudo apt-get install pithos


And wala!

I'm not sure why, but it worked!

Sunday, February 10, 2013

Control Systems in Python - Part 2 - Routh Hurwitz



In my last post Control Systems in Python Part 1, i described how to setup and use Python for doing some basic plotting of transfer functions. One of the biggest benefits of using sympy vs numeric packages like matlab/numpy/scipy is the fact that you can use symbolic variables. This post includes a function for computing the Routh Hurwitz table (Note: It does not work for row's of zeros).


Lets do my control systems design homework problem together :) (Warning: I have not verified if this answer is right so please correct me if it’s not!)

The Problem

The problem is DP 9.11 from Dorf & Bishop’s Modern Control Systems. ISBN 0136024580. Basically we have to design a controller to compensate for a system with a time delay.
The controller is:


And the system is:



First we approximate the exponential term with a 2nd order polynomial using pade(0.4,2) such that:

Thus the approximated system is:



Using frequency response methods, design the controller so that the overshoot of the system is P.O. <= 10%. From this we determine 0.59. When we plot the poles and zeros of the system we see that there are 3 poles in the LHP and two zeros in the RHP. The controller adds another pole at 0, so the zero of our controller should be somewhere to the left of the -5 pole on the real axis.
Thus Ki/Kp > 5. If Ki/Kp = 6. Using a Routh Hurwitz table we can see that 0<Kp<0.66 makes the system stable.

The code for this function is:

def routhHurwitz(Ts,*args):
    den = Poly(Ts.as_numer_denom()[1],s).all_coeffs()
    n = len(den)-1
    if n < 2:
        return None
    m = matrices.zeros(n+1)
    # Insert the first two rows
    c = [den[i] for i in range(0,n+1,2)]
    for i in range(0,len(c)):
        m[0,i] = c[i]
    c = [den[i] for i in range(1,n+1,2)]
    for i in range(0,len(c)):
        m[1,i] = c[i]
 
    # Compute the rest of the entries
    for i in range(2,n+1):
        for j in range(1,n):
            if m[i-1,j] == 0:
                m[i,j-1] = m[i-2,j]
            elif m[i-1,0] !=0:
                m[i,j-1] = ((m[i-1,0]*m[i-2,j]-m[i-2,0]*m[i-1,j])/m[i-1,0]).together().simplify()
         
     
    m = m.col_insert(0, Matrix(([s**(n-i) for i in range(0,n+1)])))
    return m

When we set Kp = 0.22 we get the controller:

giving the step response of:
if the gain is reduced the %OS reduces and Ts rises.


Saturday, February 9, 2013

Control Systems in Python - Part 1 - Bode and Step Response

I hate matlab with passion, yet sadly, nearly everyone uses it.  I'm a fan of Python and open source stuff so here's a simple article on how to do some common control systems stuff in Python.

First we need to make sure the environment is setup.


  1. Install IPython (or you can use any other python shell, but a unicode supported shell is preferred)
  2. Install python-control (numpy, scipy)
  3. Install sympy

These should do if your on Ubuntu/debian:

sudo apt-get install python-sympy python-numpy python-scipy python-matplotlib ipython

Then you need to install python control, see How to download and install python-control

Intro to using Sympy

Open ipython and run the following:

import sympy
from sympy import *
sympy.init_printing()
s = Symbol('s')


Now we can do things like define transfer functions using the symbolic variable s.


We can expand the bottom using the .simplify() method

and we can do something more complex like...
which is really nice because it does all the multiplication for us... and it’s much prettier than matlab.  

An example of a system in feedback form:

Note: Use floats (number including a decimal )for all values you insert!


Doing Step Response Plots:
Okay cool, now let’s do something useful, add the following imports:

from control import matlab
import matplotlib.pyplot as plt

Copy or save and import this helper function (use %paste in iPython to enter it)

def stepResponse(Ts,*args,**kwargs):
   num = Poly(Ts.as_numer_denom()[0],s).all_coeffs()
   den = Poly(Ts.as_numer_denom()[1],s).all_coeffs()
   tf = matlab.tf(map(float,num),map(float,den))
   y,t = matlab.step([tf],*args,**kwargs)
   plt.plot(t,y)
   plt.title("Step Response")
   plt.grid()
   plt.xlabel("time (s)")
   plt.ylabel("y(t)")
   info ="OS: %f%s"%(round((y.max()/y[-1]-1)*100,2),'%')
   try:
       i10 = next(i for i in range(0,len(y)-1) if y[i]>=y[-1]*.10)
       Tr = round(t[next(i for i in range(i10,len(y)-1) if y[i]>=y[-1]*.90)]-t[i10],2)
   except StopIteration:
       Tr = "unknown"
   try:
       Ts = round(t[next(len(y)-i for i in range(2,len(y)-1) if abs(y[-i]/y[-1])>1.02)]-t[0],2)
   except StopIteration:
       Ts = "unknown"
       
   info += "\nTr: %s"%(Tr)
   info +="\nTs: %s"%(Ts)
   print info
   plt.legend([info],loc=4)
   plt.show()


Then run stepResponse(G), where Ts is the transfer function of the system

Doing Bode, Magnitude / Phase plots:

def freqResponse(Ts,*args,**kwargs):
   num = Poly(Ts.as_numer_denom()[0],s).all_coeffs()
   den = Poly(Ts.as_numer_denom()[1],s).all_coeffs()
   tf = matlab.tf(map(float,num),map(float,den))
   matlab.bode([tf],*args,**kwargs)
   plt.show()

Then you just call freqResponse(ts) like:
You can also pass in arguments to the matlab.bode and matplotlib semilogx methods like:
which plots using dB and Hz scales.  You might notice this is pretty sketch looking, it actually missed a significant part of the magnitude plot, to smooth it out pass in your own omega values, like:
which looks much better.  

There’s lot more things you can do with the python-control library that isn’t implemented in the functions given here (such as plotting for various K values):

Anyways that’s enough for now...

Good luck and have fun!

Tuesday, December 25, 2012

How to fix PyDev unresolved import for gi.repository in Eclipse

If you get unresolved imports in Eclipse when using GObject Introspection libraries (Gtk, Gdk, etc..) like below, try this.


Right click on your PyDev project in eclipse and select Properties.  Select PyDev - Interpreter/Grammar  then click "Click here to configure an interpreter not listed."


Select the Interpreter being used for the project and click the Forced Builtins tab.  Then click the New... button and add "gi" to the list.  


Click apply and let Eclipse update itself.  Now start typing and eclipse will find the import and give you code hinting. 



References: