Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Heuristic:CARLA simulator Carla PID Controller Tuning

From Leeroopedia
Knowledge Sources
Domains Autonomous_Driving, Optimization
Last Updated 2026-02-15 07:00 GMT

Overview

Pre-tuned PID controller gains for lateral and longitudinal vehicle control in CARLA, with steering rate-limiting to prevent oscillation.

Description

The CARLA agent stack uses dual PID controllers: one for longitudinal control (throttle/brake) and one for lateral control (steering). The default gains in local_planner.py have been empirically tuned for CARLA vehicles and should be used as a starting baseline. The steering controller includes a rate-limiter (max 0.1 change per step) to prevent abrupt steering changes that cause oscillation. The error buffer is capped at 10 samples to prevent integral windup.

Usage

Use this heuristic when configuring or tuning PID controllers for autonomous agents in CARLA, particularly when:

  • Creating a custom agent based on BasicAgent or BehaviorAgent
  • Tuning vehicle control for a specific vehicle model
  • Debugging erratic steering or speed oscillation

The Insight (Rule of Thumb)

  • Default Lateral PID: `K_P=1.95, K_I=0.05, K_D=0.2, dt=0.05` (local_planner.py:81)
  • Default Longitudinal PID: `K_P=1.5, K_I=0.05, K_D=0.2, dt=0.05` (local_planner.py:82)
  • Steering Rate Limit: Max change of `0.1` per step in either direction (controller.py:77-80)
  • Max Throttle: `0.75` (controller.py:23)
  • Max Brake: `0.3` for normal driving, `0.6` for emergency stop (basic_agent.py:64)
  • Max Steering: `0.8` (controller.py:24)
  • Error Buffer: `maxlen=10` samples for both integral and derivative computation (controller.py:128, 197)
  • Trade-off: Higher K_P gives faster response but may oscillate. Higher K_D dampens oscillation but reduces responsiveness. Higher K_I eliminates steady-state error but risks windup.

Reasoning

The PID gains were empirically tuned for CARLA's default vehicle physics. The lateral controller computes steering angle from the cross-track error (angle between vehicle forward vector and target waypoint vector). The rate limiter at controller.py:77-80 is critical: without it, the steering would jump abruptly at intersections causing loss of control. The longitudinal controller clips output to [-1, 1] using `np.clip` (controller.py:164), where negative values indicate braking.

The `dt` parameter should match `fixed_delta_seconds` from the simulation settings. The default `1.0/20.0 = 0.05` corresponds to 20 FPS synchronous mode.

# PythonAPI/carla/agents/navigation/local_planner.py:78-88
self._dt = 1.0 / 20.0
self._target_speed = 20.0  # Km/h
self._sampling_radius = 2.0
self._args_lateral_dict = {'K_P': 1.95, 'K_I': 0.05, 'K_D': 0.2, 'dt': self._dt}
self._args_longitudinal_dict = {'K_P': 1.5, 'K_I': 0.05, 'K_D': 0.2, 'dt': self._dt}
self._max_throt = 0.75
self._max_brake = 0.3
self._max_steer = 0.8
# PythonAPI/carla/agents/navigation/controller.py:75-80
# Steering regulation: changes cannot happen abruptly, can't steer too much.
if current_steering > self.past_steering + 0.1:
    current_steering = self.past_steering + 0.1
elif current_steering < self.past_steering - 0.1:
    current_steering = self.past_steering - 0.1

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment