Issue in my class?
이전 댓글 표시
I am getting a very strange error when I try to initialize a class that I've written. properties of my class:
properties(GetAccess= 'private', SetAccess= 'private')
% Values require get and set methods to view or manipulate
% Sensor variables
odomDist; % Distance traveled since last check from odometry
% Format: double
odomAng; % Angle turned since last check from odometry
% Format: double
noise; % Contains noise data for sensors used
% Format: structure, fieldnames are sensor names and
% field values are sensor noise [mean standard_dev]
comDelay; % Communication delay of commands to robot
% Format: double
% Robot state variables
posAbs; % Position in absolute coordinates
% Format: vector of doubles, [x y]
velAbs; % Velocity in absolute coordinates
% Format: vector of doubles, [x y]
thAbs; % Yaw angle relative to positive x-axis
% Format: double (-pi < thAbs <= pi)
wAbs; % Angular velocity
% Format: double (positive counter-clockwise)
velInt; % Forward velocity intended by motor commands
% Format: double
wInt; % Angular velocity intended by motor commands
% Format: double
dataHist; % Time history of position and function calls for output
% Format: cell array, columns
% [time x y th fcn_called arg_val]
% time - Double, time relative to start of autonomous code
% x - Double, x-coordinate of center of robot
% y - Double, y-coordinate of center of robot
% th - Double, angle of robot relative to pos x-axis
% fcn_called - String or cell array of strings,
% name(s) of the function(s) called in that time step
% arg_val - Vector of doubles or cell array of vectors,
% value(s) for the input OR output argument(s);
% the robot object argument is ignored
% Environment variables
timeElap; % Time of the start of autonomous code execution
% Format: unsigned 64 bit integer
% time syntax - to be used with toc function
handlesGUI; % Handles to all GUI objects
% Format: structure containing handle numbers
% See SimulatorGUI.fig and SimulatorGUI.m for more
% format information on the contents of the structure
XY;
Ramp_Center;
Ramp_Entrance;
Ramp_Exit;
Target;
%positions of the sensors:
IR1;
IR2;
IR3;
IR4;
IR5;
%positions of the four corners;
p1;
p2;
p3;
p4;
body_array = zeros(4,4);
%sensor value array
sensor_vals = [0 0 0 0];
%wall array to calculate the the sensor hits:
wall_array = zeros(size(XY,1), 4);
%array of lines representing the IR sensors:
IR_array = zeros(5, 4);
%STATE VARIABLES;
%the current state
CURRENT_STATE;
%the next state
NEXT_STATE;
%collision
COLLIDED;
%distance to move
dist;
%theta to turn
thetadelta;
end
My constructor:
function obj= Rover8(varargin)
% obj = RedRover
% Creates instance of the user-defined class Create Robot and
% initializes all properties. Note that if RedRover is not
% called by SimulatorGUI (with handlesGUI argument), full
% functionality impossible.
%
% obj = RedRover(handlesGUI)
% Format of function call from SimulatorGUI. Passes along structure
% of handles for the GUI to allow full functionality
%
% Input:
% handlesGUI - Structure of handles to GUI objects
% e.g. handlesGUI.push_adv - handle for advance button
%
% Output:
% obj - Instance of class RedRover with all fields initialized
% Deal with input argument
% Will be handles to SimulatorGUI if called by simulator
if ~isempty(varargin) && isstruct(varargin{1})
obj.handlesGUI= varargin{1};
else
obj.handlesGUI= [];
end
% Assign properties
obj.timeElap= [];
obj.dataHist= {};
obj.noise= struct; % Empty structure to store noise data
obj.comDelay= 0; % Default instantaneous communication
obj.posAbs= [0 0]; % Initial position
obj.velAbs= [0 0]; % Assume robot is stationary to start
obj.thAbs= 0;
obj.wAbs= 0;
obj.velInt= 0;
obj.wInt= 0;
obj.CURRENT_STATE = 0;
obj.NEXT_STATE = 0;
obj.COLLIDED = false;
%set the positions of the sensors:
updateSensorPos(obj);
%set map vals
end
However, whenever I call this constructor from my i get the error: Undefined function or variable 'XY'.
Clearly XY is in the class so why am I getting this error? Any help is appreciated greatly.
댓글 수: 1
Guillaume
2014년 11월 23일
Can you attach your class m file, assuming it's just one file?
It would be easier to figure out the problem that way.
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Construct and Work with Object Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!