Coder Social home page Coder Social logo

boisgera / control-engineering-with-python Goto Github PK

View Code? Open in Web Editor NEW
62.0 5.0 33.0 27.25 MB

Control Engineering with Python

License: Creative Commons Attribution 4.0 International

Shell 0.06% Python 3.29% JavaScript 45.66% CSS 16.97% HTML 9.71% Jupyter Notebook 16.24% SCSS 7.97% TeX 0.09%
control-theory dynamical-systems engineering matplotlib numpy odes python scipy

control-engineering-with-python's Introduction

Control Engineering with Python

Build Status Join the chat at https://gitter.im/control-engineering-with-python/community

Notations

Symbol Meaning Symbol Meaning
🐍 Code 🔍 Worked Example
📈 Graph 🧩 Exercise
🏷️ Definition 💻 Numerical Method
💎 Theorem 🧮 Analytical Method
📝 Remark 🧠 Theory
ℹ️ Information 🗝️ Hint
⚠️ Warning 🔓 Solution

📚 Program & Slides

  1. Introduction to Control Engineering (HTML, PDF, IPYNB)

  2. Introduction to Dynamical Systems

  3. Linear-Time Invariant Systems

  4. Controller Design

  5. Observers (HTML, PDF, IPYNB)

    • Observability

    • Observer design: pole assignment & optimal filtering

  6. Application to mobile robotics

    • Lagrangian mechanics

    • Kinematic models of mobile robots

    • Control of mobile robots

📓 Notebooks

The course contents are also available as Jupyter notebooks. Open, edit and run these notebooks either

🚀 Project

  • :octocat: Fork this project as a starting point; when needed, "fetch upstream" to get the project updates.

🎉 Extra resources

💻 Animation of dynamical systems

Example notebook: double pendulum

📚 Free External Resources


Creative Commons License
This work is licensed under a Creative Commons Attribution 4.0 International License.

control-engineering-with-python's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

control-engineering-with-python's Issues

LaTeX

One of the generated notebooks has explicitly requires a function LaTeX install (for the text in matplotlib) that can be troublesome unless we manage to install LaTeX through conda. Remove this dependency ?

Adapt video element for Jupyter target

Use the pattern:

from IPython.display import HTML
HTML("""
<video style="width:100%" controls>
<source src="videos/tear.mp4" type="video/mp4"> 
Your browser does not
support the video tag.
</video>
""")

Decktape generates small images

The graphs generated by matplotlib are far smaller in the PDF output than they are in the HTML slides. Why ? Can this be solved ?

LaTeX Support

LaTeX availability assumed in notebooks but LaTeX is not available e.g. in Binder environnements.

So the matplotlib configuration with LaTeX is an issue and so are the labels that assume that LaTeX rendering is on.

Large cells

Initially, there were many generated Markdown cells (one for each block-level construct in pandoc). In the new design, consecutive cells are concatenated, but in retrospect, that
was probably not the wisest choice: cells with height larger than the screens, the difficulty to insert code cells "in the middle" of some text, etc. Returning to the simpler, original design is probably better.

Recent Pandoc and HTML handling

Raw HTML is exported as e.g. the (nonstandard)

`<i class="fa fa-wikipedia-w">`{=html}`</i>`{=html}

which does not work well with Jupyter notebooks.

Observers: Q and R are semidefinite positive or definite positive?

In observers, slide 5.5:
Q and R are positive semidefinite (may have 0 in the eigenvalues set).

According to slide 5.8, Q has to be full rank (inverse of Q is used). Not sure if it is a necessary condition for R.

If we keep semidefinite, ">0" has to be changed to ">=0".

Exercices & Solutions

Create the solutions for:

ODES / Models & Stream Plots

  • Pendulum, model
  • Pendulum, streamplot
  • Pendulum, overshoot (analytical)

ODES / Simulation

  • Transfer IVP/Rotation from exo to example

ODES / Well-posedness / Local & Maximal Solutions

  • Maximal Solutions

ODES / Well-posedness / Existence

  • Sigmoid
  • Pendulum
  • Linear Systems

ODES / Well-posedness / Continuity

  • Linear system
  • Non-uniqueness
  • Prey-Predator

Asymptotic Behavior

  • Pendulum
  • Vinograd

Linear Systems / Models

  • Turn Heat Equation into exo
  • Linearized Pendulum

Linear Systems / Solutions & Stability

  • Exponential Matrix
  • G.A.S <-> L.A.
  • Stability 2nd-order system
  • Stability of chain of integrators

Linear Systems / IO Behaviors / Impulse Response

  • Integrator
  • Double integrator
  • Gain
  • MIMO

Linear Systems / IO Behaviors / Laplace & Transfer Function

  • Ramp
  • Feedback

Controllability

  • Pendulum
  • Fully Actuated System
  • Integrator Chain
  • Heat Equation

Asymptotic Stabilization

  • Pole Assignment, default
  • Pendulum
  • Double Spring System

Optimal Control

  • Value of J

Observers

  • Fully measured systems
  • Integrator chain
  • Heat equation

Typo

Tau in bound instead of t in linear systems twice (I/O section, slide 6.10)

Reorganize toolchain

