Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions doc/4_path_tracking/4_1_stanley_controller.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 4. Stanley Controller
## 4.1 Stanley Controller

In this chapter, the Stanley steering controller class is implemented for path tracking. This class implements the Stanley path tracking algorithm, which computes a steering angle to guide a vehicle's front axle back onto a reference course by correcting both heading error and lateral (cross-track) error.

Expand Down Expand Up @@ -36,7 +36,7 @@ Ref: https://www.ri.cmu.edu/pub_files/2009/2/Automatic_Steering_Methods_for_Auto
- can be unstable at low speed(divison be 0) and steady state error.


## 4.1 StanleyController Class
### 4.1.1 StanleyController Class

The controller class is located at:
[stanley_controller.py](/src/components/control/stanley/stanley_controller.py)
Expand Down Expand Up @@ -70,7 +70,7 @@ This class imports `sin`, `cos`, `tan`, and `atan2` from Python's `math` module,

---

### 4.1.1 Constructor
#### 4.1.1.1 Constructor

```python
def __init__(self, spec, course=None):
Expand Down Expand Up @@ -100,9 +100,9 @@ The constructor takes a `VehicleSpecification` object and an optional `CubicSpli

---

## 4.2 Private Methods
### 4.1.2 Private Methods

### 4.2.1 `_calculate_front_axle_state`
#### 4.1.2.1 `_calculate_front_axle_state`

```python
def _calculate_front_axle_state(self, state):
Expand Down Expand Up @@ -131,7 +131,7 @@ where `L` is the wheelbase.

---

### 4.2.3 `_calculate_target_course_index`
#### 4.1.2.2 `_calculate_target_course_index`

```python
def _calculate_target_course_index(self, state):
Expand All @@ -143,7 +143,7 @@ This method finds the index of the nearest point on the course to the front axle

---

### 4.2.4 `_decide_target_speed_mps`
#### 4.1.2.3 `_decide_target_speed_mps`

```python
def _decide_target_speed_mps(self):
Expand All @@ -154,7 +154,7 @@ The target speed is read directly from the course at the nearest point index. Th

---

### 4.2.4 `_calculate_target_acceleration_mps2`
#### 4.1.2.4 `_calculate_target_acceleration_mps2`

```python
def _calculate_target_acceleration_mps2(self, state):
Expand All @@ -170,7 +170,7 @@ accel = Kp * (target_speed - current_speed)

---

### 4.2.5 `_calculate_tracking_error`
#### 4.1.2.5 `_calculate_tracking_error`

```python
def _calculate_tracking_error(self, state):
Expand All @@ -190,7 +190,7 @@ Only `error_lat_m` and `error_yaw_rad` are used for steering.

---

### 4.2.6 `_calculate_control_input`
#### 4.1.2.6 `_calculate_control_input`

```python
def _calculate_control_input(self, state, error_lat_m, error_yaw_rad):
Expand Down Expand Up @@ -231,9 +231,9 @@ tan(δ) = L / R => R = L / tan(δ)

---

## 4.3 Public Methods
### 4.1.3 Public Methods

### 4.3.1 `update`
#### 4.1.3.1 `update`

```python
def update(self, state, time_s):
Expand Down Expand Up @@ -263,7 +263,7 @@ If no course is set, the method returns early without computing anything.

---

### 4.3.2 Getter Methods
#### 4.1.3.2 Getter Methods

```python
def get_target_accel_mps2(self):
Expand All @@ -280,7 +280,7 @@ These three getter methods expose the computed control outputs. They are called

---

### 4.3.3 `draw`
#### 4.1.3.3 `draw`

```python
def draw(self, axes, elems):
Expand Down
44 changes: 22 additions & 22 deletions doc/4_path_tracking/4_2_mpc_controller.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 5. MPC Controller
## 4.2 MPC Controller

In this chapter, the MPC (Model Predictive Control) path tracking controller class is implemented. This class implements the MPC path tracking algorithm, which computes a steering angle and acceleration command by solving an **optimization problem** over a finite prediction horizon at every time step.

Expand Down Expand Up @@ -45,7 +45,7 @@ Before getting into the code, let's get some basic understanding behind the algo

---

## 5.1 MpcController Class
### 4.2.1 MpcController Class

The controller class is located at:
[mpc_controller.py](/src/components/control/mpc/mpc_controller.py)
Expand Down Expand Up @@ -74,7 +74,7 @@ This class uses **do-mpc** as the MPC framework and **CasADi** as the symbolic a

---

### 5.1.1 Constructor
#### 4.2.1.1 Constructor

```python
def __init__(self, spec, course=None, color="r",
Expand Down Expand Up @@ -135,9 +135,9 @@ The constructor takes a `VehicleSpecification` object and an optional `CubicSpli

---

## 5.2 Algorithm Background
### 4.2.2 Algorithm Background

### 5.2.1 State and Control Vectors
#### 4.2.2.1 State and Control Vectors

MPC operates on a **state vector** $x$ and a **control vector** $u$:

Expand All @@ -161,7 +161,7 @@ At each time step, MPC finds the sequence $U = {u_0, u_1, …, u_{N-1}}$ that mi

---

### 5.2.2 Vehicle Model - Discrete Bicycle Kinematics
#### 4.2.2.2 Vehicle Model - Discrete Bicycle Kinematics

MPC uses an internal motion model to predict how the vehicle will move in response to each control. The **kinematic bicycle model** is used:

Expand All @@ -180,7 +180,7 @@ CasADi writes these equations as symbolic expressions, meaning it can automatica

---

### 5.2.3 The Optimization Problem
#### 4.2.2.3 The Optimization Problem

At every time step, MPC solves the optimization problem:

Expand Down Expand Up @@ -221,11 +221,11 @@ The constraints are **hard constraints**, meaning the optimizer (e.g., IPOPT) en

---

### 5.2.4 Stage Cost $\ell(x_t, u_t, u_{t-1})$
#### 4.2.2.4 Stage Cost $\ell(x_t, u_t, u_{t-1})$

The stage cost is evaluated at every step $t = 0,\ldots,N-1$ of the horizon. It has three parts:

#### 1. Tracking Error
##### 1. Tracking Error

Penalises deviation from the reference trajectory:

Expand All @@ -244,7 +244,7 @@ The heading error uses **$\text{atan2}$** rather than a direct subtraction. This

---

#### 2. Control Effort
##### 2. Control Effort

Penalises large control inputs:

Expand All @@ -254,7 +254,7 @@ $$

---

#### 3. Smoothness
##### 3. Smoothness

Penalises rapid changes between consecutive control inputs:

Expand All @@ -275,7 +275,7 @@ mpc.set_rterm(

---

### 5.2.5 Terminal Cost $\phi(x_N)$
#### 4.2.2.5 Terminal Cost $\phi(x_N)$

The terminal cost is evaluated only at the **last step** $t = N$ of the horizon:

Expand All @@ -292,7 +292,7 @@ The terminal weights $W$ are set heavier than the stage weights (default: $W = 2

---

### 5.2.6 The Receding Horizon Principle
#### 4.2.2.6 The Receding Horizon Principle

MPC solves for the full sequence $\{u_0, u_1, \ldots, u_{N-1}\}$ but **only applies $u_0$** - the first control action. At the next time step, the horizon shifts forward by one step, the current state is re-measured, and the problem is solved again from scratch. This is why it is called a **receding horizon controller**.

Expand All @@ -312,9 +312,9 @@ This strategy is known as the **receding horizon** (or **moving horizon**) princ

---

## 5.3 Private Methods
### 4.2.3 Private Methods

### 5.3.1 `_build_arclength_table()`
#### 4.2.3.1 `_build_arclength_table()`

```python
def _build_arclength_table(self):
Expand Down Expand Up @@ -342,7 +342,7 @@ The tiling handles closed or looping courses: when a vehicle near the end of the

---

### 5.3.2 `_build_model()`
#### 4.2.3.2 `_build_model()`

```python
def _build_model(self):
Expand Down Expand Up @@ -390,7 +390,7 @@ The `yaw_err` auxiliary expression is registered separately so it can be referen

---

### 5.3.3 `_build_mpc(model)`
#### 4.2.3.3 `_build_mpc(model)`

```python
def _build_mpc(self, model):
Expand Down Expand Up @@ -438,7 +438,7 @@ This method assembles the full MPC optimization problem using the do-mpc API:

---

### 5.3.4 `_get_reference_trajectory(x0, y0, current_speed)`
#### 4.2.3.4 `_get_reference_trajectory(x0, y0, current_speed)`

```python
def _get_reference_trajectory(self, x0, y0, current_speed):
Expand Down Expand Up @@ -484,9 +484,9 @@ where $s_0$ is the cumulative arc-length at the vehicle's current nearest point,

---

## 5.4 Public Methods
### 4.2.4 Public Methods

### 5.4.1 `update`
#### 4.2.4.1 `update`

```python
def update(self, state, time_s):
Expand Down Expand Up @@ -541,7 +541,7 @@ $$

---

### 5.4.2 Getter Methods
#### 4.2.4.2 Getter Methods

```python
def get_target_accel_mps2(self):
Expand All @@ -558,7 +558,7 @@ These three getter methods expose the computed control outputs. They are called

---

### 5.4.3 `draw`
#### 4.2.4.3 `draw`

```python
def draw(self, axes, elems):
Expand Down
Loading
Loading