https://github.com/codename-detective/self_driving_cars_control
🧭 2D Longitudinal and Lateral Controller for CARLA simulator. Implements a PID-based throttle/brake system and a Stanley steering controller for waypoint-following autonomous vehicle navigation.
https://github.com/codename-detective/self_driving_cars_control
control pid-controller pid-longitudinal-controller python3 self-driving-car stanley-controller stanley-lateral-controller waypoint-following
Last synced: 10 months ago
JSON representation
🧭 2D Longitudinal and Lateral Controller for CARLA simulator. Implements a PID-based throttle/brake system and a Stanley steering controller for waypoint-following autonomous vehicle navigation.
- Host: GitHub
- URL: https://github.com/codename-detective/self_driving_cars_control
- Owner: CodeName-Detective
- Created: 2025-07-31T23:29:20.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2025-07-31T23:30:18.000Z (10 months ago)
- Last Synced: 2025-08-01T01:36:08.021Z (10 months ago)
- Topics: control, pid-controller, pid-longitudinal-controller, python3, self-driving-car, stanley-controller, stanley-lateral-controller, waypoint-following
- Language: Python
- Homepage:
- Size: 190 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 🚗 CARLA 2D Waypoint Follower Controller
This repository contains a 2D longitudinal and lateral controller implementation for a vehicle simulated in the [CARLA Simulator](https://carla.org/). The controller is designed to follow a predefined set of waypoints with associated target speeds, and serves as a core component of a waypoint-following autonomous driving demo.
## 🧠 Controller Overview
The `Controller2D` class handles two key aspects of vehicle control:
* **Longitudinal control**: Adjusts throttle and brake to match desired speeds.
* **Lateral control**: Adjusts the steering angle to minimize path deviation.
### 🔧 Technologies Used
* Python 3
* NumPy
* CARLA Simulator
---
## 🔁 Longitudinal Control: PID Controller
The throttle and brake commands are computed using a **PID controller** based on the velocity error between the current speed and the desired speed extracted from the closest waypoint.
PID formula:
```
a_desired = Kp * error + Ki * integral_error + Kd * derivative_error
```
* **Throttle** is applied if desired acceleration is positive.
* **Brake** is applied if deceleration is needed.
* Outputs are smoothed using `tanh` to prevent aggressive spikes.
### Tunable Parameters:
* `Kp = 1.0`
* `Ki = 0.2`
* `Kd = 0.01`
---
## 🛞 Lateral Control: Stanley Controller
The steering control is based on the **Stanley method**, using two components:
* **Heading Error**: Angular difference between vehicle yaw and path direction.
* **Cross-Track Error**: Lateral distance from the vehicle to the path.
The total steering angle is computed as:
```
steer = heading_error + arctan(K_gain * cross_track_error / velocity)
```
### Tunable Parameters:
* `K_gain = 0.3` (Stanley control gain)
* Output steering is clamped to vehicle limits: `[-1.22, 1.22]` radians
---
## 📌 Waypoint Format
Waypoints should be passed as a list of `[x, y, v_desired]`, where:
* `x`, `y`: global coordinates of the waypoint
* `v_desired`: desired speed (m/s) at that point