home / skills / benchflow-ai / skillsbench / vehicle-dynamics

This skill helps simulate vehicle motion, compute safe following distances, and manage cruise-control states using basic kinematic models.

npx playbooks add skill benchflow-ai/skillsbench --skill vehicle-dynamics

Review the files below or copy the command above to add this skill to your agents.

Files (1)
SKILL.md
2.2 KB
---
name: vehicle-dynamics
description: Use this skill when simulating vehicle motion, calculating safe following distances, time-to-collision, speed/position updates, or implementing vehicle state machines for cruise control modes.
---

# Vehicle Dynamics Simulation

## Basic Kinematic Model

For vehicle simulations, use discrete-time kinematic equations.

**Speed Update:**
```python
new_speed = current_speed + acceleration * dt
new_speed = max(0, new_speed)  # Speed cannot be negative
```

**Position Update:**
```python
new_position = current_position + speed * dt
```

**Distance Between Vehicles:**
```python
# When following another vehicle
relative_speed = ego_speed - lead_speed
new_distance = current_distance - relative_speed * dt
```

## Safe Following Distance

The time headway model calculates safe following distance:

```python
def safe_following_distance(speed, time_headway, min_distance):
    """
    Calculate safe distance based on current speed.

    Args:
        speed: Current vehicle speed (m/s)
        time_headway: Time gap to maintain (seconds)
        min_distance: Minimum distance at standstill (meters)
    """
    return speed * time_headway + min_distance
```

## Time-to-Collision (TTC)

TTC estimates time until collision at current velocities:

```python
def time_to_collision(distance, ego_speed, lead_speed):
    """
    Calculate time to collision.

    Returns None if not approaching (ego slower than lead).
    """
    relative_speed = ego_speed - lead_speed

    if relative_speed <= 0:
        return None  # Not approaching

    return distance / relative_speed
```

## Acceleration Limits

Real vehicles have physical constraints:

```python
def clamp_acceleration(accel, max_accel, max_decel):
    """Constrain acceleration to physical limits."""
    return max(max_decel, min(accel, max_accel))
```

## State Machine Pattern

Vehicle control often uses mode-based logic:

```python
def determine_mode(lead_present, ttc, ttc_threshold):
    """
    Determine operating mode based on conditions.

    Returns one of: 'cruise', 'follow', 'emergency'
    """
    if not lead_present:
        return 'cruise'

    if ttc is not None and ttc < ttc_threshold:
        return 'emergency'

    return 'follow'
```

Overview

This skill provides compact, practical building blocks for vehicle dynamics used in simulations and simple control logic. It includes kinematic updates for speed and position, safe following distance and time-to-collision calculations, acceleration clamping, and a basic mode-based state machine for cruise/follow/emergency behaviors. Use it to prototype motion models, safety checks, and mode selection for longitudinal vehicle control.

How this skill works

The skill implements discrete-time kinematics: speed is integrated from acceleration and position from speed, with non-negative speed enforcement. It computes relative distance updates when following a lead vehicle and derives safe following distance from a time headway model plus a standstill margin. Time-to-collision (TTC) returns a finite estimate only when approaching. Acceleration is clamped to physical limits and a simple state machine selects cruise, follow, or emergency modes based on lead presence and TTC.

When to use it

  • Simulating longitudinal vehicle motion with simple kinematics in discrete time.
  • Calculating safe following distances for adaptive cruise or driver-assist logic.
  • Estimating time-to-collision for collision warnings or mode switching.
  • Constraining commanded acceleration to vehicle physical limits.
  • Implementing a basic state machine for cruise, follow, and emergency responses.

Best practices

  • Use small, consistent dt values for stable integration of speed and position.
  • Combine TTC with additional checks (e.g., relative acceleration) before emergency braking.
  • Tune time headway and min distance to match vehicle type and desired safety margin.
  • Apply acceleration clamping at the last control stage to avoid commanding infeasible inputs.
  • Handle None TTC results explicitly to avoid false emergency triggers when not closing.

Example use cases

  • A prototype adaptive cruise controller that updates speed/position and switches modes based on TTC.
  • A simulator that steps multiple vehicles forward in time and computes inter-vehicle distances.
  • A safety monitor that issues warnings when safe following distance is violated.
  • A test harness for control algorithms where commanded acceleration must be clamped to limits.
  • A simplified scenario evaluator that flags emergency maneuvers when TTC falls below a threshold.

FAQ

What does TTC=None mean?

TTC=None indicates the ego vehicle is not approaching the lead vehicle (ego speed <= lead speed), so no collision is predicted under current velocities.

How should I choose time headway and min distance?

Select time headway based on desired safety cushion (commonly 1.0–2.0 s) and min distance to cover standstill spacing; tune with real-world behavior and testing.