Skip to content
Advertisement

GEKKO variable update in real time

How do I need to setup m.time and update the initial conditions if I want to use GEKKO in an online simulation that updates every second? I have tried:

JavaScript

but it doesn’t seem to update the values. I’m using IMODE = 4 This is just a dynamic simulation application. No control at the moment.

Advertisement

Answer

Gekko manages the initial conditions automatically when m.options.TIME_SHIFT=1 (default). Below is a simple example with a simulation loop and a single input and single output.

simulation results

JavaScript

The initial condition can be adjusted if it needs to change cycle-to-cycle such as with:

JavaScript

adjust initial condition

JavaScript

There was a bug just in Gekko v1.0.1 that may affect these results. I recommend upgrading with pip install gekko --upgrade to the latest version.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement