RoboRacer F1TENTH — Real-World Autonomous Racing

RACE PROGRAM

Optimization-Based Autonomy on Ackermann Vehicle

Dynamic trajectory sampling → CasADi MPC tracking → MPCC racing line control (RoboRacer F1TENTH)
STATUS TRACK READY
REAL ROBOT DEPLOYMENT

Real-World Deployment on RoboRacer F1TENTH

Built and deployed a full local autonomy stack for a real F1TENTH Ackermann platform: (1) online trajectory generation using RK4 rollouts scored with obstacle distance transforms, (2) trajectory tracking using nonlinear MPC solved with CasADi/IPOPT, and (3) MPCC for high-speed racing line control with contouring/lag errors and explicit progress optimization.

LIVE HUD MODE: AUTONOMOUS
PLANNERDYNAMIC ROLLOUT
TRACKERCASADI MPC
RACINGMPCC
PLATFORMROBORACER F1TENTH
ACKERMANN: ENABLED
OPTIMIZER: IPOPT
HORIZON: ONLINE
SYSTEM OVERVIEW

Autonomy Stack (Real Robot)

F1TENTH Ackermann ROS 2 TF2 CasADi IPOPT

This project is a “racing-style” autonomy pipeline: generate feasible motion candidates fast, then apply optimization-based control to execute them safely and smoothly on hardware. I implemented both a general MPC tracker (for arbitrary trajectories) and an MPCC controller (for racing line following + progress maximization).

SENSOR / MAP → LOCAL TRAJ GEN (RK4 rollouts + scoring) ↓ MPC TRACKER (CasADi/IPOPT) → /drive

The key engineering decision: separate “what to do next” (trajectory choice) from “how to execute” (MPC/MPCC optimization), so each component stays debuggable and swappable.

HARDWARE NOTE

Platform: RoboRacer F1TENTH (Ackermann steering). Control published as AckermannDriveStamped with steering angle and speed. Robot pose obtained via TF: map → ego_racecar/base_link.

WHY THIS MATTERS:
This is not simulation-only control. Constraints, timing, TF availability, and safety margins (distance-to-obstacle) directly affect whether the robot runs cleanly on track.
LOCAL PLANNER

Dynamic Trajectory Generation (RK4 Rollouts + Distance Transform)

RK4 Distance Transform Sampling Safety Margin

The trajectory generator samples steering commands \( \delta \) across the feasible range and forward-simulates the bicycle model for a fixed horizon \(N\) with timestep \(\Delta t\). Each rollout produces a candidate path \(\{(x_k,y_k,\theta_k)\}_{k=1}^N\) which is scored using obstacle clearance from a distance transform map and penalties for curvature and goal deviation.

KINEMATIC MODEL
$$\dot{x}=v\cos\theta,\qquad \dot{y}=v\sin\theta,\qquad \dot{\theta}=\frac{v}{L}\tan(\delta)$$

Integration is done via RK4: \(x_{k+1}=x_k+\frac{\Delta t}{6}(k_1+2k_2+2k_3+k_4)\) (applied to all state components), which reduces numerical drift compared to Euler at higher speeds / longer horizons.

OBSTACLE CLEARANCE

From an occupancy grid, free cells are binarized and passed through an Euclidean distance transform \(d(x,y)\), giving approximate clearance (in meters) for each map cell. Any rollout with \(\min_k d(x_k,y_k) < d_{\text{safe}}\) is rejected.

$$\text{Reject if }\;\min_{k\in[1,N]} d(x_k,y_k) < d_{\text{safe}}$$
SCORING FUNCTION

A simple, interpretable objective works well for fast online selection:

$$J(\tau)=\sum_{k=1}^{N} d(x_k,y_k)\;-\;\alpha\,\underbrace{\sum_{k=2}^{N}|\Delta\theta_k|}_{\text{curvature}}\;-\;\beta\,\underbrace{\|[x_N,y_N]-g\|_2}_{\text{goal}}$$
  • Clearance term prefers trajectories farther from obstacles.
  • Curvature term discourages aggressive yaw oscillations.
  • Goal term pulls the rollout endpoint toward a target.
OUTPUT

The best rollout is published as nav_msgs/Path on /dynamic_trajectory, which becomes the MPC reference.

TRACKING CONTROLLER

Nonlinear MPC Tracking (CasADi + IPOPT)

MPC CasADi IPOPT Ackermann

The MPC tracker consumes the reference path and solves a finite-horizon nonlinear optimization problem every control cycle. The state includes pose and speed: \(\mathbf{x}=[x, y, \psi, v]^T\). Controls are commanded speed and steering: \(\mathbf{u}=[v_c,\delta]^T\).

DYNAMICS (WITH SLIP ANGLE)

The model uses a small slip-angle approximation: \(\beta=\tan^{-1}\!\left(\frac{L_r}{L}\tan\delta\right)\).

$$\beta=\tan^{-1}\!\left(\frac{L_r}{L}\tan\delta\right)$$ $$\begin{aligned} x_{k+1}&=x_k+v_c\cos(\psi_k+\beta)\Delta t\\ y_{k+1}&=y_k+v_c\sin(\psi_k+\beta)\Delta t\\ \psi_{k+1}&=\psi_k+\frac{v_c\cos\beta}{L}\tan\delta\,\Delta t\\ v_{k+1}&=v_c \end{aligned}$$
OPTIMIZATION PROBLEM

Minimize tracking error + control effort with input bounds:

$$\min_{\{\mathbf{x}_k,\mathbf{u}_k\}} \sum_{k=0}^{N-1}\left(\|\mathbf{x}_k-\mathbf{x}^{ref}_k\|_Q^2+\|\mathbf{u}_k\|_R^2\right) +\|\mathbf{x}_N-\mathbf{x}^{ref}_N\|_{Q_f}^2$$ $$\text{s.t.}\;\;\mathbf{x}_{k+1}=f(\mathbf{x}_k,\mathbf{u}_k),\;\; v_{\min}\le v_c\le v_{\max},\;\;\delta_{\min}\le \delta\le \delta_{\max}$$

Implemented with CasADi symbolic variables and solved using IPOPT. The first control action \((v_0,\delta_0)\) is applied (receding horizon control).

RACING CONTROLLER

Model Predictive Contouring Control (MPCC)

MPCC Contouring Progress Racing Line

MPCC differs from standard tracking MPC by introducing a progress state \(\theta\) (arc-length along the centerline) and penalizing contouring and lag errors relative to the racing line. The optimizer simultaneously decides how to steer and how quickly to advance along the track.

STATE & DYNAMICS

Augmented state: \(\mathbf{x}=[x,y,\psi,v,\theta]^T\), with progress update: \(\theta_{k+1}=\theta_k+v_k\Delta t\).

$$\theta_{k+1}=\theta_k+v_k\Delta t$$ $$\begin{aligned} x_{k+1}&=x_k+v_c\cos(\psi_k)\Delta t\\ y_{k+1}&=y_k+v_c\sin(\psi_k)\Delta t\\ \psi_{k+1}&=\psi_k+\frac{v_c}{L}\tan\delta\,\Delta t\\ v_{k+1}&=v_c \end{aligned}$$
CONTOURING / LAG ERRORS

Let the nearest centerline reference be \((x_{cl},y_{cl},\phi_{cl},s_{cl})\). With \(dx=x-x_{cl}\), \(dy=y-y_{cl}\):

$$\varepsilon_c=\sin(\phi_{cl})\,dx-\cos(\phi_{cl})\,dy$$ $$\varepsilon_l=-\cos(\phi_{cl})\,dx-\sin(\phi_{cl})\,dy$$
MPCC OBJECTIVE

Penalize contouring/lag errors and encourage progress by rewarding \(\theta\) toward \(s_{cl}\):

$$\min \sum_{k=0}^{N-1}\left(q_c\varepsilon_{c,k}^2+q_l\varepsilon_{l,k}^2 -q_\theta(\theta_k-s_{cl,k})+\|\mathbf{u}_k\|_R^2\right)$$

In practice: MPCC “doesn’t blindly chase waypoints”; it optimizes a race-style tradeoff between staying near the line and maximizing forward progress.

WHY MPCC OVER TRACKING MPC?
  • Explicit progress makes the controller “want” to move forward, not just reduce error.
  • Stable at speed because it avoids overreacting to noisy reference points.
  • Racing line behavior: controls naturally balance corner cutting vs stability.
ROS INTERFACES
  • /racing_trajectory → custom Trajectory msg (with arc-length \(s\))
  • /mpcc_predicted_horizon → MarkerArray (visual horizon points)
  • /drive → AckermannDriveStamped (applied control)
MATH INDEX

Key Equations (Quick Reference)

Bicycle Model Distance Transform MPC Cost MPCC Errors
Module Equation Purpose
Planner \(\dot{\theta}=\frac{v}{L}\tan\delta\) Rollout curvature / turning
Planner \(\min_k d(x_k,y_k)\ge d_{\text{safe}}\) Obstacle safety margin
MPC \(\min \sum \|\mathbf{x}-\mathbf{x}^{ref}\|_Q^2+\|\mathbf{u}\|_R^2\) Trajectory tracking
MPCC \(\varepsilon_c=\sin\phi\,dx-\cos\phi\,dy\) Contouring error
MPCC \(\varepsilon_l=-\cos\phi\,dx-\sin\phi\,dy\) Lag error
MPCC \(\theta_{k+1}=\theta_k+v_k\Delta t\) Progress along track
NOTE ON EQUATIONS:
This page uses KaTeX (already included in <head>). Use inline math with \( ... \) and block math with $$ ... $$. No additional LaTeX extensions are needed beyond KaTeX.