Updating Parameters While the Model Runs (Model Interface Toolkit)

LabVIEW 2017 Model Interface Toolkit Help

Edition Date: May 2017

Part Number: 374160C-01

»View Product Info
Download Help (Windows Only)

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/outports and other parts of the application, so 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 motor controller via inport than to adjust parameters that affect the load on the motor.

Choose between two methods for implementing code that sets parameters:

The following sections describe the use case for each method and typical code for implementing them.

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.

Setting the value of a parameter outside the control loop is a two-step process: setting the new values, and then committing 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.


Loads the model from disk and reads the compiled rate of the model in seconds, which is used to calculate the Timed Loop period.


Creates a Parameter Interface reference that you pass to other VIs to get and set model parameters.


Steps the model during each iteration of the Timed Loop and reads/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 4 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.

Refer to the MIT Parameter Management VI in the labview\examples\Control and Simulation\Model Interface directory for example code that demonstrates these concepts.

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.


Loads the model from disk and reads the compiled rate of the model in seconds, which is used to calculate the Timed Loop period.


Sets the Update Parameters In Line? 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 in line with time steps or set them in code outside the control loop. You cannot use both methods simultaneously. More information.


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 in line.


Steps the model and reads/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.

Note that unlike initializing parameters or setting them from a background loop, you do not need to commit parameters when you update them in line.

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 In Line? 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 Get Parameter, Set Parameter, and Set Parameter Inline VIs allow you to update a single element of a vector parameter. To identify the specific element of the vector to update, specify the position of the element within the parameter via the Offset within parameter input of these VIs. Use the following guidelines to determine the correct value for this input:

  • If the vector has one dimension, the offset of an elements 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 Links

Format of Vector Parameters

Calculate Parameter Offset VI

Initializing Parameter Values

Basic Architecture for Executing Models

WAS THIS ARTICLE HELPFUL?

Not Helpful