Skip to content

🧭 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.

Notifications You must be signed in to change notification settings

CodeName-Detective/Self_Driving_Cars_Control

Repository files navigation

CARLA 2D Waypoint Follower Controller

CARLA Output GIF

This repository contains a 2D longitudinal and lateral controller implementation for a vehicle simulated in the CARLA Simulator. 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

Ouputs

CARLA Video

About

🧭 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.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages