Skip to content

Ghostzero00018/MPC_Course_Project

Repository files navigation

MPC Course Project — Tomato Greenhouse Climate Control

Model Predictive Control (MPC) case study for optimal climate regulation in a tomato greenhouse. Academic project for DMI Semester 3 MPC course.

Project Structure

├── src/                 MATLAB source code
│   ├── tomato_greenhouse_mpc_LMPC.m               Linear MPC (successive linearization + QP)
│   ├── tomato_greenhouse_mpc_FIXED.m               NMPC V3 (baseline, soft constraints, Euler)
│   ├── tomato_greenhouse_mpc_V5_Full.m             NMPC V5 (EKF + Chance + Robust + Economic)
│   ├── tomato_greenhouse_plots_LMPC.m              Visualization for LMPC
│   ├── tomato_greenhouse_plots_FIXED.m             Visualization for V3
│   ├── tomato_greenhouse_plots_V5.m                Visualization for V5
│   ├── tomato_greenhouse_comparison.m              LMPC vs NMPC comparison
│   ├── tomato_greenhouse_Hp_analysis.m             Prediction horizon sensitivity
│   ├── tomato_greenhouse_weight_tuning.m           Weight matrix tuning (Q/R)
│   ├── tomato_greenhouse_constraint_relaxation.m   Constraint relaxation experiments
│   ├── tomato_greenhouse_forecast_experiment.m     Disturbance forecasting experiments
│   ├── load_parameters.m                           Shared parameters (all versions)
│   ├── baseline_onoff.m                            Shared baseline on/off controller
│   ├── get_fallback_control.m                      Shared fallback control
│   └── ifelse.m                                    Inline conditional helper
├── data/                Simulation result .mat files (git-ignored)
├── figures/             Output plots organized by category (git-ignored)
│   ├── LMPC/                Plots from plots_LMPC.m
│   ├── V3_FIXED/            Plots from plots_FIXED.m
│   ├── V5_Full/             Plots from plots_V5.m
│   ├── comparison/          Plots from comparison.m
│   ├── Hp_analysis/         Plots from Hp_analysis.m
│   ├── weight_tuning/       Plots from weight_tuning.m
│   ├── constraint_relaxation/  Plots from constraint_relaxation.m
│   └── forecast_experiment/    Plots from forecast_experiment.m
├── docs/                Documentation and session logs
├── report_pdfLatex.txt  LaTeX report source (IEEE conference, edited on Overleaf)
├── INSTRUCTIONS.txt     Guide for running the code (prerequisites, run order, file deps)
├── REPORT_UPDATE_GUIDE.txt  Bilingual guide for updating report when data/figures change
├── Board.md             Project progress board
└── .gitignore

Quick Start

  1. Clone the repo
  2. Open any script in src/ and run it in MATLAB or VS Code (MathWorks extension)
  3. For MPC simulations, run the corresponding plot script afterwards

All scripts use addpath(scriptDir) for portable paths — no need to cd or modify the MATLAB path first.

MPC Versions

Version Script Model Solver Features
LMPC mpc_LMPC.m COM (linearized) quadprog (QP) Successive linearization, soft constraints, ~5ms/step
V3 (FIXED) mpc_FIXED.m SOM (nonlinear) IPOPT (NLP) 4 controls, soft constraints, Euler discretization
V5 (Full) mpc_V5_Full.m SOM (nonlinear) IPOPT (NLP) Economic MPC + RK4 + EKF + Chance-Constrained + Robust

Analysis Scripts

Script Course Requirement Description
comparison.m LMPC vs NMPC Side-by-side performance comparison (RMSE, energy, solve time)
Hp_analysis.m 4b: Prediction horizon Tests Hp = 4, 6, 8, 12, 16, 20, 24 steps
weight_tuning.m 4c: Multi-objective 10 weight configs varying Q, R, S priorities
constraint_relaxation.m 4c: Constraint effects 10 configs: setpoint conflicts, penalty variation
forecast_experiment.m 4d: Disturbance forecasting 10 forecast models: noise, persistence, lagged, partial

System Overview

3-state greenhouse model:

  • Temperature (°C) — controlled by heating + ventilation
  • Humidity (%) — controlled by dehumidifier + ventilation
  • CO2 (ppm) — controlled by CO2 injection

4 control inputs, 4 weather disturbances, 24-hour simulation at 5-minute intervals (288 steps), N=12 prediction horizon (1 hour).

Control Objectives

The ultimate goal is to maximize tomato yield and quality while minimizing energy costs, by maintaining an optimal indoor climate. Tomatoes require specific conditions at each growth stage:

  • Temperature: 22°C (day) / 17°C (night) — photosynthesis peaks near 22°C; night cooling promotes fruit development. Below 15°C risks cold damage; above 28°C causes heat stress and blossom drop.
  • Humidity: 50–80% — above 80% dramatically increases risk of Botrytis (gray mold) and other fungal diseases; below 50% impairs transpiration and nutrient uptake.
  • CO2: 600 ppm (day) / 450 ppm (night) — elevated CO2 during daylight hours enhances photosynthesis rate by up to 30%, directly increasing yield. No enrichment at night (no photosynthesis).

Energy consumption represents 30–40% of greenhouse operational costs. MPC is uniquely suited because:

Challenge Why MPC
MIMO coupling Ventilation simultaneously affects T, H, and CO2 — PID cannot handle cross-coupling
Weather preview MPC uses forecast over a 1-hour horizon to anticipate disturbances before they affect crops
Hard constraints Optimization framework naturally enforces actuator limits and plant safety bounds
Day/night transitions MPC pre-adjusts controls before setpoint changes, avoiding overshoot
Multi-objective trade-off Q/R/S weight matrices let operators balance tracking accuracy vs. energy efficiency

Key Results

Metric LMPC V3 (NMPC) V5 (NMPC) Baseline
T RMSE 2.65 °C 2.68 °C 2.79 °C 2.48 °C
H RMSE 0.30 % 0.29 % 0.82 % 0.82 %
CO2 RMSE 12.6 ppm 20.4 ppm 21.4 ppm 85.8 ppm
Total Cost 271k 641k 742k 10,640k
Violations 0 0 0 0
Avg solve time 4.6 ms 106 ms 89 ms 0 ms

Dependencies

  • MATLAB R2018b or later
  • CasADi — symbolic optimization (casadi.org)
  • Statistics Toolbox — required for V5 (norminv)

Documentation

  • INSTRUCTIONS.txt — Quick guide for running the code (prerequisites, run order, file dependencies, output paths)
  • REPORT_UPDATE_GUIDE.txt — Bilingual (CN/EN) guide mapping report sections to scripts, output logs, and figures
  • Board.md — Project progress board (requirements checklist, code inventory, report TODOs)
  • docs/DEFENSE_GUIDE.md — Bilingual defense preparation guide: theory, results, Q&A, presentation structure
  • docs/README_MPC_Documentation.md — Comprehensive bilingual (EN/CN) documentation covering theory, code explanation, parameter tuning, and troubleshooting

About

MPC case study - Tomato greenhouse control

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages