{
"cells": [
{
"cell_type": "markdown",
"id": "933381a6",
"metadata": {},
"source": [
"[← Control Systems as Dynamical Systems](../../../getting_started/theory_to_python/control_systems_as_dynamical_systems.rst)"
]
},
{
"cell_type": "markdown",
"id": "121971fc",
"metadata": {
"lines_to_next_cell": 0
},
"source": [
"# Example: Car Cruise Control"
]
},
{
"cell_type": "markdown",
"id": "bc110efa",
"metadata": {},
"source": [
"Suppose we want to build a robot. If we were hobbyists, we might want a weekend project; if we were engineers, we might need an extra arm on the assembly line; if we were academics, we might dream of a quadruped with a cannon-head to threaten the government for grant money.\n",
"\n",
"Of course, we must begin somewhere. In this notebook, we take a classic example of a feedback system -- a car with cruise control -- and use ``pykal`` to take it from a block diagram to a composition of dynamical systems."
]
},
{
"cell_type": "markdown",
"id": "8016da19",
"metadata": {},
"source": [
"## System Overview\n",
" We consider here a gross simplification: our car will only ever drive on a perfectly flat plane with minimal drag.\n",
"\n",
"We are given an acceleromoter (which will give us a measurement of our current speed), a button on the steering wheel (which will enable us to modify the cruise control speed), and the car's CPU (i.e. we can implement any algorithm we want)."
]
},
{
"cell_type": "markdown",
"id": "422665ce",
"metadata": {
"lines_to_next_cell": 0
},
"source": [
"## Dynamical System Graph\n",
":::{warning}\n",
"This section assumes you have already gone through the [Dynamical System](./dynamical_system.ipynb) notebook. If you have not, please do so now.\n",
":::\n",
"\n",
" Recall the following block diagram for a simple feedback system:\n",
"\n",
"\n",
"\n",
"where $r$ is the **setpoint** (or **reference point**),\n",
"$u$ is the **control input**,\n",
"$x$ is the (hidden) **state** of the plant,\n",
"$\\hat{x}$ is the **state estimate**,\n",
"and $e$ is the **error** term.\n",
"\n",
"In the case of our car cruise control system, we can leverage this diagram with a simple relabling:\n",
"\n",
"
\n",
"\n",
"where the **PID** is a proportional-integrative-differential control algorithm, **KF** is a Kalman filter, and the **car** is, well, the car.\n",
":::{note} If you were to ask five control theorists to design a block diagram, you would get six different diagrams. Don't fret the particulars; the diagram is simply a tool to organize our thinking.\n",
":::\n",
"\n",
"We now proceed with casting the block diagram defined above as **dynamical system graph**:\n",
"\n",
"
\n",
"\n",
"We construct this graph block-by-block in the sections that follow.\n",
"\n",
":::{note} Although the signals between blocks have remained, for the most part, unchanged, the **summing junction** and **inverter** have dissapeared. Indeed, they've been absorbed into the PID block, as our [implementation of the algorithm](../../algorithm_library/pid_pykal.ipynb) computes the error term internally.\n",
":::"
]
},
{
"cell_type": "markdown",
"id": "27d3fd3f",
"metadata": {
"lines_to_next_cell": 0
},
"source": [
"### Block 1: Setpoint Generator\n",
"\n",
"