Main Content

createTunerCostTemplate

Create template of tuner cost function

Since R2022a

Description

createTunerCostTemplate(filter) creates a template of a tuner cost function and shows it in an editor window. The created cost function computes the cost as the root-mean-squared (RMS) error between the estimated states and the ground truth. You can modify the cost function as desired.

When you tune the filter parameters of the insEKF object using its tune object function, use the function created by createTunerCostTemplate to specify the cost in the tunerconfig object as an input to the tune object function.

example

Examples

collapse all

Create an insEKF filter object and create a cost function using the createTunerCostTemplate object function.

filter = insEKF;
createTunerCostTemplate(filter);

Save the created function in an m-file.

doc = matlab.desktop.editor.getActive;
doc.saveAs(fullfile(pwd,"tunercost.m"));

Load prerecorded sensor data and ground truth data.

load("accelGyroINSEKFData.mat");

Specify an initial orientation state and its covariance.

stateparts(filter,"Orientation",compact(initOrient));
statecovparts(filter,"Orientation",1e-2);

Create a measurement noise structure using the tunernoise function.

mnoise = tunernoise(filter);

Create a tunerconfig object using the created cost function.

cfg = tunerconfig(filter,MaxIterations=1, ...
    ObjectiveLimit=1e-4, ...
    Cost="custom", ...
    CustomCostFcn=@tunercost);

Tune the filter. Show the tuned measurement noise and process noise in the filter.

tunedmn = tune(filter,mnoise,sensorData, ...
    groundTruth,cfg)
    Iteration    Parameter                    Metric
    _________    _________                    ______
    1            AdditiveProcessNoise(1)      0.3413
    1            AdditiveProcessNoise(15)     0.3381
    1            AdditiveProcessNoise(29)     0.3353
    1            AdditiveProcessNoise(43)     0.3334
    1            AdditiveProcessNoise(57)     0.3214
    1            AdditiveProcessNoise(71)     0.3121
    1            AdditiveProcessNoise(85)     0.3110
    1            AdditiveProcessNoise(99)     0.3107
    1            AdditiveProcessNoise(113)    0.3106
    1            AdditiveProcessNoise(127)    0.3105
    1            AdditiveProcessNoise(141)    0.2972
    1            AdditiveProcessNoise(155)    0.2872
    1            AdditiveProcessNoise(169)    0.2855
    1            AccelerometerNoise           0.2852
    1            GyroscopeNoise               0.2851
tunedmn = struct with fields:
    AccelerometerNoise: 0.9000
        GyroscopeNoise: 0.9000

orientationNoise = statecovparts(filter,"Orientation")
orientationNoise = 4×4

    0.0100         0         0         0
         0    0.0100         0         0
         0         0    0.0100         0
         0         0         0    0.0100

Input Arguments

collapse all

INS filter, specified as an insEKF object.

Version History

Introduced in R2022a