Mechanics Problems using StateSpace

Below are some Mechanics problems that can be solved using StateSpace.

Example 1

../../../_images/Mechanics_Problems_Q1.svg

A spring-mass-damping system can be modeled using a mass (m), a spring with a constant (k), and a damper with a damping coefficient (b). The spring force is proportional to the displacement of the mass, and the damping force is proportional to the velocity of the mass. Find the frequency response of the system. The free-body diagram for this system is shown below:

../../../_images/Mechanics_Problems_Q1_FBD.svg

The equation of motion for the mass-spring-damper system is given by:

\[m\ddot{x} + b\dot{x} + kx = F(t)\]

where:

  • \(x\) is the displacement of the mass,

  • \(\dot{x}\) is the velocity of the mass,

  • \(\ddot{x}\) is the acceleration of the mass,

  • \(F(t)\) is the external force applied to the system.

To determine the state-space representation of the mass-spring-damper system, we reduce the second-order differential equation to a set of two first-order differential equations. We choose the position and velocity as our state variables:

\[x_1 = x \quad \text{and} \quad x_2 = \dot{x}\]

The state equations become:

\[ \begin{align}\begin{aligned}\begin{split}\dot{x}_1 = x_2 \\\end{split}\\\begin{split}\dot{x}_2 = -\frac{k}{m}x_1 - \frac{b}{m}x_2 + \frac{1}{m}F(t)\\\end{split}\end{aligned}\end{align} \]

The state-space can be represented by:

\[\begin{split}\mathbf{A} = \begin{bmatrix} 0 & 1 \\ -\frac{k}{m} & -\frac{b}{m} \end{bmatrix}, \quad \mathbf{B} = \begin{bmatrix} 0 \\ \frac{1}{m} \end{bmatrix}, \quad \mathbf{C} = \begin{bmatrix} 1 & 0 \end{bmatrix}\end{split}\]

The state equation can be written as

\[\begin{split}\dot{x} = \begin{bmatrix} \dot{x} \\ \ddot{x} \end{bmatrix} = \begin{bmatrix} 0 & 1 \\ -\frac{k}{m} & -\frac{b}{m} \end{bmatrix} \begin{bmatrix} x \\ \dot{x} \end{bmatrix} + \begin{bmatrix} 0 \\ \frac{1}{m} \end{bmatrix} F(t)\end{split}\]

Using SymPy’s Control Systems Toolbox (CST), we can define the state-space representation and convert it to the transfer function.

Solution

The following code demonstrates how to define the state-space representation of the spring-mass-damper system and convert it to a transfer function using SymPy:

>>> from sympy import symbols, Matrix
>>> from sympy.physics.control import *

Define the variables

>>> m, k, b = symbols('m k b')

Define the state-space matrices

>>> A = Matrix([[0, 1], [-k/m, -b/m]])
>>> B = Matrix([[0], [1/m]])
>>> C = Matrix([[1, 0]])
>>> D = Matrix([[0]])

Create the StateSpace model

>>> ss = StateSpace(A, B, C, D)
>>> ss
StateSpace(Matrix([
[   0,    1],
[-k/m, -b/m]]), Matrix([
[  0],
[1/m]]), Matrix([[1, 0]]), Matrix([[0]]))

Converting StateSpace to TransferFunction by rewrite method.

>>> tf = ss.rewrite(TransferFunction)[0][0]
>>> tf
TransferFunction(1, b*s + k + m*s**2, s)

References

  1. ctms.engin.umich.edu

Example 2

../../../_images/Mechanics_Problems_Q2.svg

This problem explains how to model a rotaional system to state-space model. The system has input torque \(τ_a\) and damping effects \(B_{r1}\) and \(B_{r2}\). The system consists of two flywheels connected by a spring, with the angular positions denoted by \(θ_1\) and \(θ_2\).

The energy variables for the rotating system are potential energy stored in springs \(1/2 K_r \theta^ 2\) and kinetic energy stored in inertial elments \(1/2 J \omega ^ 2\).

The State Variables: can be written as:

\[ \begin{align}\begin{aligned}x_1 = \theta_1 \quad \text{(angular position of the first flywheel)}\\x_2 = \dot{\theta}_1 \quad \text{(angular velocity of the first flywheel)}\\x_3 = \dot{\theta_2} \quad \text{(angular velocity of the second flywheel)}\end{aligned}\end{align} \]

The goal is to find a set of first-order differential equations that describe the system in terms of these state variables.

First, we write the equations of motion for the two flywheels, including the effects of damping.

  1. For the first flywheel (\(J_1\)):

    ../../../_images/Mechanics_Problems_Q2_FBD1.svg
    \[J_1 \ddot{\theta}_1 + B_{r1} \dot{\theta}_1 + K_r\theta_1 - B_{r1} \dot{\theta}_2 = - \tau_a\]
  2. For the second flywheel (\(J_2\)):

    ../../../_images/Mechanics_Problems_Q2_FBD2.svg
    \[J_2 \ddot{\theta}_2 + (B_{r2} + B_{r1}) \dot{\theta}_2 - B_{r1} \dot{\theta}_1 = 0\]

Now we want the equations for the derivates of state variables.

\[\dot{x}_1 = \dot{\theta}_1 = x_2\]
\[ \begin{align}\begin{aligned}\dot{x}_2 = \ddot{\theta_1} = \frac{1}{J_1} \left(-\tau_a - B_{r1} \dot{\theta_1} - K_r \theta_1 + B_{r1}\dot{\theta_2} \right)\\\dot{x}_2 = \frac{1}{J_1} \left(-\tau_a - B_{r1} x_2 - K_r x_1 + B_{r1} x_3 \right)\end{aligned}\end{align} \]
\[ \begin{align}\begin{aligned}\dot{x}_3 = \ddot{\theta}_2 = \frac{1}{J_2} \left(- (B_{r2} + B_{r1}) \dot{\theta_2} + B_{r1} \dot{\theta_1} \right)\\\dot{x}_3 = \frac{1}{J_2} \left( - (B_{r2} + B_{r1}) x_3 + B_{r1} x_2 \right)\end{aligned}\end{align} \]

The state-space model of the system can be expressed in the standard form:

\[ \begin{align}\begin{aligned}\dot{x} = A x + B u\\y = C x + D u\end{aligned}\end{align} \]

Where:

  • x is the state vector:

    \[\begin{split}x = \begin{bmatrix} x_1 \\ x_2 \\ x_3 \end{bmatrix} = \begin{bmatrix} \theta_1 \\ \dot{\theta}_1 \\ \theta_2 \end{bmatrix}\end{split}\]
  • u is the input torque (\(τ_a\)).

  • y is the output angular position (\(θ_1\)).

The matrices A, B, C, and D are defined as follows:

The A matrix represents the relationship between the state variables. It is defined as:

\[\begin{split}A = \begin{bmatrix} 0 & 1 & 0 \\ -\frac{K_r}{J_1} & -\frac{B_{r1}}{J_1} & \frac{B_{r1}}{J_1} \\ 0 & \frac{B_{r1}}{J_2} x_2 & -\frac{B_{r2} + B_{r1}}{J_2} \end{bmatrix}\end{split}\]

The B matrix represents the influence of the input torque on the system. It is defined as:

\[\begin{split}B = \begin{bmatrix} 0 \\ \frac{-1}{J_1} \\ 0 \end{bmatrix}\end{split}\]

The C matrix defines the relationship between the output (y) and the state variables (x). Since we are only interested in the angular position θ₁, the C matrix is:

\[C = \begin{bmatrix} 1 & 0 & 0 \end{bmatrix}\]

The D matrix is the direct transmission matrix. Since there is no direct transmission frothe input to the output, D is zero:

\[D = 0\]

Solution

>>> from sympy import symbols, Matrix
>>> from sympy.physics.control import StateSpace
>>> K_r, J1, J2, B_r1, B_r2, x2 = symbols('K_r J1 J2 B_r1 B_r2 x2')
>>> A = Matrix([[0, 1, 0], [-K_r/J1, -B_r1/J1, B_r1/J1], [0, B_r1/J2 * x2, - (B_r2 + B_r1)/J2]])
>>> B = Matrix([[0], [-1/J1], [0]])
>>> C = Matrix([[1, 0, 0]])
>>> ss = StateSpace(A, B, C)
>>> ss
StateSpace(Matrix([
[      0,          1,                 0],
[-K_r/J1,   -B_r1/J1,           B_r1/J1],
[      0, B_r1*x2/J2, (-B_r1 - B_r2)/J2]]), Matrix([
[    0],
[-1/J1],
[    0]]), Matrix([[1, 0, 0]]), Matrix([[0]]))

References

  1. https://lpsa.swarthmore.edu/