In [10]:
%pylab inline
import control
import scipy
rcParams['figure.figsize'] = (10,5)
rcParams['font.size'] = 12
In [11]:
def plot_poly_set(verts):
# close poly for plot
verts_closed = column_stack([verts, verts[:,0]])
plot(verts_closed[0,:], verts_closed[1,:], '-b')
def add_vector_to_poly(v, poly):
new_poly = zeros(poly.shape)
for j in range(len(v)):
new_poly[j,:] = poly[j,:] + v[j]
return new_poly
def plot_traj(A= matrix([[0, 1],[-1,-1]]), x0=[0,0], d_x0=0.1, x_targ=[0,0], dt=0.1, tf=10, d_u=0.01):
x0_box = d_x0*array([[-1,-1],[-1,1],[1,1],[1,-1]]).T
x0_box = add_vector_to_poly(x0, x0_box)
plot_poly_set(x0_box)
x = x0_box
Psi = matrix(scipy.linalg.expm(A*dt))
t = arange(0, tf, dt)
for i in range(len(t)):
x_diff = add_vector_to_poly(-array(x_targ), x)
x_diff_new = Psi*x_diff
x = add_vector_to_poly(x_targ, x_diff_new)
# input effect
# minkowski sum for 2d
n = x.shape[0]
x_min = zeros(n)
x_max = zeros(n)
for i in range(n):
x_min[i] = x[i,:].min()
x_max[i] = x[i,:].max()
verts = array([
[x_min[0] - d_u, x_min[1] - d_u],
[x_min[0] - d_u, x_max[1] + d_u],
[x_max[0] + d_u, x_max[1] + d_u],
[x_max[0] + d_u, x_min[1] - d_u],
]).T
plot_poly_set(verts)
In [12]:
clf()
plot_traj(x0=[0,0], x_targ=[1,0])
plot_traj(x0=[1,0], x_targ=[0,0])
plot_traj(x0=[0,0], x_targ=[-1,0])
plot_traj(x0=[-1,0], x_targ=[0,0])
plot_traj(x0=[1,0], x_targ=[-1,0])
plot_traj(x0=[-1,0], x_targ=[1,0])
title('flow pipes')
Out[12]: