Vehicle Platooning Simulations with Functional Reactive Programming

Bernd Finkbeiner, Felix Klein, Ruzica Piskac, Mark Santolucito

TL;DR

This paper introduces Haskell-TORCS, a library that brings Functional Reactive Programming (FRP) to the world of autonomous vehicle simulation. By leveraging Haskell’s strong typing and the Yampa FRP library, the authors demonstrate how to build modular, verifiable, and elegant controllers for both solo driving and multi-vehicle platooning.

What Problem Does This Paper Address?

Autonomous vehicles (AVs) are "reactive systems" that must interact reliably with a highly dynamic environment. Traditionally, these systems are built using imperative languages like C++, which rely on complex callback loops and shared state. As these systems scale, they become notoriously difficult to reason about, debug, and formally verify.

While functional programming offers benefits like purity and strong typing, applying it to cyber-physical systems is tricky. These systems require a tight integration of continuous signals (like a car's velocity) and discrete steps (like a digital controller's logic). Existing tools often lack an explicit notion of time, making it difficult to model the temporal dependencies inherent in driving.

Methods

The authors present a new bridge between the functional world and the physical world:

  • Haskell-TORCS: A library providing Haskell bindings for TORCS (The Open Racing Car Simulator), a sophisticated open-source physics engine used in AV research.
  • Arrowized FRP (Yampa): The authors use the Yampa library, which implements "Arrowized" Functional Reactive Programming. In this paradigm, the core abstraction is a Signal (a value that varies over time) and a Signal Function (SF) (a transformer that converts one signal to another).
  • State Management via ArrowLoop: To handle stateful logic—such as remembering the previous gear or comparing two consecutive video frames to calculate velocity—the authors utilize the ArrowLoop abstraction. This allows for feedback loops in the code without the "spaghetti" of global variables.
  • Pure Control Logic: By defining control functions (steering, acceleration, shifting) as pure functions, the authors ensure that the logic is isolated from side effects, making it significantly easier to test and verify.

Datasets

The paper does not use traditional training datasets (as it is not a machine learning paper). Instead, it utilizes:

  • TORCS Simulator: The primary evaluation environment, including its preloaded racing tracks and physics engine.
  • Sensor Data: The controllers process simulated data including RPM, track position, LiDAR-like sensor arrays, and camera images.

Key Insights and Ideas

  • Time as a First-Class Citizen: FRP treats time-varying values as primary objects. This is a natural fit for AVs, where the "now" is always dependent on the "then."
  • Separation of Concerns: The "Arrow" syntax allows developers to pipe data through a series of transformations (e.g., Image -> Steering -> DriveState). This makes the dependency flow of the controller explicit and easy to follow.
  • Concurrency for Platooning: Haskell’s native support for multi-threading makes simulating multiple vehicles (platooning) straightforward. The authors implemented a communication layer using a thread-safe shared memory library (MVar), allowing vehicles to "talk" to each other to coordinate speed.
  • Safety through Purity: Because the steering value is only changed in one specific, pure function, the risk of "malformed state" causing a crash is drastically reduced compared to imperative code where any part of the program might accidentally modify a global variable.

Key Results

  • Solo Controller: The authors successfully implemented a basic controller that navigates TORCS tracks with "reasonable speed and finesse." The code for gear shifting, steering, and gas is remarkably concise (fitting into a single code listing).
  • Platooning Logic: They demonstrated a multi-vehicle scenario where cars check for imminent collisions and broadcast "faster" or "slower" requests to the rest of the platoon.
  • Performance: While not providing raw benchmarks for the car, the authors point to previous research showing that FRP-based network controllers can outperform imperative versions on multicore processors due to efficient parallelism.

Limitations and Future Work

  • Idealized Communication: The current platooning simulation assumes zero packet loss and no distance constraints for vehicle-to-vehicle (V2V) communication. Real-world V2V is much noisier.
  • Simulator Graphics: While TORCS is excellent for physics, its graphics are dated. The authors suggest that future work could involve higher-fidelity environments like Grand Theft Auto V for better image recognition testing.
  • Formal Verification: Although the paper argues that FRP makes verification easier, the authors have not yet applied formal methods (like model checking) to the specific controllers developed in this paper. This remains a promising next step.

Summary updated

Abstract

Functional languages have provided major benefits to the verification community. Although features such as purity, a strong type system, and computational abstractions can help guide programmers away from costly errors, these can present challenges when used in a reactive system. Functional Reactive Programming is a paradigm that allows users the benefits of functional languages and an easy interface to a reactive environment. We present a tool for building autonomous vehicle controllers in FRP using Haskell.
BibTeX
@inproceedings{finkbeiner2017vehicle,
  author = {Bernd Finkbeiner and Felix Klein and Ruzica Piskac and Mark Santolucito},
  title = {{Vehicle Platooning Simulations with Functional Reactive Programming}},
  booktitle = {SCAV@CPSWeek},
  year = {2017},
  doi = {10.1145/3055378.3055385},
}

Loading related content...

Figure