import numpy as np
from numpy import sin, cos
import scipy.integrate as integrate
import scipy.linalg
import scipy.signal as signal
import scipy
import matplotlib.pyplot as plt
import matplotlib.patches as patches4
from matplotlib import animation, rc
from IPython.display import HTML
'ggplot') plt.style.use(
In diesem Notebook wollen wir erstmal eine Simulation des Systems durchführen. Dazu benutzen wir scipy
und scipy.signal
.
System
Bewegungsgleichung
Zustandsraum
= 1.0
m1 = 0.1
d1 = 1.0
c1
= 1.0
m2 = 0.1
d2 = 1.0
c2
= 0.5
d3 = 1.0 c3
def derivs(state, t, action):
= state[0]
q1 = state[1]
q2 = state[2]
q1d = state[3]
q2d
= action[0]
F1 = action[1]
F2
= np.array([[m1, 0.], [0., m2]])
M
= np.array([[d1*q1d+d2*(q1d-q2d)+c1*q1+c2*(q1-q2)], [d3*q2d-d2*(q1d-q2d)+c3*q2-c2*(q1-q2)]])
gqqd
= np.array([[F1],[F2]])
Qq
= np.linalg.inv(M)
M_inv = M_inv @ (-gqqd+Qq)
qdd
= np.zeros_like(state)
dydx 0] = q1d
dydx[1] = q2d
dydx[2] = qdd[0]
dydx[3] = qdd[1]
dydx[
return dydx
# create a time array from 0..100 sampled at 0.05 second steps
= 0.05
dt = np.arange(0.0, 20, dt)
t
= 2.0
q1 = 0.0
qd1
= -2.0
q2 = 0.0
qd2
# initial state
= np.array([q1, q2, qd1, qd2])
state = state
state_0
# action
= np.array([0,0]) action
= integrate.odeint(derivs, state, t, args=(action,))
y
= y[:,0]
q1 = y[:,1]
q2
# plot
plt.plot(t, q1)
plt.plot(t, q2)#plt.grid()
= plt.figure()
fig = fig.add_subplot(111, autoscale_on=False)
ax
#ax.set_aspect('equal', 'box')
'equal')
ax.axis(set(xlim=(-5,5),ylim=(-5, 6))
ax.set()
ax.#ax.grid()
= patches.Rectangle((0, 0), 1.0, 1.0, fc='k')
patch1 = patches.Rectangle((0, 0), 1.0, 1.0, fc='k')
patch2 = 'time = %.1fs'
time_template = ax.text(0.05, 0.9, '', transform=ax.transAxes) time_text
def init():
ax.add_patch(patch1)
ax.add_patch(patch2)'')
time_text.set_text(return patch1, patch2, time_text
def animate(i):
-0.5)
patch1.set_x(q1[i]-0.5)
patch2.set_x(q2[i]
% (i*dt))
time_text.set_text(time_template return patch1, patch2, time_text
= animation.FuncAnimation(fig, animate, np.arange(1, len(y)),
anim =25, blit=True, init_func=init) interval
HTML(anim.to_jshtml())
Fazit
Nachdem erste Simulationen durchgeführt und die grundsätzliche Struktur des Systems durch die Modellbildung bekannt sind, müssen Systeme mit der Wirklichkeit abgeglichen werden.
In der Regelungstechnik spricht man dann von einer Grey-Box Systemidentifikation und in der Robotik von der Parameteridentifikation.