Robot.plot MATLAB R2013b error

21 views (last 30 days)
Hello everyone,
I am new here to the forums. I am a bit familiar with MATLAB codes, but still consider myself a novice. I have just recently starting using Peter Corke's Toolbox using a GUI, and I have been running into some trouble concerning some of the commands. Basically, what I am trying to do is learn more about it, and decided to look up some tutorials online to get things started, and hopefully learn on my own from there. This is the one I've been trying to replicate, by the way:
https://www.youtube.com/watch?v=xF1KaINQwa8
I don't know how this guy exactly did it, but I ran all the codes exactly the same way, but I got errors upon errors from constructors not being using properly to attributes not belonging to certain variables, etc. So, I started fixing every single line of code so that it works in my MATLAB R2013b IDE, and surprisingly, they did! Well... almost. You probably already guessed from the title what the problem is. Robot.plot just won't plot! It's such a huge pain in the rear, and it's driving me crazy.
Attempt to reference field of non-structure array.
Error in SerialLink/plot>create_robot (line 470)
d = [ax.XLim ax.YLim ax.ZLim];
Error in SerialLink/plot (line 252)
handle = create_robot(robot, opt);
Error in Simple_Robotic_Arm>ForwardButton_Callback (line 262)
Robot.plot(Tff,'floorlevel', 0);
Error in gui_mainfcn (line 96)
feval(varargin{:});
Error in Simple_Robotic_Arm (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in @(hObject,eventdata)Simple_Robotic_Arm('ForwardButton_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback
Everything is working just fine aside from this particular error. I can tell that it has something to do with the plot limits not being identified for the SerialLink, but I just don't know how to tackle that. I mean, I tried a lot using the basic xlim and ylim that we get with the 'plot' function. I also tried using 'ax' and 'axes' to try and define it, to 'set' the limits for X, Y and Z, but to no avail. It's always the same error. As for the code itself, it's right here:
function varargout = Simple_Robotic_Arm(varargin)
% SIMPLE_ROBOTIC_ARM MATLAB code for Simple_Robotic_Arm.fig
% SIMPLE_ROBOTIC_ARM, by itself, creates a new SIMPLE_ROBOTIC_ARM or raises the existing
% singleton*.
%
% H = SIMPLE_ROBOTIC_ARM returns the handle to a new SIMPLE_ROBOTIC_ARM or the handle to
% the existing singleton*.
%
% SIMPLE_ROBOTIC_ARM('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in SIMPLE_ROBOTIC_ARM.M with the given input arguments.
%
% SIMPLE_ROBOTIC_ARM('Property','Value',...) creates a new SIMPLE_ROBOTIC_ARM or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before Simple_Robotic_Arm_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to Simple_Robotic_Arm_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help Simple_Robotic_Arm
% Last Modified by GUIDE v2.5 20-May-2020 01:44:52
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @Simple_Robotic_Arm_OpeningFcn, ...
'gui_OutputFcn', @Simple_Robotic_Arm_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before Simple_Robotic_Arm is made visible.
function Simple_Robotic_Arm_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to Simple_Robotic_Arm (see VARARGIN)
% Choose default command line output for Simple_Robotic_Arm
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes Simple_Robotic_Arm wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = Simple_Robotic_Arm_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
function Theta1_Callback(hObject, eventdata, handles)
% hObject handle to Theta1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of Theta1 as text
% str2double(get(hObject,'String')) returns contents of Theta1 as a double
% --- Executes during object creation, after setting all properties.
function Theta1_CreateFcn(hObject, eventdata, handles)
% hObject handle to Theta1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function Theta2_Callback(hObject, eventdata, handles)
% hObject handle to Theta2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of Theta2 as text
% str2double(get(hObject,'String')) returns contents of Theta2 as a double
% --- Executes during object creation, after setting all properties.
function Theta2_CreateFcn(hObject, eventdata, handles)
% hObject handle to Theta2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function Theta3_Callback(hObject, eventdata, handles)
% hObject handle to Theta3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of Theta3 as text
% str2double(get(hObject,'String')) returns contents of Theta3 as a double
% --- Executes during object creation, after setting all properties.
function Theta3_CreateFcn(hObject, eventdata, handles)
% hObject handle to Theta3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function Pos_X_Callback(hObject, eventdata, handles)
% hObject handle to Pos_X (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of Pos_X as text
% str2double(get(hObject,'String')) returns contents of Pos_X as a double
% --- Executes during object creation, after setting all properties.
function Pos_X_CreateFcn(hObject, eventdata, handles)
% hObject handle to Pos_X (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function Pos_Y_Callback(hObject, eventdata, handles)
% hObject handle to Pos_Y (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of Pos_Y as text
% str2double(get(hObject,'String')) returns contents of Pos_Y as a double
% --- Executes during object creation, after setting all properties.
function Pos_Y_CreateFcn(hObject, eventdata, handles)
% hObject handle to Pos_Y (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function Pos_Z_Callback(hObject, eventdata, handles)
% hObject handle to Pos_Z (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of Pos_Z as text
% str2double(get(hObject,'String')) returns contents of Pos_Z as a double
% --- Executes during object creation, after setting all properties.
function Pos_Z_CreateFcn(hObject, eventdata, handles)
% hObject handle to Pos_Z (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in ForwardButton.
function ForwardButton_Callback(hObject, eventdata, handles)
% hObject handle to ForwardButton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
cla(handles.axes1,'reset');
%Get values for angles
T_1 = get(handles.Theta1,'String');
T_2 = get(handles.Theta2,'String');
T_3 = get(handles.Theta3,'String');
%Convert values from String to Double
T_1 = str2double(T_1);
T_2 = str2double(T_2);
T_3 = str2double(T_3);
%Get values for links
L_1 = get(handles.Link1,'String');
L_2 = get(handles.Link2,'String');
L_3 = get(handles.Link3,'String');
%Convert values from String to Double
L_1 = str2double(L_1);
L_2 = str2double(L_2);
L_3 = str2double(L_3);
L(1)=Link([0 L_1 0 pi/2]);
L(2)=Link([0 0 L_2 0]);
L(3)=Link([0 0 L_3 0]);
Robot = SerialLink(L);
Robot.name='Robotic Arm';
Tff=[T_1, T_2, T_3];
Tm = Robot.fkine(Tff);
Tm = Tm.T;
X = num2str(Tm(1,4));
Y = num2str(Tm(2,4));
Z = num2str(Tm(3,4));
set(handles.Pos_X,'String',X);
set(handles.Pos_Y,'String',Y);
set(handles.Pos_Z,'String',Z);
drawnow
view(45,30);
Robot.display;
%set(gca,'XLim',[0 1000], 'YLim', [0 1000], 'Zlim', [0 1000]);
%Robot.plot(Tff,'workspace', [0, 1000, 0, 1000, 0, 1000]);
Robot.plot(Tff,'floorlevel', 0);
% --- Executes on button press in ReverseButton.
function ReverseButton_Callback(hObject, eventdata, handles)
% hObject handle to ReverseButton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
PX = get(handles.Pos_X,'String');
PY = get(handles.Pos_Y,'String');
PZ = get(handles.Pos_Z,'String');
PX = str2double(PX);
PY = str2double(PY);
PZ = str2double(PZ);
L_1 = get(handles.Link1,'String');
L_2 = get(handles.Link2,'String');
L_3 = get(handles.Link3,'String');
L_1 = str2double(L_1);
L_2 = str2double(L_2);
L_3 = str2double(L_3);
L(1)=Link([0 L_1 0 pi/2]);
L(2)=Link([0 0 L_2 0]);
L(3)=Link([0 0 L_3 0]);
Robot = SerialLink(L);
Robot.name='Robotic Arm';
T = [1 0 0 PX; 0 1 0 PY; 0 0 1 PZ; 0 0 0 1];
J = Robot.ikine(T, [0 0 0],'mask', [1 1 1 0 0 0])*180/pi;%Mask has to be included to draw the Inverse Kinematics
set(handles.Theta1,'String',num2str(J(1)));
set(handles.Theta2,'String',num2str(J(2)));
set(handles.Theta3,'String',num2str(J(3)));
drawnow
view(45,30);
%Robot.plot(J*pi/180);
function Link1_Callback(hObject, eventdata, handles)
% hObject handle to Link1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of Link1 as text
% str2double(get(hObject,'String')) returns contents of Link1 as a double
% --- Executes during object creation, after setting all properties.
function Link1_CreateFcn(hObject, eventdata, handles)
% hObject handle to Link1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function Link2_Callback(hObject, eventdata, handles)
% hObject handle to Link2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of Link2 as text
% str2double(get(hObject,'String')) returns contents of Link2 as a double
% --- Executes during object creation, after setting all properties.
function Link2_CreateFcn(hObject, eventdata, handles)
% hObject handle to Link2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function Link3_Callback(hObject, eventdata, handles)
% hObject handle to Link3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of Link3 as text
% str2double(get(hObject,'String')) returns contents of Link3 as a double
% --- Executes during object creation, after setting all properties.
function Link3_CreateFcn(hObject, eventdata, handles)
% hObject handle to Link3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end

Accepted Answer

Steven Lord
Steven Lord on 20 May 2020
If ax is the axes into which you're trying to plot the robot, I believe the reason for the error is that the plotting code was written using some of the functionality introduced in release R2014b with the major upgrade of the graphics system. With release R2014b and later you can directly access properties of graphics objects with dot notation:
ax = axes;
ax.XLim
With release R2014a and earlier that will not work and you need to use get.
ax = axes;
get(ax, 'XLim')
Depending on how extensively that code uses the new graphics functionality, modifying it to use only functionality present in the older graphics system version could be a lot of work (or it may not even be possible if it requires functionality newly added in the new graphics system.) The easier way to get this working, if it's possible, would probably be to upgrade to release R2014b or later.
  4 Comments
Cam Salzberger
Cam Salzberger on 22 May 2020
Edited: Cam Salzberger on 22 May 2020
You see where the error says it's trying to do "ax.XLim"? That's not usable in pre-R2014b, because in the original graphics, the graphics "handles" are just numbers. They refer to graphics objects, they don't encapsulate them. That kind of line would need to be changed to d = [get(ax, 'XLim'), get(ax, 'YLim'), get(ax, 'ZLim'), just for example.
I'd hesitate to call it a bug if it is designed to work for recent releases of MATLAB, and it does so. Peter Corke's page does mention that there was an older version of the toolbox released in 2011, so if you can get that one, it's more likely to work with your release. You should be able to get it through here, I think, but I don't know if it will have all the functionality you need.
Jean-Pierre Asdiguian
Jean-Pierre Asdiguian on 23 May 2020
Edited: Jean-Pierre Asdiguian on 24 May 2020
@Cam Salzberger Ah, that makes sense! I just changed it in the plot.m code, and it worked great!!! THANK YOU SO MUCH!!! I wish you'd put it as an answer. This is definitely worth Best answer :)
I changed this in line 470 in plot.m to the following, and now it's working on previous versions of MATLAB too! (R2013b in this case):
d = [get(ax,'Xlim'), get(ax,'YLim'), get(ax,'ZLim')];

Sign in to comment.

More Answers (0)

Products


Release

R2013b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!