Code covered by the BSD License  

Highlights from
MPC555 Motor Control Function Blockset

MPC555 Motor Control Function Blockset

by

 

20 Mar 2006 (Updated )

Additional I/O blocks for MPC555 target - specifically targetting TPU functionality

mpc555_mtrctrl_ekf(block, callback_fn, varargin)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% function mpc555_mtrctrl_ekf(block, callback_fn, varargin)
%
function mpc555_mtrctrl_ekf(block, callback_fn, varargin)
% This is the entry function to allow the appropriate callback functions to
% be run

% Get a list of parameters which would be valid to pass to this block
callback_params = get_param(block, 'MaskNames');

% Get a list of parameters which have specifications which must be adhered
% to
[f,c] = i_parameterspecs();

% Create a list of parameters which will be numerically validated
params_to_validate = c(:,1);

% Create a list of parameters to ignore
params_to_ignore = callback_params;
for a = 1:length(params_to_validate)
   paramtokill = strmatch(params_to_validate{a}, params_to_ignore, 'exact');
   params_to_ignore(paramtokill) = '';
end

switch callback_fn
    case params_to_validate
        [validate] = mpc555_mtrctrl_validate_mask_value(block, i_getparameterspecs(callback_fn));
    case params_to_ignore
        % Just save that the parameter has changed
        mpc555_mtrctrl_mask_copy_values(block, 'save');
        return;        
    otherwise
        error(['Invalid callback ', callback_fn]);
end
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% function [f,c] = i_parameterspecs()
%
function [f,c] = i_parameterspecs()

f = {'ParamName',               'PrettyName',               'MinVal',   'MaxVal',   'DataType', 'ArrayLengthMin',   'ArrayLengthMax',   'ErrorMessage', 'SpecialConditions'};

c = {'Rs',                      'Rs',                       0,          inf,         'double',   1,                  1,                  '',             []; ...
     'Rr',                      'Rr',                       0,          inf,         'double',   1,                  1,                  '',             []; ...
     'Lm',                      'Lm',                       0,          inf,         'double',   1,                  1,                  '',             []; ...
     'Lis',                     'Lis',                      0,          inf,         'double',   1,                  1,                  '',             []; ...
     'Lir',                     'Lir',                      0,          inf,         'double',   1,                  1,                  '',             []; ...
     'poles',                   'poles',                    0,          inf,         'double',   1,                  1,                  '',             []; ...
     'X0',                      'X0',                       -inf,       inf,         'double',   {5,1},              {5,1},                  '',             []; ...
     'P0',                      'P0',                       -inf,       inf,         'double',   {5,5},              {5,5},                  '',             []; ...
     'Q',                       'Q',                        -inf,       inf,         'double',   {5,5},              {5,5},                  '',             []; ...
     'R',                       'R',                        -inf,       inf,         'double',   {2,2},              {2,2},                  '',             []; ...
     'T',                       'T',                        0,          inf,         'double',   1,                  1,                  '',             []; ...     
     };

end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% function parameterspecs = i_getparameterspecs(varargin)
%
function parameterspecs = i_getparameterspecs(varargin)

% Get the raw table of parameterspecs
[f,c] = i_parameterspecs();

% Convert the table to a cell structure
parameterspecs = cell2struct(c,f,2);

switch nargin
    case 0 
        % If no parameters are specified when the function is called return
        % the whole list
        return;
    case 1
        % If a parameter is specified then return the specification
        % table for only this item
        paramnumber = strmatch(varargin(1), c(:,1), 'exact');
        if isempty(paramnumber)
           error(['Invalid parameter name ', varargin(1)]);
        else
           parameterspecs = parameterspecs(paramnumber); 
        end
    otherwise
        error('Invalid number of parameters')

end

end

Contact us