2

I'm trying to implement an online MPC controller and I'm a bit confused about what exactly the m.time does.

With m.options.IMODE = 6 #MPC and m.options.REQCTRLMODE=3, I try to define the prediction and control horizons:

m.options.CTRL_HOR=10
m.options.CTRL_TIME=0.05
m.options.PRED_HOR=10
m.options.PRED_TIME=0.05

If I understand it right the ctrl_hor and pred_hor sets how many future timesteps we calculate and the pred_time and ctrl_time defines how long is one timestep. But the problem is that the controller throws an error if I don't define m.time, but what exactly does it do and why isn't it enough to set ctrl and pred horizons with respective timesteps?

  • Hi, welcome to SO. Please strongly consider posting a MRE (stackoverflow.com/help/minimal-reproducible-example) with snippets of both HTML and CSS (and JS if applicable or other lang.) so we can better help you thank you. Also, please focus on a single specific question. – avia Sep 21 '20 at 17:25
  • Here is another recent post on Control and Prediction horizons: https://stackoverflow.com/questions/64040582/the-control-horizon-and-prediction-horizon/64046894 – John Hedengren Sep 24 '20 at 12:57

1 Answers1

1

Gekko uses m.time by default instead of CTRL_HOR and PRED_HOR. You can define an equivalent control / prediction horizon in Gekko with:

import numpy as np
from gekko import GEKKO

m = GEKKO()
m.time = np.linspace(0,0.05,11)

The CTRL_HOR and PRED_HOR properties are optionally used when CSV_READ=0. However, Gekko uses the CSV file to insert information about default values for parameters and variables so I don't recommend that you turn it off. Using m.time is also more flexible because you can have a non-uniform control / prediction horizon such as:

m.time = [0,0.05,0.1,0.2,0.5,1.0]

This helps to have the fine resolution at the beginning and then larger steps to determine steady-state move plans. Here is a practical TCLab MPC application with real-time data.

MPC Application

John Hedengren
  • 12,068
  • 1
  • 21
  • 25
  • 1
    Thanks for the reply. I suspected that that's what the m.time does, but what can I do if I need prediction and control horizons to be different from each other? – Andris Lipenitis Sep 22 '20 at 14:41
  • 1
    You can set up something like `m.time = [0.0,0.05,0.1,0.15,0.2,0.4,0.6.0.8,1.0]` that is equivalent to `CTRL_TIME=0.05`, `CTRL_HOR=4`, `PRED_TIME=0.2`, `PRED_HOR=8`. If you really don't want to adjust the last 4 moves of the MV prediction horizon then you can use `m.Connection()` to connect them into a single value. – John Hedengren Sep 22 '20 at 15:39