www.gusucode.com > ros 工具箱 matlab源码程序 > ros/+robotics/+ros/+msggen/+people_msgs/Person.m
classdef Person < robotics.ros.Message %Person MATLAB implementation of people_msgs/Person % This class was automatically generated by % robotics.ros.msg.internal.gen.MessageClassGenerator. % Copyright 2014-2016 The MathWorks, Inc. %#ok<*INUSD> properties (Constant) MessageType = 'people_msgs/Person' % The ROS message type end properties (Constant, Hidden) MD5Checksum = '0b7c0818b76476f3863bd13f4d59f8df' % The MD5 Checksum of the message definition end properties (Access = protected) JavaMessage % The Java message object end properties (Constant, Access = protected) GeometryMsgsPointClass = robotics.ros.msg.internal.MessageFactory.getClassForType('geometry_msgs/Point') % Dispatch to MATLAB class for message type geometry_msgs/Point end properties (Dependent) Name Position Velocity Reliability Tagnames Tags end properties (Access = protected) Cache = struct('Position', [], 'Velocity', []) % The cache for fast data access end properties (Constant, Hidden) PropertyList = {'Name', 'Position', 'Reliability', 'Tagnames', 'Tags', 'Velocity'} % List of non-constant message properties ROSPropertyList = {'name', 'position', 'reliability', 'tagnames', 'tags', 'velocity'} % List of non-constant ROS message properties end methods function obj = Person(msg) %Person Construct the message object Person 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 name = get.Name(obj) %get.Name Get the value for property Name name = char(obj.JavaMessage.getName); end function set.Name(obj, name) %set.Name Set the value for property Name validateattributes(name, {'char'}, {}, 'Person', 'Name'); obj.JavaMessage.setName(name); end function position = get.Position(obj) %get.Position Get the value for property Position if isempty(obj.Cache.Position) obj.Cache.Position = feval(obj.GeometryMsgsPointClass, obj.JavaMessage.getPosition); end position = obj.Cache.Position; end function set.Position(obj, position) %set.Position Set the value for property Position validateattributes(position, {obj.GeometryMsgsPointClass}, {'nonempty', 'scalar'}, 'Person', 'Position'); obj.JavaMessage.setPosition(position.getJavaObject); % Update cache if necessary if ~isempty(obj.Cache.Position) obj.Cache.Position.setJavaObject(position.getJavaObject); end end function velocity = get.Velocity(obj) %get.Velocity Get the value for property Velocity if isempty(obj.Cache.Velocity) obj.Cache.Velocity = feval(obj.GeometryMsgsPointClass, obj.JavaMessage.getVelocity); end velocity = obj.Cache.Velocity; end function set.Velocity(obj, velocity) %set.Velocity Set the value for property Velocity validateattributes(velocity, {obj.GeometryMsgsPointClass}, {'nonempty', 'scalar'}, 'Person', 'Velocity'); obj.JavaMessage.setVelocity(velocity.getJavaObject); % Update cache if necessary if ~isempty(obj.Cache.Velocity) obj.Cache.Velocity.setJavaObject(velocity.getJavaObject); end end function reliability = get.Reliability(obj) %get.Reliability Get the value for property Reliability reliability = double(obj.JavaMessage.getReliability); end function set.Reliability(obj, reliability) %set.Reliability Set the value for property Reliability validateattributes(reliability, {'numeric'}, {'nonempty', 'scalar'}, 'Person', 'Reliability'); obj.JavaMessage.setReliability(reliability); end function tagnames = get.Tagnames(obj) %get.Tagnames Get the value for property Tagnames javaArray = obj.JavaMessage.getTagnames; array = obj.readJavaArray(javaArray, 'char'); tagnames = arrayfun(@(x) char(x), array, 'UniformOutput', false); end function set.Tagnames(obj, tagnames) %set.Tagnames Set the value for property Tagnames if ~isvector(tagnames) && isempty(tagnames) % Allow empty [] input tagnames = cell.empty(0,1); end validateattributes(tagnames, {'cell'}, {'vector'}, 'Person', 'Tagnames'); if any(cellfun(@(x) ~ischar(x), tagnames)) error(message('robotics:ros:message:CellArrayStringError', ... 'tagnames')); end javaArray = obj.JavaMessage.getTagnames; array = obj.writeJavaArray(tagnames, javaArray, 'char'); obj.JavaMessage.setTagnames(array); end function tags = get.Tags(obj) %get.Tags Get the value for property Tags javaArray = obj.JavaMessage.getTags; array = obj.readJavaArray(javaArray, 'char'); tags = arrayfun(@(x) char(x), array, 'UniformOutput', false); end function set.Tags(obj, tags) %set.Tags Set the value for property Tags if ~isvector(tags) && isempty(tags) % Allow empty [] input tags = cell.empty(0,1); end validateattributes(tags, {'cell'}, {'vector'}, 'Person', 'Tags'); if any(cellfun(@(x) ~ischar(x), tags)) error(message('robotics:ros:message:CellArrayStringError', ... 'tags')); end javaArray = obj.JavaMessage.getTags; array = obj.writeJavaArray(tags, javaArray, 'char'); obj.JavaMessage.setTags(array); end end methods (Access = protected) function resetCache(obj) %resetCache Resets any cached properties obj.Cache.Position = []; obj.Cache.Velocity = []; 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.Name = obj.Name; cpObj.Reliability = obj.Reliability; cpObj.Tagnames = obj.Tagnames; cpObj.Tags = obj.Tags; % Recursively copy compound properties cpObj.Position = copy(obj.Position); cpObj.Velocity = copy(obj.Velocity); end function reload(obj, strObj) %reload Called by loadobj to assign properties obj.Name = strObj.Name; obj.Reliability = strObj.Reliability; obj.Tagnames = strObj.Tagnames; obj.Tags = strObj.Tags; obj.Position = feval([obj.GeometryMsgsPointClass '.loadobj'], strObj.Position); obj.Velocity = feval([obj.GeometryMsgsPointClass '.loadobj'], strObj.Velocity); 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.Name = obj.Name; strObj.Reliability = obj.Reliability; strObj.Tagnames = obj.Tagnames; strObj.Tags = obj.Tags; strObj.Position = saveobj(obj.Position); strObj.Velocity = saveobj(obj.Velocity); 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.people_msgs.Person.empty(0,1); return end % Create an empty message object obj = robotics.ros.msggen.people_msgs.Person; obj.reload(strObj); end end end