π CTRAIL: A Commonsense World Framework for Trajectory Planning in Autonomous Driving
April 9, 2025 Β· View on GitHub
π Abstract
Trajectory planning in dynamic environments is a paramount challenge for autonomous driving, especially in unseen environments where traditional models struggle to generalize. To address this, we propose \textsf{C-TRAIL}, a \textbf{\underline{C}}ommonsense world framework for \textbf{\underline{TRA}}jectory p\textbf{\underline{L}}anning. Inspired by how humans leverage commonsense when planning, C-TRAIL introduces a \textbf{Commonsense World} that interacts with the environment through a closed-loop three-stage process: \textbf{Recall}, \textbf{Plan}, and \textbf{Update}.
This commonsense world is implemented via three core modules. First, Trust Commonsense Recall module queries LLMs for high-level relations and actions, and filters through a fused trust mechanism combining commonsense trust and kinematic trust, resulting in a trust commonsense representation. Second, the Commonsense-Guided Monte Carlo Planning module integrates this representation into a Dirichlet-based trust policy, which guides Monte Carlo Tree Search (MCTS) for efficient and targeted trajectory exploration. Third, an Adaptive Calibration Update module continuously refines the trust state and planning policy using real-world feedback, ensuring consistency and adaptability over time.
To the best of our knowledge, C-TRAIL is the first to introduce a human-inspired Commonsense World into a trajectory planning loop. Experiments on the Highway-env simulator in four scenarios (i.e., highway, merge, intersection, and roundabout) show that CβTRAIL yields average improvements over state-of-the-art baselines by 53.8% w.r.t. ADE, 62.5% w.r.t. FDE, and 35.8% w.r.t. SR in seen environments, and 42.5% w.r.t. ADE, 52.2% w.r.t. FDE, and 27.1% w.r.t. SR in unseen environments, respectively. Additionally, case studies show that C-TRAIL generates safe and smooth trajectories, underscoring its effectiveness and real-world potential.
π Project Structure
CTrail/
βββ data/ # Data files
βββ mcts/ # MCTS + planning modules
β βββ mcts_with_prior.py # Core MCTS with prior knowledge
β βββ ObservationGraphBuilder.py# Build observation graphs from environments
β βββ PolicyAdapter.py # Policy wrapper for planning
β βββ TrustGraphPlanner.py # Trust-graph-based trajectory planner
β βββ TrustModel.py # Trust estimation model
βββ ppo_logs/ # PPO training logs
βββ results/ # Output results
βββ scenario/ # Prompt, trust, and encoder definitions
β βββ Encoder.py # Transformer encoder for graphs
β βββ Prompt.py # Prompt construction for language models
β βββ Trust_commonse_graph.py # Common-sense trust graph generation
β βββ Trust.py # Trust modeling and updates
βββ utils/ # Utilities and test environments
β βββ agent_propmt.py # Agent-specific prompt logic
β βββ data_gather.py # Data collection scripts
βββ videos/ # Rendered simulation videos
βββ config.yaml # Configuration file
βββ license.txt # License
βββ run_CTRAIL.py # π Main entry point
βββ README.md # You are here
π Data Format
Each `.json` file in `data/*-v0/` directories defines a simulation scenario
with specific lane and traffic density settings.
Filename format:
<scenario>-v0_lane_<num_lanes>_density_<traffic_density>.json
- <scenario>: One of `highway`, `intersection`, `merge`, `roundabout`
- <num_lanes>: Number of lanes in the environment (e.g., 3)
- <traffic_density>: e.g., 1.0, 1.5, 2.0, etc.
Example:
merge-v0_lane_3_density_2.5.json β A merging scenario with 3 lanes and
vehicle density of 2.5
βοΈ Configuration Format
############ Large language model config ############
OPENAI_API_TYPE: 'openai' # 'openai' or 'azure'
# Below are for OpenAI
OPENAI_KEY: your own key
OPENAI_CHAT_MODEL: 'gpt-3.5-turbo' # 'gpt-4-1106-preview', etc.
# Below are for Azure OAI service
AZURE_API_BASE: # https://xxxxxxx.openai.azure.com/
AZURE_API_VERSION: "2023-07-01-preview"
AZURE_API_KEY: # 'xxxxxxx'
AZURE_CHAT_DEPLOY_NAME:
AZURE_EMBED_DEPLOY_NAME:
############### Settings ############
reflection_module: False # True or False
few_shot_num: 3 # 0 for zero-shot
episodes_num: 2 # run episodes
result_folder: 'results'
############ Highway-env config ############
simulation_duration: 20 # step
vehicle_count: 20
vehicles_density: 2.0
other_vehicle_type: "highway_env.vehicle.behavior.IDMVehicle"
# Other types: DefensiveVehicle / AggressiveVehicle