[Control engineering] Calculation of transfer functions and state space models by Python

Introduction

Since I decided to control the robot at work, I summarized it to know the following. ・ Review of basic knowledge of control engineering ・ How to draw control system and PID control with python ・ To understand the Kalman filter and self-position estimation by understanding the state space model

References

Hiroki Minami, Ohmsha, "Introduction to Control Engineering with Python"

Contents

Contents of Chapter 3 of "Introduction to Control Engineering with Python"

Common

Import the following libraries

import sympy import control

Transfer function

The code is shown below

# chapter 3-2 Transfer function model
Np = [0,1]
Dp = [1,2,3]
P = control.tf(Np, Dp)
print(P)
output
      1
-------------
s^2 + 2 s + 3

State space

The code is shown below

#3-3 State space model
A = '1 1 2; 2 1 1; 3 4 5'
B = '2; 0; 1'
C = '1 1 0'
D = '0'
P = control.ss(A,B,C,D)
print(P)
sysA, sysB, sysC, sysD = control.ssdata(P)
print(sysA)
output
A = [[1. 1. 2.]
 [2. 1. 1.]
 [3. 4. 5.]]

B = [[2.]
 [0.]
 [1.]]

C = [[1. 1. 0.]]

D = [[0.]]

[[1. 1. 2.]
 [2. 1. 1.]
 [3. 4. 5.]]

Summary

-Using libraries such as control and sympy, Laplace transform and transfer function notation can be done so easily.

Recommended Posts

[Control engineering] Calculation of transfer functions and state space models by Python
Transfer function / state space model of RLC series circuit and simulation by Python
Transfer function / state space model of spring / mass / damper system and simulation by Python
[Control engineering] Graphing transfer functions using Python
Implementation of particle filters in Python and application to state space models
[Scientific / technical calculation by Python] Fitting by nonlinear function, equation of state, scipy
Calculation of technical indicators by TA-Lib and pandas
Calculation of standard deviation and correlation coefficient in Python
[Control engineering] Visualization and analysis of PID control and step response
Overview of generalized linear models and implementation in Python
Version control of Node, Ruby and Python with anyenv
[Scientific / technical calculation by Python] List of usage of (special) functions used in physics by using scipy
[Scientific and technical calculation by Python] Drawing of fractal figures [Sierpinski triangle, Bernsley fern, fractal tree]
Python implementation of CSS3 blend mode and talk of color space
[Python] Heron's formula functionalization and calculation of the maximum area
[Python of Hikari-] Chapter 05-10 Control syntax (interruption and continuation of iteration)
[Python] Summary of how to use split and join functions
[Scientific / technical calculation by Python] Basic operation of arrays, numpy
Comparison of how to use higher-order functions in Python 2 and 3
[Introduction to Data Scientists] Basics of Python ♬ Functions and classes
Scientific / technical calculation by Python] Drawing and visualization of 3D isosurface and its cross section using mayavi
Calculation of similarity by MinHash
Python 3 sorted and comparison functions
Source installation and installation of Python
Python higher-order functions and comprehensions
[Science and technology calculation by Python] Taylor expansion, mathematical formulas, sympy
[Science and technology calculation by Python] (Partial) differential, mathematical formula, sympy
Automatic acquisition of gene expression level data by python and R
Practice of data analysis by Python and pandas (Tokyo COVID-19 data edition)
Comparison of calculation speed by implementation of python mpmath (arbitrary precision calculation) (Note)
[Python] Implementation of Nelder–Mead method and saving of GIF images by matplotlib
[Introduction to Data Scientists] Basics of Python ♬ Functions and anonymous functions, etc.
[Scientific / technical calculation by Python] Derivation of analytical solutions for quadratic and cubic equations, mathematical formulas, sympy