Support for:

  • short vs long content (reveal notes in slides ?)
  • font awesome -> emoji
  • automatic image insertion in slides ? image as backgroud (see https://salferrarello.com/full-screen-image-in-reveal-js/) ?
  • more generally, use jupyter cells output ?
  • hidden code (to be executed)
  • target-dependent sections (via key-value assignments) ?
  • style reveal with left-justified text by default ?

Backends:

  • Slides (reveal),
  • Jupyter notebooks,
  • Starboard (Jupystar first ?)

Consider speaker notes

Supported for reveal.js ; may need to be removed for the Jupyter notebook (? need to think about it).

Adapt Q helper

x and y args can already be 1d array, replace Q with a "sampler" that produces u and v from f (with t args ?) and x, y.

Jupyter Backend

TODO:

  • Solve missing imports
  • Map to GFM (e.g. to get the proper map support)
  • Internal links (generate dummy ids/span)
  • Typography : "--"
  • Color backgrounds ? (Not sure it's possible; not unless we convert the whole block to HTML?)
  • Need to normalize the size of images and drop the special attributes that are not rendered (?)
  • Support for videos.
  • Can't split code in multiple cells once figure() appears

Split notebooks into smaller units

Use each section of the slides to generate a new notebook;
manage the common parts into a preamble; or even simpler,
repeat the commands with a preamble at the start of each section.
Also, reduce the size of each section ? Some are probably too large.

Matplotlib: many open figures

Analyze / see if it's possible to get rid of :

./build.py:286: RuntimeWarning: More than 20 figures have been opened. 
Figures created through the pyplot interface (`matplotlib.pyplot.figure`) are retained until explicitly closed and may consume too much memory. (To control this warning, see the rcParam `figure.max_open_warning`).

Optimal Control, open/closed loop

Give the optimal control as an open-loop solution first (function of the time and initial-value of the state), and afterwards, "discover" that it can be implemented as a simple closed-loop, linear strategy and explain why it's better to do it like that.

Typo

ds instead of d tau in I/O behavior integral

PID Control

The control of a 2nd order system (with offset) via pole assignement to find the coefficients of a PID controller would be a nice exercise (PID tuning as a special case of the general approach).

Matplotlib configuration warning

get rid of this warning:

/usr/share/miniconda/envs/control-engineering-with-python/lib/python3.7/_collections_abc.py:841: 
MatplotlibDeprecationWarning: Support for setting the 'text.latex.preamble' or 'pgf.preamble' rcParam to a list of strings is deprecated since 3.3 and will be removed two minor releases later; set it to a single string instead.

Optimal Control, Inverted Pendulum

Consider the linearized dynamics of the inverted pendulum, described by the matrices A and B:

g=9.81
l=1
m=1
b=0
J = m * l * l

A = np.array([[0.0, 1.0], [g/l, -b/J]])
B = np.array([[0.0],[1/J]])

Select reference parameters Q and R, then solve the Riccati equation to get the optimal gain:

Q = array([[1.0, 0], [0, 1.0]])
R = array([[1.0]])
Pi = solve_continuous_are(A, B, Q, R)
K = inv(R) @ B.T @ Pi

We get K == [[19.67083668 6.35150953]]. At first sight, these coefficients appear to be almost insensitive with respect to Q and R, which is puzzling to say the least ; for example, with

Q = array([[1e-15, 0], [0, 1e-15]])
R = array([[1.0]])

we get K == [[19.62 6.26418391]]. However, this is true only for decreasing Qs (and/or increasing Rs) ; if instead we increase Q to get a faster convergence of the closed-loop system, say:

Q = array([[1e15, 0], [0, 1e15]])
R = array([[1.0]])

we get K: [[31622786.41168933 31622777.60168409]]. Note however that its probably unwise to have both Q[0,0] and Q[1,1] pushed to infinity at the same rate : since a large Q[1, 1] prevents the angle velocity to have large values, such parameters won't allow a really fast convergence of the solution towards the equilibrium. And indeed, for the choice above,
the eigenvalues of A - B @ K are [-1.00000000e+00 -3.16227766e+07], so the time constant is 1, despite the large coefficients. Instead, we can pick a large Q[0,0], but not a large Q[1, 1] :

Q = array([[1e15, 0], [0, 1.0]])
R = array([[1.0]])

We get K: [[3.16227864e+07 7.95270858e+03]] and the closed-loop eigenvalues [-3976.35429204+3976.35299563j -3976.35429204-3976.35299563j] (time constant: ~ 0.00025 seconds !!! Obviously far too fast, but you get the idea).

Complements about the corner case

Q ==[[0, 0], [0, 0]] does not satisfy the assumptions that we have made in the lectures: Q is not positive definite ; but you can check that there is an optimal solution to the problem anyway : it is u =0 ; it corresponds to Pi = 0 and thus K = 0. But the numerical approach does not give this answer. Instead we have K: [[19.62 6.26418391]]. I suspect that the reason is the following : here since Q is not definite positive the optimal solution does not asymptotically stabilizes the system ; but the numerical package always performs its search among the solutions that stabilizes the system. That would be consistent with the information that scipy.linalg.solve_continuous_are is solved by hamiltonian methods (see for example Ricatti Equations and Their Solution, theorem 14.5 : under mild assumptions -- that hold in our context -- there is a unique solution to the Ricatti equation that results in an asymptotically stable dynamics ; and here the scipy solution generates the eigenvalues [-3.13209195+5.3530231e-08j -3.13209195-5.3530231e-08j] so we do have this property).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.