Updating Parameters While the Model Runs
- Updated2026-05-07
- 5 minute(s) read
Updating Parameters While the Model Runs
Use the Model Interface API to update model parameters programmatically during runtime.
Many models have parameters, which act as variables in the model. The default values of parameters are compiled into the model. However, while a model runs in your application, you might want to adjust parameter values to test the system response. In your application, use the Model Interface API to programmatically change parameter values at run time.
Methods of Updating Parameters
Updates to parameters are often lower priority than transferring data between model inports and outports and other parts of the application. Updates do not need to occur during every time step. For example, it is more critical for a model to receive the motor command from a controller by inport than to adjust parameters that affect the load on the motor.
Choose between the following methods for implementing code that sets parameters:
- With a lower priority than updates to inport and outports.
- With the same high priority as updating inports and outports.
Low-Priority Updates to Parameters
You can use the Model Interface API to set parameter values in a lower priority, background part of your application, such as a loop that runs when the high priority control loop finishes executing and sleeps. This design is useful because updating parameters in the control loop that steps your model can decrease performance of the application.
To set the value of a parameter outside the control loop, complete the following steps:
- Set the new values.
- Commit the new values.
This process is similar to the process for initializing parameters.
The following block diagram shows the use of a Timed Loop that steps the model at a constant rate and a While Loop that updates parameter values:
Both loops run until an error occurs or the stop front panel control is TRUE.
The code performs the following steps:
- Loads the model from disk.
- Reads the compiled rate of the model in seconds, which is used to calculate the Timed Loop period.
- Creates a Parameter Interface reference. Pass the reference to other VIs to get and set model parameters.
- Steps the model during each iteration of the Timed Loop. Reads and writes inports and outports. The Timed Loop iterates until an error occurs or the stop control is TRUE.
- Runs when the Timed Loop sleeps to
set the value of a scalar parameter whose index is 0 among all the model
parameters.Tip You also can use the Set Parameter VI to set one element of a vector parameter or an entire vector parameter.
- Applies the new value to the model when the Apply Changes Boolean control is TRUE. Until the Commit Parameters VI runs, any values you set in step 5 are not applied. Therefore, you can set multiple new values and only set the latest value with the Commit Parameters VI.
- Closes the reference to the parameter-update session. Unloads the model from memory and handles any errors.
For an example code that demonstrates updating parameter values, see MIT Parameter Management VI in the labview\examples\Control and Simulation\Model Interface.
High-Priority Updates to Scalar Parameters
To ensure that the model receives updates to parameter values during the same time step that you set them, you can update parameter values in the same control loop that steps your model. However, be aware that frequently calling this VI can decrease the performance of the control loop.
The code performs the following steps:
- Loads the model from disk.
- Reads the compiled rate of the model in seconds, which is used to calculate the Timed Loop period.
- Sets the Update Parameters Inline property to TRUE so
that you can access parameters in the same loop that steps the model. If this
property is FALSE (default), meaning you can update parameters
only outside the control loop, LabVIEW returns error code -383700 when the
Set Parameter Inline VI runs.Note Within an application, you can either set parameters inline with time steps or set them in code outside the control loop. You cannot use both methods simultaneously.
- Sets the value of a scalar parameter whose index is 0 among all the model
parameters.Note
For illustration purposes, the Set Parameter Inline VI runs during every iteration of the Timed Loop. In a real-world application, you might want to implement this code so that the VI runs only when you want to set a new parameter value.
The Set Parameter Inline VI allows you to set new parameter values only for scalar parameters or for a single element of a vector parameter. You cannot set an entire vector parameter or get any parameter values inline.
- Steps the model and reads and writes inports and outports. The Timed Loop iterates until an error occurs or the stop control is TRUE.
- Unloads the model from memory and handles any errors.
Making Background and Inline Updates to Parameters
If you want to make background updates to parameter values in one part of your code and also make inline updates in the control loop, you can switch the value of the Update Parameters Inline property. For example, you might want to initialize parameter values prior to stepping your model, and then change the values as the model executes.
Getting and Setting Elements in Vector Parameters
In addition to getting and setting scalar parameters, the following VIs allow you to update a single element of a vector parameter:
- Get Parameter
- Set Parameter
- Set Parameter Inline
To identify the specific element of the vector to update, specify the position of the element within the parameter by the Offset within parameter input of these VIs. Consider the following guidelines to determine the correct value for this input:
- If the vector has one dimension, the offset of an element is zero-based.
- If the vector has two dimensions, the Model Interface API treats the parameter as a flattened 1D array in column-major order. You can use the Calculate Parameter Offset VI to return the offset of a particular element within the flattened array.
Related Information
- Manipulating Model Components in Flattened Format
Format data as flattened 1D arrays in column-major order for inports, outports, signals, and vector parameters.
- Initializing Parameter Values
Set and initialize parameter values in models using the Model Interface API or modeling environment software.