Why do I get an "Incorrect data type" error or "Parameter precision loss" warning when I try to tune a parameter with SLRT & Speedgoat?

14 次查看(过去 30 天)

I am trying to change a Gain parameter during my Simulink Real-Time (SLRT) simulation, but I get the following error when I use "setparam":

>> tg = slrealtime;
>> tg.setparam('MyModel/Gain','Gain',-2)
Error using slrealtime.Target/throwErrorWithCause
Unable to set 'Gain' parameter value on target computer 'TargetPC1': Incorrect data type.

Error in slrealtime.Target/setparam (line 99)
        this.throwErrorWithCause('slrealtime:target:setparamError', ...

Caused by:
    Error using slrealtime.internal.ParameterTuning/setParamWork
    Incorrect data type.
When I try changing the parameter in the block mask while using the external mode ("Run on Target"), I see warnings such as the following in the MATLAB prompt:

Warning: Parameter precision loss occurred for 'Gain' of 'MyModel/Gain'. The
original value of the parameter, 1, cannot be represented exactly using the run-time data type
sfix32_En31. The value is quantized to 0.9999999995343387. Quantization error occurred with an absolute
difference of 4.656612873077393e-10 and a relative difference of 4.65661287307739e-08%.
Suggested Actions:
• To disable this warning or error for all parameters in the model, set the 'Detect precision loss'
option to 'none'. - Apply
• Inspect details in the Parameter Quantization Advisor. - Open
• - Suppress

> In slrealtime/Instrument/dataAvailableFromObserverViaTarget (line 1413)
In slrealtime.Target/dataAvailableFromObserver (line 66)
In slrealtime.Instrument>@(varargin)tg.dataAvailableFromObserver(varargin{:}) (line 1332)
In slrealtime.internal.instrument.StreamingCallBack.NewData (line 25)

采纳的回答

MathWorks Support Team
MathWorks Support Team 2024-9-14,0:00
You can first query the parameter with "getparam" to get clarity on the data type:
>> tg.getparam(gcb,'Gain') ans = int8 -1
In this case, you need to pass an explicit int8 Type:
>> tg.setparam('MyModel/Gain','Gain',int8(-2));
If the parameter type is fixed-point, you will see the following output for "getparam":
>> val = tg.getparam(gcb,'Gain') val = -1 DataTypeMode: Fixed-point: binary point scaling Signedness: Signed WordLength: 32 FractionLength: 31
In this case, it is easiest to re-use the same "fi" object returned by "getparam":
>> val.Value = -2; >> tg.setparam('MyModel/Gain','Gain',val);
To avoid fixed-point types for the Gain parameter, enable the model setting: Gain parameters inherit a built-in integer type that is lossless
For an interactive approach, you can also check the parameter data types in the SLRT Explorer "Parameters" tab and "Type" column:
The new Parameter Quantization Advisor app (R2022b+) may also be useful:https://www.mathworks.com/help/simulink/slref/parameterquantizationadvisor-app.html 
More information on controlling block parameter data types in Simulink can be found in the documentation: 

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Model References 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by