If I change the 1 line code than error is different. That line is
model.state = [initial_state; initial_covariance(:)];
Whole code is
//Kalman_Filter_IF.sci
// The interface file for the generic Kalman Filter block.
// This block is externally activated to take measurements data.
// Takes the continuous positions velocity or accelerations as input, adds some
// errors (noise, scale, nonlinearity, misalignment) and gives
// it as the output.
// Abbrev.
// IF: Inertial Frame, BF: Body Frame,
// Model input:
// 2x2 Real - State vector with position and velocity BF w.r.t. IF
// 1 Real - Covariance vector
// Model output:
// 2x2 Real - Single axis gyro measurement output w.r.t. BF
// 1x1 Real - Error flag
// 0: No error
// 1: Positive saturation error
// 2: Negative saturation error
// Model states:
// 1x1 Real - Random walk error
// Model parameters:
// 2x2 Real - State Vector measurement unit vector w.r.t. BF (Unit vector)
// 1x1 Real - Noise mean (bias) of the sensors
// 1x1 Real - Noise stddev of the sensors
// 1x1 Real - Scale error
// 2x1 Real - Misalignment error
// 1x1 Real - Random walk error
function [x, y, typ] = Kalman_Filter_IF(job, arg1, arg2)
funcprot(0)
x = [];
y = [];
typ = [];
getInputFromSim = 1;
initial_state = [0.0; 0.0]; // 2*1 matrix
initial_covariance = [1.0, 0.0; 0.0, 1.0]; // 2*2 matrix
funcprot(0) // Use funcprot(0) to avoid this message it happen when we see inbuilt funcitons by system
select job
// Initialize with mask parameters if any
case "plot" then
standard_draw(arg1);
case "getinputs" then
[x, y, typ] = standard_inputs(arg1);
case "getoutputs" then
[x, y, typ] = standard_outputs(arg1);
case "getorigin" then
[x, y] = standard_origin(arg1);
case 'set'
// Assignments here comes after assignments of the execution with the "define" flag
x = arg1; // This line is essential, otherwise gives "Invalid index." error.
graphics = arg1.graphics;
exprs = graphics.exprs;
model = arg1.model;
if getInputFromSim == 1 then
exec("macros/Kalman_Filter_Utils.sci", -1); // Not sure about this line in MATLAB, comment it if not necessary
title = "Set Parameter";
labels = [ 'Initial state [x_dot(velocity), x(position)] which is position in ECEF frame and velocity';
'Covariance which gives the uncertainty at position and velocity'];
// Changed 'Stiffness' to 'Covariance'
// In future we can add {'Accelerations', 'Orientations which is obation altitude control system'}
types = list('mat', [2,2], 'mat', [2,2]); // Changed 'vec' to 'mat' for Covariance
endLoop = %f;
disp(36)
// Create a dialog for getting user inputs
while ~endLoop do
// Initialize dialog for parameters and initial state
[ok, State, Covariance, exprs] = scicos_getvalue(title, labels, types, exprs);
errMsg = [];
// Check return set conditions of the initial state as per meetings
if ~ok then
// depends on what type of data we are having
if condition1 // first condition of position and velocity
errMsg = [];
end
if condition2 // second condition of velocity
errMsg = [];
end
if isempty(errMsg) then
[model.rpar, isError] = EncodeRpar_KF(model.rpar, State, Covariance);
graphics.exprs = exprs;
x.graphics = graphics;
x.model = model;
endLoop = %t;
// Check parameters
// You can add additional checks for input parameters here if needed
// Accept inputs and save them
else
messagebox(errMsg);
error(errMsg, 20000);
endLoop = %f;
end
else
warning('Kalman_Filter_IF: Set: Cancel!');
endLoop = %t;
end
end
else
graphics.exprs = exprs;
x.graphics = graphics;
x.model = model;
end
// Concatenate the covariance matrix to the state vector
// model.state = [State; Covariance(:)]; // Use the concatenation operator ":" for the matrix
disp(84)
// Define block properties
case 'define'then
// Create object
model = scicos_model();
// Provide name and type
model.sim = {'Kalman_Filter_sim', 5}; // what is case 4 and 5? https://help.scilab.org/scicos_model.html
// Define inputs and outputs
// One input with a variable-size "double" element
model.in = 1; // it's only z,[-ve, complier will try to find appropriate size, 0 and +ve]
// it has at first position occupies which means at first position is 1, 1 indicates that only one input value, see wriiten notes to understand
model.in2 = 1; // the second dimension of I/P whcih means all the data enter has one dimension data for example just z axis data while if it was 2 than we have input data of x and y if there is 3 then x,y,z so on. each column represents specific data. Same as above comment [https://help.scilab.org/scicos_model.html]
model.intyp = 1;
// One output with a single "double" element
model.out = [2; 2];
model.out2 = [1;2];
model.outtyp = 1;
// Set default parameter
model.rpar= []; // Use the covariance matrix as a parameter
ipar=[1;1;1;1;2;3;1;3;1;1];
// Set initial state
model.state = [initial_state,matrix(initial_covariance)]; // Use the matrix concatenation operator ":" to convert matrix to column vector model.state=[State;Covariance]
model.state = [initial_state; initial_covariance(:)];
model.rpar = initial_covariance; // Use the covariance matrix as a parameter
// Define block properties
model.blocktype = 'c';
model.dep_ut = [%t,%f]; // what does %t and %f indicates? true and false
// Set block properties
exprs = ['[0.0; 0.0]', '[1.0]']; // How do we get this value?
x = standard_define([4 4], model, exprs);
x.graphics.style = ['blockWithLabel;displayedLabel=Kalman_Filter'];
// other cases other than set or define sections
end
endfunction