Skip to content

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LLM-Supervised Water Tank Control (MATLAB / Python / Ollama)

This repository provides a reproducible experimental framework for evaluating the use of a large language model (LLM) as a supervisory element in closed-loop process control. The benchmark system is a nonlinear water-tank model implemented in MATLAB/Simulink, with online interaction between Simulink, Python, and a locally hosted LLM via Ollama.

The LLM does not replace classical feedback control. Instead, it periodically suggests PID gains that are applied within a conventional PID controller, enabling controlled comparison between:

  • classical PID control,
  • autotuned PID control,
  • hybrid LLM-supervised PID control.

The repository corresponds to the experiments reported in the manuscript
“An Experiment of Using a Large Language Model to Control a Water Tank System.”


Repository Structure

This repository contains three experiment folders:

  • Comparison of LLM LLM-PID PID PIDautotuned/
    Main comparison experiment used in the paper.
    Includes:

    • watertank_LLM_PID_PIDautotuned_compare.slx
    • MATLAB helper functions
    • Python LLM interface scripts
    • shared data files
  • Step Fault/
    Step-disturbance robustness test.

  • Ramp Fault/
    Ramp-disturbance robustness test.

Each folder contains a self-contained Simulink model corresponding to the named experiment.


Core Files (Shared Across Experiments)

Simulink

  • watertank_LLM_PID_PIDautotuned_compare.slx
    Main comparison model (hybrid LLM-PID vs PID vs autotuned PID)

MATLAB

  • LLM_Controller.m
    Applies LLM-generated PID gains and enforces safety bounds.
  • getLLMGains.m
    MATLAB wrapper that calls Python to query the LLM.
  • TrimAndLinearizeSimulinkModelsExample.m
    Used for linearization and autotuned PID baseline.
  • watertankdat.mat
    Water-tank model parameters.

Python

  • llm_interface.py
    Handles prompt construction, Ollama calls, output parsing, and logging.
  • llm_controller.py
    Direct LLM controller (illustrative baseline; not used for stable control).

Key Design Principles

  • Supervisory Control
    The LLM is queried at a fixed supervisory update period (e.g., 0.5 s). Between updates, PID gains remain constant.

  • Latency-Aware Execution
    The supervisory update period is selected to exceed worst-case observed LLM inference latency.

  • Safety Constraints
    All LLM-generated gains are clamped to predefined bounds before being applied.

  • Reproducibility First
    Raw LLM outputs and parsed values are logged for analysis and debugging.


Requirements

Software

  • MATLAB + Simulink 2025b
  • Python 3.12.x
  • Ollama (local LLM server)
  • LLM model: LLaMA 3.2 (3B) via Ollama

MATLAB Toolboxes (recommended)

  • Simulink
  • Control System Toolbox
  • Simulink Control Design

Quick Start

  1. Install MATLAB/Simulink and Python.
  2. Install Ollama and pull the model:
    ollama pull llama3.2
  3. Start the Ollama server
    ollama serve
  4. Open MATLAB and set the current folder to the repository root.
  5. Open one of the experiment folders and run the corresponding .slx model.

Detailed build and run instructions are provided in MANUAL.md.

Reproducibility Notes

  • LLM outputs are stochastic by nature.
  • For reproducibility:
    • Keep model versions fixed.
    • Log raw LLM responses.
    • Use conservative gain bounds.
    • Avoid interpreting single runs as optimal performance.

Citation

If you use this repository in academic work, please cite:

Roberts, J., Wen, H., Zaidi, A., McLeod, A. An Experiment of Using a Large Language Model to Control a Water Tank System. (Manuscript under revision)

License

This project is intended for academic and educational use.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages