With the help of above function, I have tried to validate the block. But there is an error with
case "define" then
This is whole code as below
// 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.1; 0.0]; // 2*1 matrix
initial_covariance = [1.0, 0.0; 0.0, 1.0]; // 2*2 matrix
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" then
// 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;
disp('line27')
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('vec', 2, 'mat', [2,2]); // Changed 'vec' to 'mat' for Covariance
endLoop = %f;
// Create a dialog for getting user inputs
while ~endLoop do
// Initialize dialog for parameters and initial state
[ok, State, Covariance, exprs] = 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 State<0 then // first condition of position and velocity
errMsg = ["The velocity is negative [m/s]"];
end
if Covariance<0 then // second condition of velocity
errMsg = [errMsg; 'Kalman_Filter_IF: There is an no noise present in covariance as it is negative!'];
end
if isempty(errMsg) then
disp("Setting parameters...");
[model.rpar, isError] = EncodeRparIpar_KF(model.rpar, State, Covariance);
disp('line57')
graphics.exprs = exprs;
x.graphics = graphics;
x.model = model;
endLoop = %t;
// Check parameters
// You can add additional checks for input parameters here if needed
disp('line64')
// 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
model.state = [concatAB(initial_state,initial_covariance)];
model.rpar = initial_covariance; // Use the covariance matrix as a parameter
graphics.exprs = exprs;
x.graphics = graphics;
x.model = model;
break
message("Failed to update block io");
end
disp('line85')
// Concatenate the covariance matrix to the state vector
// model.state = [State; Covariance(:)]; // Use the concatenation operator ":" for the matrix
// Define block properties
disp('line89')
case "define" then
disp('line91')
// Create object
model = scicos_model();
disp('line93')
// Provide name and type
model.sim = list('Kalman_Filter_sim', 5); // what is case 4 and 5?
disp('line96')
// Define inputs and outputs
// One input with a variable-size "double" element
model.in = [2;2]; // first dimension of the first input whcih is row 2*1 and 2*2 hence it will be [2;2]
model.in2 = [1;2]; // the second dimension of I/P port is [1;2] from above
model.intyp = [1;1]; // all the vector and matrices are real value
disp('line101')
model.out = [2;2]; // first dimension of the first output whcih is row 2*1 and 2*2 hence it will be [2;2]
model.out2 = [1;2]; // the second dimension of O/P port is [1;2] from above
model.outtyp = [1;1]; // all the vector and matrices are real value
//model.state = [initial_state,matrix(initial_covariance)]; // Use the matrix concatenation operator ":" to convert matrix to column vector model.state=[State;Covariance]
model.state = [concatAB(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
disp('line109')
// Set block properties
exprs = ["[0.1; 0.0]";"1.0, 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
After line 89, it showing an error
** msg =
status =
T **
Can anyone direct me what is this error means?