### 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.

### Kivy vs React-Native for building cross platform mobile apps

I've built three apps now using Kivy and one with React-Native, just wanted to share my thoughts on both.

Just a warning, I am strongly biased towards python and this is all based on opinion and experience and is thus worth what you pay for it. I don't claim to be an expert in either of these, just have worked with each for several months.  If something is incorrect I'd love to hear advice.

Kivy
Demo of one of the apps

Pros:
Nice to be able to run natively on the desktop WITHOUT a simulatorPython is easy to work withUse (almost) any python libraryVery easy to create custom widgetsKivy properties and data binding just work. Way nicer than React's "state" / flux / redux whatever you want to call it (stupid?). Native interfaces (pyjnius) and (pyobjc)Runs and feels pretty smooth Cons:Default widget toolkit looks like Android 4.4. Requiring you use your own widgets or a theming kit like KivyMD if styling bothers youCreating dynamic widgets declaratively is not yet s…

### 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.
Install IPython (or you can use any other python shell, but a unicode supported shell is preferred)Install python-control (numpy, scipy)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 SympyOpen 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’…

### How to populate a Combo Box in GTK3 using Glade

This post will show how to use Glade to list combo box items with GTK3 since I could not find any other tutorials and it took me a while to figure it out.  No coding necessary!

Step 1:  Insert the combo box. A GtkComboBox will be created.

Step 2: Select the combo box.  In the General Properties click the ... button next to ComboBox Model and click new.  A new GtkListStore will be created and set to the combo box's model.

Step 3: With the combo box selected, open the Combo Editor by clicking the edit button from the toolbar.
Step 4; Add some columns to the combo box's liststore.  Use type: gchararry for text.  Insert any other model columns at this time as well.

Step 5: Insert data into the liststore by scrolling down in the Combo Editor and clicking the + to add a new row.  Enter the data needed for each row.

Step 6: Click the Hierarchy tab and then click add.  A new GtkCellRendererText will be created.

Step 7: Under properties and attributes, change the Text: from unset to th…