Table of Contents > QUARC > User's Guide > QUARC Basics for Models
Parameter Tuning
One of the powerful features of QUARC is its ability to tune parameters online - while the real-time code is running and interacting with an actual physical system. For example, suppose a Sine Wave block is present in the model. The real-time code has been built and downloaded to the target, and is now running on the target with the Simulink model window connected to it via external mode. If you double-click on the Sine Wave block to open its parameters dialog and change the sine wave amplitude, and then click OK, the new sine wave amplitude takes effect immediately in the real-time code - while the real-time code is running! There is no need to stop the model, recompile it and restart it. The changes take effect immediately, while the real-time code is running. This ability to change block parameters on the fly is called parameter tuning and it works even if the target is a remote machine or embedded system. Rapid prototyping has never been easier!
It should be noted, however, that most, but not all, parameters may be tuned online. Some parameters may be changed without recompiling as long as the model is not running. For example, the HIL Initialize block has parameters for setting the initial values of the analog and digital outputs of a data acquisition card. It does not make sense to change the initial values after the real-time code has already started running, so these parameters are disabled while the model is running. However, they can be changed without recompiling the model.
Other parameters may not be changed without recompiling the model. A parameter common to many blocks that fits this description is the Sample time parameter of a block. Since the sample time of a block determines the task (and thereby the thread in multitasking mode) to which the block belongs, changing the sample time of a block affects the actual structure of the generated code. Hence, the sample time cannot be changed without recompiling the model and cannot be tuned online. Likewise, the dimensions of a parameter cannot be modified, in general, without recompiling the model because doing so changes the size of the variable assigned to the parameter in the real-time code. Parameters which cannot be tuned online are detected automatically by Simulink by using a checksum for the model. Any attempt to connect to the real-time code after modifying such a parameter will cause Simulink to report an error about the checksum for the model having changed. Similarly, attempting to change such a parameter while already connected to the real-time code via external mode will also cause an error to be reported by Simulink.
The blocksets provided in the Quarc Targets library are designed to minimize the number of times a model has to be rebuilt by making as many parameters tunable online as possible. Parameter tuning may be done using one of the following methods, provided the Simulink model window is connected to the real-time code on the target via external mode (refer to External Mode vs. Normal Simulation in the QUARC documentation, if necessary):
Modifying Simulink Block Parameters in the Block Dialog Box - Batch Download Disabled
While your real-time application is running, you can tune each block's parameters by double-clicking on that block, modifying the values in the corresponding block parameters dialog box and then clicking Gain block in your diagram, you can change its value while the model is running in real-time and see the effect of your change immediately without having to stop and re-build your model. The above procedure results in your changes becoming effective immediately because, by default, the Batch download option in the is disabled. When the Batch download option is disabled, modified parameters are downloaded to your real-time application as soon as you click on the modified block's dialog box.
or to effect the changes. For example, if you have aModifying Simulink Block Parameters in the Block Dialog Box - Batch Download Enabled
As mentioned above, the Batch download option is disabled by default. If it is enabled, then each time you make a change to a block parameter, a diagram update is also required before your changes take effect. This option allows you to download the parameters of multiple blocks simultaneously to the real-time code, rather than one block at a time. To enable the batch download option click on the
menu in the Simulink window and select as shown below:
In the Parameter tuning panel. Click on the box to the left of Batch download to enable this option as shown below and click on Close.
window, the Batch download option can be found in the
With the Batch download option enabled, a diagram update must be performed after changing your model parameters, as mentioned earlier. To update the diagram after changing the parameters of blocks in the model, simply click on the Ctrl+D while the Simulink diagram is the active window.
menu of the Simulink window and select , as shown below. This action causes the new parameter values from all the blocks that were changed to be downloaded to the real-time application, at which point the parameter changes take effect in the real-time code. Alternatively, the diagram update may be accomplished by pressing
For more details on the External Mode Control Panel settings, please see the
MATLAB Command Line
Click to copy the following command line to the clipboard. Then paste it in the MATLAB Command Window:
qc_open_matlab_help('external_mode_control_panel')Modifying MATLAB Workspace Variables
One nice feature of Simulink is the ability to use MATLAB workspace variables for block parameter values. For example, the value of
a Gain block may be set to the variable K
, where the value of K
is assigned
in the MATLAB workspace. This flexibility allows a MATLAB script to be used to assign the values of block parameters. The variable
K
in the above example might be computed as part of a Linear Quadratic Regulator (LQR) control design, for instance.
Like other block parameters, MATLAB workspace variables that are associated with the model may also be tuned online. However, modifying
the MATLAB workspace variable while the Simulink model window is connected to the real-time code does not make the change take effect
in the real-time code as soon as the variable is modified in MATLAB. To make the changes take effect in the real-time code, the diagram
must be updated. To update the diagram after changing the values of MATLAB workspace variables used by the model, simply click on
the menu of the Simulink
window and select , as shown above. This action causes the new variable values
to be downloaded to the real-time application, at which point the parameter changes take effect in the real-time code.
Alternatively, the diagram update may be accomplished by pressing Ctrl+D while
the Simulink diagram is the active window.
Another means of updating the diagram is to use the QUARC MATLAB function qc_update_model. Running the qc_update_model function is similar to selecting from the menu of the Simulink window. This method is particularly convenient in MATLAB scripts because it allows the MATLAB script to compute the new variable values and then update the diagram - the diagram does not have to updated manually. Simply enter the following command in the MATLAB script or directly in the MATLAB command window:
qc_update_model; % update the diagram, downloading new parameter values
Note that if you do not specify any arguments to the qc_update_model function then the current model will be updated. If you would like your changes to be applied to a specific model then pass the model's name as an argument of the qc_update_model function. Please see the qc_update_model function reference page for more details.
Copyright ©2024 Quanser Inc. This page was generated 2024-10-17. Submit feedback to Quanser about this page.
Link to this page.