Real-time input and plotting with ModelingToolkit

Callbacks are one option. Another option is to run the simulation for 0…dt, then update the display, than from dt…2dt etc.

Example code:

function simulate(integrator, steps)
    for i in 1:steps
        KiteModels.next_step!(kps4, integrator; set_speed=0, dt)

        sys_state = SysState(kps4)
        q = QuatRotation(sys_state.orient)
        roll, pitch, yaw = rad2deg.(quat2euler(q))
        println("roll: ", roll, " pitch: ", pitch, " yaw: ", yaw)
        
        reltime = i*dt-dt
        if mod(i, 5) == 1
            plot2d(kps4.pos, reltime; zoom=ZOOM, xlim=(40,60), front=FRONT_VIEW, segments=set.segments)                       
        end
    end
end

In this example I run the simulation with steps of 20ms and update the GUI on every 5th step.

ControlPlots.jl does not (yet) offer sliders, for sliders you must use other options like Makie.jl or QML.jl or others.

The integrator interface from DifferentialEquations.jl can be used with MTK models.

1 Like