www.gusucode.com > ros 工具箱 matlab源码程序 > ros/+robotics/+ros/+msggen/+manipulation_msgs/GraspableObject.m

    classdef GraspableObject < robotics.ros.Message
    %GraspableObject MATLAB implementation of manipulation_msgs/GraspableObject
    %   This class was automatically generated by
    %   robotics.ros.msg.internal.gen.MessageClassGenerator.
    
    %   Copyright 2014-2016 The MathWorks, Inc.
    
    %#ok<*INUSD>
    
    properties (Constant)
        MessageType = 'manipulation_msgs/GraspableObject' % The ROS message type
    end
    
    properties (Constant, Hidden)
        MD5Checksum = 'e2efd13d8e2bbb4697a5d71f167bceaa' % The MD5 Checksum of the message definition
    end
    
    properties (Access = protected)
        JavaMessage % The Java message object
    end
    
    properties (Constant, Access = protected)
        HouseholdObjectsDatabaseMsgsDatabaseModelPoseClass = robotics.ros.msg.internal.MessageFactory.getClassForType('household_objects_database_msgs/DatabaseModelPose') % Dispatch to MATLAB class for message type household_objects_database_msgs/DatabaseModelPose
        ManipulationMsgsSceneRegionClass = robotics.ros.msg.internal.MessageFactory.getClassForType('manipulation_msgs/SceneRegion') % Dispatch to MATLAB class for message type manipulation_msgs/SceneRegion
        SensorMsgsPointCloudClass = robotics.ros.msg.internal.MessageFactory.getClassForType('sensor_msgs/PointCloud') % Dispatch to MATLAB class for message type sensor_msgs/PointCloud
    end
    
    properties (Dependent)
        ReferenceFrameId
        Cluster
        Region
        CollisionName
        PotentialModels
    end
    
    properties (Access = protected)
        Cache = struct('PotentialModels', [], 'Cluster', [], 'Region', []) % The cache for fast data access
    end
    
    properties (Constant, Hidden)
        PropertyList = {'Cluster', 'CollisionName', 'PotentialModels', 'ReferenceFrameId', 'Region'} % List of non-constant message properties
        ROSPropertyList = {'cluster', 'collision_name', 'potential_models', 'reference_frame_id', 'region'} % List of non-constant ROS message properties
    end
    
    methods
        function obj = GraspableObject(msg)
            %GraspableObject Construct the message object GraspableObject
            import com.mathworks.toolbox.robotics.ros.message.MessageInfo;
            
            % Support default constructor
            if nargin == 0
                obj.JavaMessage = obj.createNewJavaMessage;
                return;
            end
            
            % Construct appropriate empty array
            if isempty(msg)
                obj = obj.empty(0,1);
                return;
            end
            
            % Make scalar construction fast
            if isscalar(msg)
                % Check for correct input class
                if ~MessageInfo.compareTypes(msg(1), obj.MessageType)
                    error(message('robotics:ros:message:NoTypeMatch', obj.MessageType, ...
                        char(MessageInfo.getType(msg(1))) ));
                end
                obj.JavaMessage = msg(1);
                return;
            end
            
            % Check that this is a vector of scalar messages. Since this
            % is an object array, use arrayfun to verify.
            if ~all(arrayfun(@isscalar, msg))
                error(message('robotics:ros:message:MessageArraySizeError'));
            end
            
            % Check that all messages in the array have the correct type
            if ~all(arrayfun(@(x) MessageInfo.compareTypes(x, obj.MessageType), msg))
                error(message('robotics:ros:message:NoTypeMatchArray', obj.MessageType));
            end
            
            % Construct array of objects if necessary
            objType = class(obj);
            for i = 1:length(msg)
                obj(i,1) = feval(objType, msg(i)); %#ok<AGROW>
            end
        end
        
        function referenceframeid = get.ReferenceFrameId(obj)
            %get.ReferenceFrameId Get the value for property ReferenceFrameId
            referenceframeid = char(obj.JavaMessage.getReferenceFrameId);
        end
        
        function set.ReferenceFrameId(obj, referenceframeid)
            %set.ReferenceFrameId Set the value for property ReferenceFrameId
            validateattributes(referenceframeid, {'char'}, {}, 'GraspableObject', 'ReferenceFrameId');
            
            obj.JavaMessage.setReferenceFrameId(referenceframeid);
        end
        
        function cluster = get.Cluster(obj)
            %get.Cluster Get the value for property Cluster
            if isempty(obj.Cache.Cluster)
                obj.Cache.Cluster = feval(obj.SensorMsgsPointCloudClass, obj.JavaMessage.getCluster);
            end
            cluster = obj.Cache.Cluster;
        end
        
        function set.Cluster(obj, cluster)
            %set.Cluster Set the value for property Cluster
            validateattributes(cluster, {obj.SensorMsgsPointCloudClass}, {'nonempty', 'scalar'}, 'GraspableObject', 'Cluster');
            
            obj.JavaMessage.setCluster(cluster.getJavaObject);
            
            % Update cache if necessary
            if ~isempty(obj.Cache.Cluster)
                obj.Cache.Cluster.setJavaObject(cluster.getJavaObject);
            end
        end
        
        function region = get.Region(obj)
            %get.Region Get the value for property Region
            if isempty(obj.Cache.Region)
                obj.Cache.Region = feval(obj.ManipulationMsgsSceneRegionClass, obj.JavaMessage.getRegion);
            end
            region = obj.Cache.Region;
        end
        
        function set.Region(obj, region)
            %set.Region Set the value for property Region
            validateattributes(region, {obj.ManipulationMsgsSceneRegionClass}, {'nonempty', 'scalar'}, 'GraspableObject', 'Region');
            
            obj.JavaMessage.setRegion(region.getJavaObject);
            
            % Update cache if necessary
            if ~isempty(obj.Cache.Region)
                obj.Cache.Region.setJavaObject(region.getJavaObject);
            end
        end
        
        function collisionname = get.CollisionName(obj)
            %get.CollisionName Get the value for property CollisionName
            collisionname = char(obj.JavaMessage.getCollisionName);
        end
        
        function set.CollisionName(obj, collisionname)
            %set.CollisionName Set the value for property CollisionName
            validateattributes(collisionname, {'char'}, {}, 'GraspableObject', 'CollisionName');
            
            obj.JavaMessage.setCollisionName(collisionname);
        end
        
        function potentialmodels = get.PotentialModels(obj)
            %get.PotentialModels Get the value for property PotentialModels
            if isempty(obj.Cache.PotentialModels)
                javaArray = obj.JavaMessage.getPotentialModels;
                array = obj.readJavaArray(javaArray, obj.HouseholdObjectsDatabaseMsgsDatabaseModelPoseClass);
                obj.Cache.PotentialModels = feval(obj.HouseholdObjectsDatabaseMsgsDatabaseModelPoseClass, array);
            end
            potentialmodels = obj.Cache.PotentialModels;
        end
        
        function set.PotentialModels(obj, potentialmodels)
            %set.PotentialModels Set the value for property PotentialModels
            if ~isvector(potentialmodels) && isempty(potentialmodels)
                % Allow empty [] input
                potentialmodels = feval([obj.HouseholdObjectsDatabaseMsgsDatabaseModelPoseClass '.empty'], 0, 1);
            end
            
            validateattributes(potentialmodels, {obj.HouseholdObjectsDatabaseMsgsDatabaseModelPoseClass}, {'vector'}, 'GraspableObject', 'PotentialModels');
            
            javaArray = obj.JavaMessage.getPotentialModels;
            array = obj.writeJavaArray(potentialmodels, javaArray, obj.HouseholdObjectsDatabaseMsgsDatabaseModelPoseClass);
            obj.JavaMessage.setPotentialModels(array);
            
            % Update cache if necessary
            if ~isempty(obj.Cache.PotentialModels)
                obj.Cache.PotentialModels = [];
                obj.Cache.PotentialModels = obj.PotentialModels;
            end
        end
    end
    
    methods (Access = protected)
        function resetCache(obj)
            %resetCache Resets any cached properties
            obj.Cache.PotentialModels = [];
            obj.Cache.Cluster = [];
            obj.Cache.Region = [];
        end
        
        function cpObj = copyElement(obj)
            %copyElement Implements deep copy behavior for message
            
            % Call default copy method for shallow copy
            cpObj = copyElement@robotics.ros.Message(obj);
            
            % Clear any existing cached properties
            cpObj.resetCache;
            
            % Create a new Java message object
            cpObj.JavaMessage = obj.createNewJavaMessage;
            
            % Iterate over all primitive properties
            cpObj.ReferenceFrameId = obj.ReferenceFrameId;
            cpObj.CollisionName = obj.CollisionName;
            
            % Recursively copy compound properties
            cpObj.Cluster = copy(obj.Cluster);
            cpObj.Region = copy(obj.Region);
            cpObj.PotentialModels = copy(obj.PotentialModels);
        end
        
        function reload(obj, strObj)
            %reload Called by loadobj to assign properties
            obj.ReferenceFrameId = strObj.ReferenceFrameId;
            obj.CollisionName = strObj.CollisionName;
            obj.Cluster = feval([obj.SensorMsgsPointCloudClass '.loadobj'], strObj.Cluster);
            obj.Region = feval([obj.ManipulationMsgsSceneRegionClass '.loadobj'], strObj.Region);
            PotentialModelsCell = arrayfun(@(x) feval([obj.HouseholdObjectsDatabaseMsgsDatabaseModelPoseClass '.loadobj'], x), strObj.PotentialModels, 'UniformOutput', false);
            obj.PotentialModels = vertcat(PotentialModelsCell{:});
        end
    end
    
    methods (Access = ?robotics.ros.Message)
        function strObj = saveobj(obj)
            %saveobj Implements saving of message to MAT file
            
            % Return an empty element if object array is empty
            if isempty(obj)
                strObj = struct.empty;
                return
            end
            
            strObj.ReferenceFrameId = obj.ReferenceFrameId;
            strObj.CollisionName = obj.CollisionName;
            strObj.Cluster = saveobj(obj.Cluster);
            strObj.Region = saveobj(obj.Region);
            strObj.PotentialModels = arrayfun(@(x) saveobj(x), obj.PotentialModels);
        end
    end
    
    methods (Static, Access = {?matlab.unittest.TestCase, ?robotics.ros.Message})
        function obj = loadobj(strObj)
            %loadobj Implements loading of message from MAT file
            
            % Return an empty object array if the structure element is not defined
            if isempty(strObj)
                obj = robotics.ros.msggen.manipulation_msgs.GraspableObject.empty(0,1);
                return
            end
            
            % Create an empty message object
            obj = robotics.ros.msggen.manipulation_msgs.GraspableObject;
            obj.reload(strObj);
        end
    end
end