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_maskparam(enable_conds)
% FUNCTION MPC555_MTRCTRL_MASKPARAM(ENABLE_CONDS)
%
% This function is used as a mask callback to enable/disable and optionally
% hide parameters in the block mask based on a series of string equality
% conditions.
% 
% An array of structures of form:
%        enable_conds(iCondition).param_names
%        enable_conds(iCondition).param_conditions
%        enable_conds(iCondition).to_enable
%        enable_conds(iCondition).to_disable
%        enable_conds(iCondition).to_hide
%        enable_conds(iCondition).reciprocal
% is passed to the function, and if the values in the mask parameters named
% in the cell array passed in 'param_names' are equal to the values passed
% in the cell array 'param_conditions', then the parameters named in
% 'to_enable' will be enabled and unhidden.  Those named in 'to_disable' will be
% disabled, and those named in 'to_hide' will be hidden.
%
% If the 'reciprocal' value is non-zero then if the conditions are NOT met
% then the to_enable and to_disable functions will be reversed.
function mpc555_mtrctrl_maskparam(enable_conds)

% Block to use is implicit from the mask from which it is called.
% Use gcb within THIS function
block = gcb;
for iCondition = 1:length(enable_conds)
    % Ensure that all structure fields are in place
    structure_fields = fieldnames(enable_conds(iCondition));
    for structure_required = {'param_names', 'param_conditions', 'to_enable', ...
            'to_disable', 'to_hide'}
       position = strmatch(structure_required, structure_fields, 'exact'); 
       if isempty(position)
           eval(['enable_conds(iCondition).', structure_required, '= {};']);
       end
    end
   position = strmatch('reciprocal', structure_fields, 'exact'); 
   if isempty(position)
      enable_conds(iCondition).reciprocal = 0; 
   end
    % Do the dirty work
    i_check_and_enable(block, ...
        enable_conds(iCondition).param_names, ...
        enable_conds(iCondition).param_conditions, ...
        enable_conds(iCondition).to_enable, ...
        enable_conds(iCondition).to_disable, ...
        enable_conds(iCondition).to_hide, ...
        enable_conds(iCondition).reciprocal);
end
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This function actually does the main body of the work for each structure
% in the structure array
%
function i_check_and_enable(block, param_names, param_conditions, ...
    to_enable, to_disable, to_hide, reciprocal)

% First of all check that the parameter conditions are met
param_values{length(param_names)} = [];
for iParam = 1:length(param_names)
    param_values{iParam} = get_param(block, param_names{iParam});
end
conditions_met = isequal(param_values, param_conditions);

% Return and don't do anything if the condition is not met unless the
% reciprocal mode is being used, in which case swap the functions to enable
% and disable
if ~conditions_met
    if ~(reciprocal == 0)
        to_temp = to_enable;  % Swap enable and disable
        to_enable = to_disable;
        to_disable = to_temp;
    else
        return;
    end
end

% Now need to enable and disable the mask parameters as appropriate
mask_names = get_param(block, 'MaskNames');
mask_enables = get_param(block, 'MaskEnables');
mask_visibles = get_param(block, 'MaskVisibilities');

% Enable mask parameters that have been specified
for iParam = 1:length(to_enable)
    position = strmatch(to_enable{iParam}, mask_names, 'exact');
    if isempty(position)
        error(['Mask parameter to enable: ', to_enable{iParam}, 'not found']);
    end
    mask_enables{position} = 'on';
    mask_visibles{position} = 'on';
end

% Disable mask parameters that have been specified
for iParam = 1:length(to_disable)
    position = strmatch(to_disable{iParam}, mask_names, 'exact');
    if isempty(position)
        error(['Mask parameter to disable: ', to_disable{iParam}, 'not found']);
    end
    mask_enables{position} = 'off';
end

% Hide mask parameters that have been specified
for iParam = 1:length(to_hide)
    position = strmatch(to_hide{iParam}, mask_names, 'exact');
    if isempty(position)
        error(['Mask parameter to hide: ', to_hide{iParam}, 'not found']);
    end
    mask_visibles{position} = 'off';
end

% And finally write back to the mask
set_param(block, 'MaskEnables', mask_enables);
set_param(block, 'MaskVisibilities', mask_visibles);

end

Contact us