Skip to content

CORALL (COLREGs-guided Risk Aware LLM) is a novel framework that integrates Large Language Models with real-time risk assessment for autonomous maritime navigation. The system combines LLM-based decision-making with traditional motion planning to enable COLREGs-compliant collision avoidance in ASVs.

License

Notifications You must be signed in to change notification settings

Klins101/CORALL

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CORALL: COLREGs-Guided Risk-Aware LLM for Maritime Autonomous Navigation

CORALL is a novel framework that integrates Large Language Models with real-time risk assessment for autonomous maritime navigation. The system combines LLM-based decision-making with traditional motion planning to enable COLREGs-compliant collision avoidance in autonomous surface vessels.

This repository contains the complete implementation of the CORALL framework as published in our research paper, providing researchers and practitioners with a comprehensive tool for studying LLM-guided autonomous maritime navigation.

Features

  • LLM-based COLREGs Interpretation: Advanced decision-making using OpenAI GPT and Claude models
  • Real-time Risk Assessment: DCPA/TCPA calculations and comprehensive risk metrics
  • Multi-vessel Encounter Handling: Complex scenarios with multiple target vessels
  • Explainable Navigation Decisions: Transparent reasoning for autonomous maneuvers
  • Standardized Test Scenarios: Validation across 22 Imazu test scenarios
  • Dynamic Path Planning: Intelligent waypoint navigation and trajectory optimization
  • Vessel Dynamics Simulation: Realistic modeling of marine vessel movement and control
  • Comparison Mode: Side-by-side analysis of LLM vs baseline navigation decisions
  • Real-time Animation: Interactive visualization of vessel movements and decisions
  • Modular Architecture: Clean, extensible codebase with clear separation of concerns

Project Structure

CORALL/
├── main.py                 # Main entry point
├── requirements.txt        # Python dependencies
├── setup.py               # Package installation
├── README.md              # This file
├── .gitignore            # Git ignore rules
│
├── src/                   # Source code
│   ├── core/             # Core simulation components
│   │   ├── simulation.py # Main simulation loop
│   │   └── integration.py # Numerical integration
│   │
│   ├── dynamics/         # Vessel dynamics and control
│   │   ├── vessel_dynamics.py
│   │   ├── controller.py
│   │   └── actuator_modeling.py
│   │
│   ├── navigation/       # Navigation and path planning
│   │   ├── planning.py
│   │   ├── obstacle_sim.py
│   │   └── reactive_avoidance.py
│   │
│   ├── risk_assessment/  # Risk and collision analysis
│   │   ├── cpa_calculations.py
│   │   ├── cpa_calculations_0speed.py
│   │   ├── cpa_calculations2.py
│   │   └── risk_calculations.py
│   │
│   ├── decision_making/  # Autonomous decision systems
│   │   ├── decision_making.py
│   │   ├── decision_makingllm.py
│   │   └── decision_makingllm1.py
│   │
│   ├── visualization/    # Rendering and animation
│   │   ├── animate.py
│   │   ├── rendering.py
│   │   └── save_animation.py
│   │
│   └── utils/           # Utilities and helpers
│       ├── imazu_cases.py
│       └── validation.py
│
├── tests/              
├── docs/                # Documentation   
├── config/              # Configuration files
└── img/                 # Output images and animations

Installation

Prerequisites

Quick Start

  1. Clone the repository:
git clone https://github.com/Klins101/CORALL
cd CORALL
  1. Create a virtual environment (recommended):
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
  1. Install dependencies:
pip install -r requirements.txt
  1. Set up API keys and configuration:

Create a .env file in the root directory with your API keys:

# OpenAI Configuration
OPENAI_API_KEY=your-openai-api-key-here
OPENAI_MODEL=gpt-4
OPENAI_TEMPERATURE=0.1
OPENAI_MAX_TOKENS=50

# Claude Configuration  
CLAUDE_API_KEY=your-claude-api-key-here
CLAUDE_MODEL=claude-sonnet-4-20250514
CLAUDE_TEMPERATURE=0.1

# Default LLM Provider
LLM_PROVIDER=openai

Note: The .env file is not included in the repository for security reasons. You must create it yourself with your own API keys.

  1. Run a simulation:
python main.py

Usage

Basic Usage

Run the default simulation (Case 1):

python main.py

Command Line Options

python main.py [OPTIONS]

Options:
  --case_number INT    Simulation scenario (default: 1)
  --sim_time FLOAT     Simulation duration in seconds (default: 450.0)
  --dt FLOAT           Time step size (default: 0.1)
  --no_animation       Disable real-time animation
  --output_dir PATH    Output directory for results (default: img/)
  --llm INT           Enable LLM decision making (0=off, 1=on, default: 0)
  --llm_provider STR   LLM provider (openai, claude)
  --compare            Run comparison between LLM and baseline simulation

Examples

  1. Run Case 2 with extended simulation time:
python main.py --case_number 2 --sim_time 600
  1. Quick simulation without animation:
python main.py --no_animation --sim_time 300
  1. Run with LLM-based decision making:
python main.py --llm 1 --case_number 3
  1. Custom output directory:
python main.py --output_dir results/experiment1/
  1. Run LLM vs Baseline comparison:
python main.py --compare --llm_provider claude --case_number 1
python main.py --compare --llm_provider openai --case_number 2

Simulation Cases

The system includes several predefined test scenarios (Imazu cases) that represent common marine navigation situations:

  • Case 1: Head-on encounter
  • Case 2: Crossing situation
  • Case 3: Overtaking scenario
  • Case 4: Multiple vessel encounter
  • Case 5-23: Various complex scenarios

Output

Each simulation run generates:

  1. Animation: scenario_animation{case_number}.gif

    • Real-time visualization of vessel movements
    • Obstacle positions and trajectories
    • Risk zones and avoidance maneuvers
  2. Analysis Plots: plot_dcpa_tcpa_risk_{case_number}.png

    • DCPA (Distance at Closest Point of Approach)
    • TCPA (Time to Closest Point of Approach)
    • Distance to obstacles over time
    • Risk metrics evolution
  3. Simulation Results: simulation_result{case_number}.png

    • Final vessel trajectories
    • Waypoint achievements
    • Collision avoidance paths

Comparison Mode Output (--compare)

When using --compare flag, additional files are generated:

  1. Kdir Comparison: kdir_comparison_{provider}_case_{number}.png

    • Side-by-side comparison of turn decisions
    • Baseline vs LLM steering commands
    • Statistical analysis of navigation behavior
  2. Trajectory Comparison: trajectory_comparison_{provider}_case_{number}.png

    • Overlay of vessel paths (baseline vs LLM)
    • Start/end positions and obstacle locations
    • Visual comparison of navigation efficiency
  3. Summary Report: comparison_summary_{provider}_case_{number}.txt

    • Quantitative comparison statistics
    • Turn frequency and risk management analysis
    • Performance metrics and behavioral insights

Configuration

API Keys and Security

Important Security Notes:

  • Never commit your .env file to version control
  • Keep your API keys secure and do not share them publicly
  • The .env file is already included in .gitignore for security
  • API keys are loaded automatically when the simulation starts
  • You can switch between providers using the LLM_PROVIDER environment variable

LLM Configuration

You can customize LLM behavior by modifying the environment variables:

# Adjust response length (max 100 characters recommended)
OPENAI_MAX_TOKENS=INT
CLAUDE_MAX_TOKENS=INT

# Adjust creativity (0.0 = deterministic, 1.0 = creative)
OPENAI_TEMPERATURE=0.1
CLAUDE_TEMPERATURE=0.1

# Switch between models
OPENAI_MODEL=gpt-gpt-4
CLAUDE_MODEL=claude-sonnet-4-20250514

Customizing LLM Prompt Template

You can customize the LLM prompt template to implement your own COLREGs interpretation or navigation logic. The prompt template is located in:

src/decision_making/multi_llm_decision.py

To modify the prompt:

  1. Edit the system prompt in the MultiLLMCOLREGSInterpreter class (around line 131):
self.system_prompt = """You are a ship navigation officer. Make COLREGs-compliant decisions..."""
  1. Customize for your needs:

    • Add specific COLREGs rules you want to emphasize
    • Modify the response format if needed
    • Adjust the character limit (but keep responses concise)
    • Add domain-specific knowledge or constraints
  2. Example custom prompt:

