4.8. A quarter car suspension#
4.8.1. Question:#
Simulate the time response of the quarter car suspension model equations descibed below.
4.8.2. Mathematical model:#
4.8.3. Solution: Transfer function model: #
4.8.3.1. Generic solution:#
We can rewrite the previously describe model as a set of Ordinary Differential Equations (ODE’s) by substituting \(\dot x\) with \(v_x\) and \(\dot y\) with \(v_y\)
if we define a state vector \(X = \begin{bmatrix} x \\ y \\ v_y \\ v_y \end{bmatrix}\) and \(U = \begin{bmatrix} r \end{bmatrix}\) then we can rewrite the previous equation as follows
with \(A = \begin{bmatrix} a^1_1& \dots& a^1_4 \\ \vdots & \vdots &\vdots \\ a^4_1& \dots& a^4_4 \end{bmatrix} = \begin{bmatrix} 0&0&1&0 \\ 0&0&0&1\\ \frac{-k_s-k_w}{m_1} & \frac{k_s}{m_1} & \frac{-b}{m_1} & \frac{b}{m_1} \\ \frac{k_s}{m_2} & \frac{-k_s}{m_2} & \frac{b}{m_2} & \frac{-b}{m_2} \end{bmatrix}\) and \(B = \begin{bmatrix} b^1_1& \\ \vdots\\ b^4_1& \end{bmatrix}= \begin{bmatrix}0\\0\\ \frac{k_w}{m_1} \\ 0 \end{bmatrix}\)
4.8.3.1.1. Determine the state space model:#
The state space model is specified as:
This equation directly specifies the dynamic equation of the state space model (matrices A,B). The other matrices (C,D) are defined based on the required output of the system.
4.8.3.2. Detailed solution:#
First load the necessary libraries into Python:
The Python Control Systems Library (python-control) is a Python package that implements basic operations for analysis and design of feedback control systems.
NumPy library is a python library used for working with arrays.
The SciPy library is one of the core packages that make up the SciPy stack. It provides many user-friendly and efficient numerical routines, such as routines for numerical integration, interpolation, optimization, linear algebra, and statistics. The signal processing toolbox currently contains some filtering functions, a limited set of filter design tools, and a few B-spline interpolation algorithms for 1- and 2-D data.
import psutil
L = psutil.Process().parent().cmdline()
if any("jupyter-notebook" in string for string in L):
%matplotlib notebook
elif any("jupyter-labhub" in string for string in L):
%matplotlib widget
else:
%matplotlib inline
from scipy import signal
import numpy as np
Equation (1) derived above specifies a linear relation \(\dot x = Ax+Bu\) with \(A = \begin{bmatrix} 0&0&1&0 \\ 0&0&0&1\\ \frac{-k_s-k_w}{m_1} & \frac{k_s}{m_1} & \frac{-b}{m_1} & \frac{b}{m_1} \\ \frac{k_s}{m_2} & \frac{-k_s}{m_2} & \frac{b}{m_2} & \frac{-b}{m_2} \end{bmatrix}\) and \(B =\begin{bmatrix}0\\0\\ \frac{k_w}{m_1} \\ 0 \end{bmatrix}\)
We assume following parameter values: \(m=[m_1,m_2]^T\) with \(m_1=20\) kg ,\(m_2=375\) kg together with \(b=9800\) N/(m/s) and the spring constants \(K_w=1e6=1000000\), \(K_s=1.3*e5=130000\):
m1=20 #kg
m2=375 #kg
m = [m1,m2]
b=9800 #N/(m/s)
kw=1e6 #N/m
ks=1.3e5 #N/m
A = [[0,0,1,0 ], [0,0,0,1],[(-ks-kw)/m1, ks/m1, -b/m1, b/m1],[ks/m2,-ks/m2,b/m2,-b/m2]]
B = [[0],[0],[kw/m1],[0]]
Create a state space model from A and B with the velocity \(v_x\) as an output
C = np.eye(4)
D = [[0],[0],[0],[0]]
sys = signal.StateSpace(A,B,C,D)
Define the time vector (T) and the input vector (U);
T=np.linspace(0,2,100)
y0=[0,0,0,0] #Initial values for the
a= 0*np.ones(49) # 1 second zero values for input
b= 0.2*np.ones(51) # 1 second 0.2 values for input
u = np.concatenate((a, b), axis=0) # combine both vectors a and b
We want to simulate the response of state space model sys given the specified input (u) assuming zero initial values for both position and velocity. We will use the lsim function by the SciPy library :
T, yout, xout = signal.lsim(system, U, T, X0=None, interp=True)
- system: an instance of the LTI class or a tuple describing the system.
- u (array-like, optional) –
An input array describing the input at each time T (interpolation is assumed between given times). If there are multiple inputs, then each column of the rank-2 array represents an input. If u = 0 or None, a zero input is used.
- T (array-like) – The time steps at which the input is defined and at which the output is desired. Must be nonnegative, increasing, and equally spaced.
- x0 (array-like, optional) – Initial condition (default = 0) where the number of states is equal to the number of poles in the transfer function.
- interp (bool, optional) – Whether to use linear (True, the default) or zero-order-hold (False) interpolation for the input array.
- T (1D ndarray) – Time values of the output.
- yout (1D ndarray) – Response of the system.
- xout (ndarray) – Time evolution of the state vector.
T, yout, vout = signal.lsim(sys, u, T, y0)
import matplotlib.pyplot as plt # Load the pyplot object from the matplotlib library
fig, axes = plt.subplots(nrows=1, ncols=2)
ax0, ax1 = axes.flatten()
ax0.plot(T, yout[:,0], 'b', label='x') # plot the time signal and create a label for the legend
ax0.legend(loc='best') # position the legend at a minimal overlapping position
ax0.set(xlabel='t[s]', ylabel='Position mass 1 [m]') # label the y-axis
ax0.grid() # plot a grid
ax1.plot(T, yout[:,1], 'b', label='y') # plot the time signal and create a label for the legend
ax1.legend(loc='best') # position the legend at a minimal overlapping position
ax1.set(xlabel='t[s]', ylabel='Position mass 2 [m]') # label the y-axis
ax1.grid() # plot a grid
fig.tight_layout()
plt.show() # show the plot