image thumbnail

Using Model-Based Design for Vehicle Electronics Applications

by

 

29 Aug 2006 (Updated )

This ZIP-file contains the presentation and power window model that was used in the MathWorks webina

pmJointInfo (hBlk,watchPort)
function [primList,isConnected,hJointBlk,retStatus] = pmJointInfo (hBlk,watchPort)
% Copyright 2005 The MathWorks, Inc.

retStatus = false;
ignoreBranchingBars = true;
isConnected = false;
primList = [];
hJointBlk = -1;
getNeighbors = mech_private('pmNeighbors');

if isempty (watchPort)
    myNbr = getNeighbors(hBlk, 1, [], [], ignoreBranchingBars);
else
    nbrBlk = -1; %#ok
    nbrPort = -1;%#ok
    portInfo = get_param (hBlk, 'PortConnectivity');
    matchIdx = find (strcmpi (watchPort, {portInfo(:).Type}));
    if ~isempty (matchIdx) && ~isempty (portInfo(matchIdx(1)).DstBlock)
        nbrBlk = portInfo(matchIdx(1)).DstBlock;
        nbrPort = portInfo(matchIdx(1)).DstPort;
    end

    myNbr = getNeighbors(hBlk, 1, nbrBlk, nbrPort, ignoreBranchingBars);
end

numNbrs = numel(myNbr);

for idx = 1:numNbrs
    if (local_isaJoint(myNbr(idx)))
        isConnected = true;
        jointBlk = myNbr(idx);
        hJointBlk = get_param(jointBlk, 'Handle');
        propStr = get_param(jointBlk, 'PrimitiveProps');

        if (~isempty (propStr))
            try
                ser = MECH.PMSerializer;
                % Deserialize in Primitive list
                tmpList = ser.deserializePrimitive (propStr);

                nFrames = numel (tmpList);

                % Convert to MechPrimitiveHelper object array
                for idx1 = 1:nFrames
                    if isempty (primList)
                        primList = MECH.MechPrimitiveHelper (tmpList(idx1));
                    else
                        primList(end+1) = MECH.MechPrimitiveHelper (tmpList(idx1)); %#ok<AGROW>
                    end
                end
                retStatus = true;
                
            catch
                retStatus = false; %#ok<NASGU>
                error (xlate('Expecting a joint block handle.'));
                rethrow (lasterror);
            end
        end
    end
end

function retVal = local_isaJoint( hBlk )
% Checks to see of the block handle 'hBlk' points to a SimMech joint
% block.  Returns true = is a joint else false.

retVal = false;
blkClassName = []; %#ok
paramLst = get_param (hBlk, 'ObjectParameters');
if isfield (paramLst, 'ClassName')
    blkClassName = get_param (hBlk, 'ClassName');
end

if (~isempty (blkClassName))

    switch (blkClassName)
        case {'Joint', 'PlanarJoint', 'BearingJoint', 'InplaneJoint',...
                'CylindricalJoint', 'ScrewJoint', 'DisassembledCylindrical',...
                'DisassembledRevolute', 'DisassembledPrismatic',...
                'DisassembledSpherical', 'MasslessRR', 'MasslessRS', 'MasslessSS'}
            retVal = true;
        otherwise
            retVal = false;
    end
end

Contact us