sim

Simulate a jMPC MPC Controller in a given jSIM Simulation Environment.

Syntax

jSIMobj = sim(jMPCobj,jSIMobj)
jSIMobj = sim(jMPCobj,jSIMobj,mode)

Description

jSIMobj = sim(jMPCobj,jSIMobj,mode) applies the MPC Controller in jMPCobj to the Simulation Environment in jSIMobj, using the given mode. There are currently four modes available for simulation:

'MEX'Default High speed C implementation of the jMPC engine and QP solver. Useful for multiple MPC simulation studies.
'Matlab'Simulation mode uses an m-file implementation of the jMPC engine. Best for debugging and algorithm development.
'Simulink'Uses the Discrete MPC C S Function within Simulink as the jMPC engine.
'MPCToolbox'Converts the jMPC object to a MATLAB MPC Toolbox object and simulates it using the MPC Toolbox®. Useful for comparison studies of jMPC results against a commercial product.

From all simulation modes the returned jSIM object will be tagged as a results object, and will contain the simulation results.

Functional Overview

The function performs 6 steps at every sample of the simulation:

StepOperationDescription
1State Estimator UpdateThe current model states are updated with the state estimation gain, Kest. This infers a current step rather than a predictor step state estimator.
2Solve MPC Control LawAs described in mpcsolve, the MPC Control law is computed here and u solved for.
3Saturate InputsThe calculated rate of change of input, and absolute input are saturated to the limits of the constraints (if they are not already within these limits).
4Simulate ModelThe model is simulated over one time step.
5Apply Input to PlantThe input is applied to the plant for one time step.
6Save Sample Results & RepeatThe results of the above are saved and the simulation repeats until specified.