Modeling Control Systems

These tools are use to model simple linear and nonlinear discrete-time control systems.

LinearSystem

class stlpy.systems.LinearSystem(A, B, C, D)

Bases: NonlinearSystem

A linear discrete-time system of the form

\[ \begin{align}\begin{aligned}x_{t+1} = A x_t + B u_t\\y_t = C x_t + D u_t\end{aligned}\end{align} \]

where

  • \(x_t \in \mathbb{R}^n\) is a system state,

  • \(u_t \in \mathbb{R}^m\) is a control input,

  • \(y_t \in \mathbb{R}^p\) is a system output.

Parameters
  • A – A (n,n) numpy array representing the state transition matrix

  • B – A (n,m) numpy array representing the control input matrix

  • C – A (p,n) numpy array representing the state output matrix

  • D – A (p,m) numpy array representing the control output matrix

DoubleIntegrator

class stlpy.systems.DoubleIntegrator(d)

Bases: LinearSystem

A linear system describing a double integrator in \(d\) dimensions with full state and control output:

\[\begin{split}A = \begin{bmatrix} I_{d \times d} & I_{d \times d} \\ 0_{d \times d} & I_{d \times d} \end{bmatrix} \quad B = \begin{bmatrix} 0_{d \times d} \\ I_{d \times d} \end{bmatrix}\end{split}\]
\[\begin{split}C = \begin{bmatrix} I_{2d \times 2d} \\ 0_{d \times 2d} \end{bmatrix} \quad D = \begin{bmatrix} 0_{2d \times d} \\ I_{d \times d} \end{bmatrix}\end{split}\]
Parameters

d – Integer describing the dimensionality of the system

NonlinearSystem

class stlpy.systems.NonlinearSystem(f, g, n, m, p)

Bases: object

A class which represents some (possibly nonlinear) discrete-time control system

\[ \begin{align}\begin{aligned}x_{t+1} = f(x_t, u_t)\\y_t = g(x_t, u_t)\end{aligned}\end{align} \]

where

  • \(x_t \in \mathbb{R}^n\) is a system state,

  • \(u_t \in \mathbb{R}^m\) is a control input,

  • \(y_t \in \mathbb{R}^p\) is a system output.

Parameters
  • f – A function representing \(f\), which takes two numpy arrays (\(x_t,u_t\)) as input and returns another numpy array (\(x_{t+1}\)).

  • g – A function representing \(f\), which takes two numpy arrays (\(x_t,u_t\)) as input and returns another numpy array (\(y_{t}\)).

  • n – Size of the state vector \(x_t\).

  • m – Size of the control vector \(u_t\).

  • p – Size of the output vector \(p_t\).

f(x, u)

Given state \(x_t\) and control \(u_t\), compute the forward dynamics

\[x_{t+1} = f(x_t, u_t).\]
Parameters
  • x – The current state \(x_t\)

  • u – The control input \(u_t\)

Returns

The subsequent state \(x_{t+1}\)

g(x, u)

Given state \(x_t\) and control \(u_t\), compute the output

\[y_t = g(x_t, u_t).\]
Parameters
  • x – The current state \(x_t\)

  • u – The control input \(u_t\)

Returns

The output \(y_t\)

Unicycle

class stlpy.systems.Unicycle(dt)

Bases: NonlinearSystem

A simple nonlinear system representing a 2D mobile robot with unicycle dynamics. The robot is controlled by specifing a forward velociy \(v\) and an angular velocity \(\omega\).

This is example of a non-holonomic system: the robot cannot directly control its motion in the horizontal direction.

The state is given by

\[\begin{split}x = \begin{bmatrix} p_x \\ p_y \\ \theta \end{bmatrix},\end{split}\]

where \(p_x\) and \(p_y\) are positions in the plane and \(\theta\) is an orientation. The dynamics are given by

\[\begin{split}\dot{x} = \begin{bmatrix} v \cos(\theta) \\ v \sin(\theta) \\ \omega \end{bmatrix}\end{split}\]

and the control input is \(u = \begin{bmatrix} v \\ \omega \end{bmatrix}\). We use forward Euler integration to transform this into a discrete-time system:

\[x_{t+1} = x_t + \dot{x}~dt.\]

The system output is simply the state of the robot, \(y_t = x_t\).

Parameters

dt – Discretization step size (for forward Euler integration)

f(x, u)

Given state \(x_t\) and control \(u_t\), compute the forward dynamics

\[x_{t+1} = f(x_t, u_t).\]
Parameters
  • x – The current state \(x_t\)

  • u – The control input \(u_t\)

Returns

The subsequent state \(x_{t+1}\)

g(x, u)

Given state \(x_t\) and control \(u_t\), compute the output

\[y_t = g(x_t, u_t).\]
Parameters
  • x – The current state \(x_t\)

  • u – The control input \(u_t\)

Returns

The output \(y_t\)