self.system_prompt = """You are an expert maritime navigator with 20 years experience.
Follow IMO COLREGs strictly. Consider vessel types, weather, and traffic density.

Response format:
- "turn starboard" - right turn per Rule 14/15
- "turn port" - left turn per Rule 16/17  
- "stand on" - maintain course per Rule 13/17
"""
  1. Response parsing: If you change the response format, also update the extract_kdir_from_response() function in the same file to properly parse your custom responses.

Note: Keep responses under 50 characters for optimal performance and ensure they can be parsed by the extract_kdir_from_response() function.

Vessel Parameters

Modify vessel characteristics in the simulation:

  • Length Overall (LOA)
  • Beam Overall (BOL)
  • Maximum speed
  • Turning rates

Control Parameters

Adjust control system settings:

  • PID controller gains
  • Sampling time
  • Actuation limits

Risk Thresholds

Configure safety parameters:

  • Minimum safe distance
  • Risk assessment weights
  • COLREGs compliance levels

API Reference

Core Modules

from src.core.simulation import run_simulation
from src.dynamics.vessel_dynamics import vessel_dynamics
from src.navigation.planning import waypoint_selection
from src.risk_assessment.cpa_calculations import cpa_calculations

Custom Simulations

Create custom simulation scenarios:

from src.core.simulation import run_simulation
import numpy as np

# Define custom waypoints
waypoints = np.array([[100, 200], [300, 400], [500, 300]])

# Run simulation with custom parameters
run_simulation(
    case_number=23,
    waypoints=waypoints,
    sim_time=600.0,
    dt=0.1
)

Example Scenarios

Here are some example simulations demonstrating CORALL's performance across different encounter types:

Case 2: Crossing Encounter

Crossing Encounter
Crossing encounter showing LLM-guided starboard turn decision

Case 8: Head-on with Crossing

Head-on with Crossing
Complex scenario handling Head-on vessel while managing crossing vessel

Case 21: Multi-vessel Encounter

Multi-vessel Scenario
Three-vessel encounter demonstrating complex decision-making capabilities

Each animation shows:

  • Own Ship (OS) in voilet
  • Target Ships (TS) in blue, orange and green respectively depending on the number of target ships
  • Vessel trajectories and maneuvers
  • Real-time COLREGs-compliant decisions

Analysis and Results

Risk and CPA Analysis for case 1, 7, 21

DCPA TCPA Risk Analysis for Case 1 DCPA TCPA Risk Analysis for Case 7 DCPA TCPA Risk Analysis for Case 21
Evolution of DCPA, TCPA, Range, and Risk parameters

The plots demonstrate:

  • DCPA/TCPA trends showing effective collision avoidance
  • Risk assessment throughout the encounter
  • Clear correlation between risk levels and LLM decisions
  • Validation of COLREGs compliance through maneuver choices

Contributing

We welcome contributions! Please follow these guidelines:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Code Style

  • Follow PEP 8 guidelines
  • Add docstrings to all functions
  • Include type hints where applicable
  • Write unit tests for new features

License

This project is licensed under the MIT License - see the LICENSE file for details.

Citation

If you use CORALL in your research, please cite:

@software{corall_2025,
  title = {CORALL: COLREGs-Guided Risk-Aware LLM for Maritime Autonomous Navigation},
  author = {Agyei, Klinsmann and Sarhadi, Pouria and Naeem, Wasif },
  year = {2025},
  url = {https://github.com/Klins101/CORALL}
}

Acknowledgments

This work was developed in collaboration with:

  • Dr. Pouria Sarhadi (University of Hertfordshire)
  • Prof. Wasif Naeem (Queen's University Belfast)
  • LLM integration using OpenAI GPT and Anthropic Claude models

Contact

For questions or support, please open an issue on GitHub or contact:

About

CORALL (COLREGs-guided Risk Aware LLM) is a novel framework that integrates Large Language Models with real-time risk assessment for autonomous maritime navigation. The system combines LLM-based decision-making with traditional motion planning to enable COLREGs-compliant collision avoidance in ASVs.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages