# Xcos model set error - scicos\_new: Wrong value for input argument #2: unable to set "model"

**URL:** <https://scilab.discourse.group/t/xcos-model-set-error-scicos-new-wrong-value-for-input-argument-2-unable-to-set-model/469>\
**Category:** Xcos\
**Created:** [April 16, 2024, 10:08pm UTC](https://scilab.discourse.group/t/xcos-model-set-error-scicos-new-wrong-value-for-input-argument-2-unable-to-set-model/469 "2024-04-16T22:08:12Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vimsrocz](https://avatars.discourse-cdn.com/v4/letter/v/ed8c4c/32.png) [@Vimsrocz](https://scilab.discourse.group/u/Vimsrocz)\
**Post date:** [April 16, 2024, 10:08pm UTC](https://scilab.discourse.group/t/xcos-model-set-error-scicos-new-wrong-value-for-input-argument-2-unable-to-set-model/469/1 "2024-04-16T22:08:13Z")

</div>

As per mention in the Xcos block setup [Block Parameters](https://help.scilab.org/scicos_model).  
There is requirement of two file for block in XCOS. Simulation file and Interface file. Model setup has error in the interface file and code is

```auto
// 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;
            
            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,1], '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] = 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 State>0 // first condition of position and velocity
                            errMsg = ["The velocity is positive [m/s]"];
                        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
                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
            // Concatenate the covariance matrix to the state vector
            // model.state = [State; Covariance(:)]; // Use the concatenation operator ":" for the matrix
        // Define block properties
        case 'define'
            // 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 = [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
            
            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

            // 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

```

The error is  
\>! Building macros…  
\>! Creation of [spacecraft\_gnc\_tbxlib] (Macros) –  
\>! genlib: Processing file: Common\_Utils.sci  
\>! genlib: Processing file: GravityGradient\_Utils.sci  
\>! genlib: Processing file: Gyroscope\_SIM.sci  
\>! genlib: Processing file: Gyroscope\_Utils.sci  
\>! genlib: Processing file: Kalman\_Filter\_IF.sci  
\>! genlib: Processing file: Kalman\_Filter\_IF.sci~  
\>! genlib: Processing file: Kalman\_Filter\_Utils.sci  
\>! genlib: Processing file: MagneticField\_Utils.sci  
\>! genlib: Processing file: Magnetometer\_Utils.sci  
\>! genlib: Processing file: Magnetorquer\_Utils.sci  
\>! genlib: Processing file: ReactionWheel\_Utils.sci  
\>! genlib: Processing file: RigidBody\_Utils.sci  
\>! genlib: Processing file: StarTracker\_Utils.sci  
\>! Building blocks…  
\>! at line 8 of function scicos\_block ( C:\Program Files\scilab-2024.0.0\modules\scicos\macros\scicos\_scicos\scicos\_block.sci line 29 )  
\>! at line 29 of function standard\_define ( C:\Program Files\scilab-2024.0.0\modules\scicos\macros\scicos\_scicos\standard\_define.sci line 50 )  
\>! at line 110 of function Kalman\_Filter\_IF ( C:\Users\Vims\Desktop\spacecraft-gnc-tbx\macros\Kalman\_Filter\_IF.sci line 141 )  
\>! at line 1 of executed string  
\>! at line 78 of function tbx\_build\_blocks ( C:\Program Files\scilab-2024.0.0\modules\modules\_manager\macros\tbx\_build\_blocks.sci line 90 )  
\>! at line 7 of function buildmacros ( C:\Users\Vims\Desktop\spacecraft-gnc-tbx\macros\buildmacros.sce line 10 )  
\>! at line 14 of executed file C:\Users\Vims\Desktop\spacecraft-gnc-tbx\macros\buildmacros.sce  
\>! at line 13 of function tbx\_builder ( C:\Program Files\scilab-2024.0.0\modules\modules\_manager\macros\tbx\_builder.sci line 26 )  
\>! at line 40 of function tbx\_builder\_macros ( C:\Program Files\scilab-2024.0.0\modules\modules\_manager\macros\tbx\_builder\_macros.sci line 55 )  
\>! at line 34 of function main\_builder ( C:\Users\Vims\Desktop\spacecraft-gnc-tbx\builder.sce line 43 )  
\>! at line 50 of executed file C:\Users\Vims\Desktop\spacecraft-gnc-tbx\builder.sce  
\>!  
\>! scicos\_new: Wrong value for input argument #2: unable to set “model”.  
Can you please point out that where is the error?
