0

I am trying to change the used state space function for a step response and running into an issue. When it switches (at time 40s which for this example is just arbitrarily picked) I get a massive spike in position and velocity (10000x magnitude). I don't see why this is a problem, seeing that I'm shifting from one state space function which requires position (x1) and velocity (x2) to another function which requires only the same states.

Unsure if I have to adjust x1 or x2 between states, or if this is simply impossible. I've considered delving into the depths of Linear time-varying state-space models but feel as though my method is correct there's just a small adjustment I'm missing

Please help and thanks to those who do!

Ts = 0.1
tstart = 0
tstop = 60
t = np.arange(tstart,tstop,Ts)
N = t.size #int((tstop-tstart)/Ts) # Simulation length
x1 = np.zeros(N)
x2 = np.zeros(N)
ys = np.zeros(t.shape[0])
x1[0] = 0 # Initial Position
x2[0] = 0 # Initial Speed
u = np.ones(t.shape[0])*5

num = 3.56 # long resp
den = [1,2.67,3.56]
defTF = control.TransferFunction(num, den)
defSS = control.tf2ss(defTF)
defSS = defSS.sample(Ts,method='zoh')

num = 16000
den = [1,1400,16000]
defTF = control.TransferFunction(num, den)
defSSs = control.tf2ss(defTF)
defSS = np.append(defSS, defSSs.sample(Ts,method='zoh'))

sel = 0

for ik in range(t.shape[0]-1):
    if ik == 40:  # at 4 seconds
        sel = 1  # switch
    a11 = defSS[sel].A[0, 0]
    a12 = defSS[sel].A[0, 1]
    a21 = defSS[sel].A[1, 0]
    a22 = defSS[sel].A[1, 1]
    b1 = defSS[sel].B[0, 0]
    b2 = defSS[sel].B[1, 0]
    c1 = defSS[sel].C[0, 0]
    c2 = defSS[sel].C[0, 1]
    x1[ik + 1] = a11 * x1[ik] + a12 * x2[ik] + b1 * u[ik]
    x2[ik + 1] = a21 * x1[ik] + a22 * x2[ik] + b2 * u[ik]
    ys[ik] = c1*x1[ik] + c2*x2[ik]

Expecting a smooth transition between two state space functions and their step response. I tried to essentially switch out the state space variables while using the same state vector. I get a massive spike as shown in the plots zoomed in zoomed out

Hayden
  • 1
  • 1

0 Answers0