Index Exceeds Array Bounds

4 views (last 30 days)
Cadence Motley
Cadence Motley on 3 Apr 2019
Edited: Cadence Motley on 3 Apr 2019
Hi so, Im having an issue with "Error in Jacobian_Calculator_Func (line 14)) Jv(1:3,t)=T(1:3,(4*t-1));". I cant seem to be able to spot what the problem is. I was hoping that one of you could take a look really quick and tell me what Im doing wrong in reguard to my indexing.
Ive got a sneaky suspision that maybe its the part where the index value is 4*t-1. However, this should work fine since my T matrix is 4x12 and I need the 3rd 7th and 11th collums between rows 1:3
Here is the code: There are two function files and a script. The commented out section is the part Im trying to outsource in the second function.
%Cadence Motley
%Script for DH Table Multiplication
%ME422
%4/2/19
format compact; clc; clear all;
%% Compiling DH Tables/ Forward Kinematics
%Indication of sys need: 1-value 0-sym should be a matrix that is nx1
A=1; %for a
D=0; %for d
C=1; %for alpha
O=0; %for theta
%For Value to go in place of a,d,theta or alpha
Av=0; %for a
Dv=0; %for d
Cv=90; %for alpha
Ov=0; %for theta
T1=DH_Table_Calculator(A,D,C,O,Av,Dv,Cv,Ov);
%Indication of sys need: 1-value 0-sym should be a matrix that is nx1
A=0; %for a
D=1; %for d
C=1; %for alpha
O=0; %for theta
%For Value to go in place of a,d,theta or alpha
Av=0; %for a
Dv=0; %for d
Cv=0; %for alpha
Ov=0; %for theta
T2= DH_Table_Calculator(A,D,C,O,Av,Dv,Cv,Ov);
global o
p=sym('p'); %p is o2
T2=subs(T2,o,p);
%Indication of sys need: 1-value 0-sym should be a matrix that is nx1
A=0; %for a
D=1; %for d
C=1; %for alpha
O=0; %for theta
%For Value to go in place of a,d,theta or alpha
Av=0; %for a
Dv=0; %for d
Cv=0; %for alpha
Ov=0; %for theta
T3= DH_Table_Calculator(A,D,C,O,Av,Dv,Cv,Ov);
global a
y=sym('y'); %a3 is y
i=sym('i'); %o3 is i
T3=subs(T3,o,i);
T3=subs(T3,a,y);
T02=T1*T2;
T03=T1*T2*T3;
T=[T1,T02,T03];
%% Jacobian Calculations
Joints=[1,1,1]; %1 for Revolute, 0 for Prismatic
%Jv1=cross(T1(1:3,3),T03(1:3,4)-T1(1:3,4)); %takeing the cross product
%Jw1=T1(1:3,3);
%J1=[Jv1;Jw1];
%Jv2=cross(T03(1:3,3),T03(1:3,4)-T02(1:3,4)); %takeing the cross product
%Jw2=T02(1:3,3);
%J2=[Jv2;Jw2];
%Jv3=cross(T03(1:3,3),T03(1:3,4)-T03(1:3,4)); %takeing the cross product
%Jw3=T03(1:3,3);
%J3=[Jv3;Jw3];
%J=[J1 J2 J3];
%J
J= Jacobian_Calculator_Func(T,Joints);
J
^Script
v DH_Table_Calculator
function [T] = DH_Table_Calculator(A,D,C,O,Av,Dv,Cv,Ov)
%Cadence Motley
%Function for DH Table Calculator
%ME422
%4/2/19
%% Variable Appropriation for Calculation
% a determination
if A == 1
a= Av;
else
global a
a= sym('a');
end
% d determination
if D == 1
d= Dv;
else
global d
d= sym('d');
end
% o determination - theta
if O == 1
o= Ov;
else
global o
o= sym('o');
end
% c determination - alpha
if C == 1
c= Cv;
else
global c
c= sym('c');
end
%% Homo Trans Calculation
if O==1 && C==1
T=[cosd(o),-sind(o)*cosd(c),sind(o)*sind(c),a*cosd(o);sind(o),cosd(o)*cosd(c),-cosd(o)*sind(c),a*sind(o);0,sind(c),cosd(c),d;0,0,0,1];
elseif O==1 && C==0
T=[cosd(o),-sind(o)*cos(c),sind(o)*sin(c),a*cosd(o);sind(o),cosd(o)*cos(c),-cosd(o)*sin(c),a*sind(o);0,sin(c),cos(c),d;0,0,0,1];
elseif O==0 && C==1
T=[cos(o),-sin(o)*cosd(c),sin(o)*sind(c),a*cos(o);sin(o),cos(o)*cosd(c),-cos(o)*sind(c),a*sin(o);0,sind(c),cosd(c),d;0,0,0,1];
else %O=0 and C=0
T=[cos(o),-sin(o)*cos(c),sin(o)*sin(c),a*cos(o);sin(o),cos(o)*cos(c),-cos(o)*sin(c),a*sin(o);0,sin(c),cos(c),d;0,0,0,1];
end
simplify(T)
end
v Jacobian_Calculator
function [J] = Jacobian_Calculator_Func(Joints,T)
%Preallocating
Jv=zeros(3,length(Joints));
Jw=zeros(3,length(Joints));
J=zeros(2,length(Joints));
for t=1:length(Joints)
if Joints(t) == 1 %Revolute Joint Type
Jv(1:3,t)=cross(T(1:3,(4*t)),T(1:3,(4*length(Joints)))-T(1:3,(4*t))); %takeing the cross product
Jw(1:3,t)=T(1:3,(4*t-1));
J(1:3,t)=[Jv(t);Jw(t)];
elseif Joints(t) == 0 %Prismatic Joint Type
Jv(1:3,t)=T(1:3,(4*t-1));
Jw(1:3,t)=zeros(3,1);
J(1:3,t)=[Jv(t);Jw(t)];
else
disp('Error, incorect Input')
end
end
end
Im getting an error on the Jv equation under the elseif.
The error reads:
Index in position 1 exceeds array bounds (must not exceed 1).
Error in Jacobian_Calculator_Func (line 14)
Jv(1:3,t)=T(1:3,(4*t-1));
Error in Jacobian_Calculator (line 84)
J= Jacobian_Calculator_Func(T,Joints);
Thanks for the help

Accepted Answer

Stephen23
Stephen23 on 3 Apr 2019
Edited: Stephen23 on 3 Apr 2019
You swapped around the function inputs. The function is defined like this:
Jacobian_Calculator_Func(Joints,T)
but you call it like this:
Jacobian_Calculator_Func(T,Joints);
Joints only has one row, which matches the error that you showed.
  1 Comment
Cadence Motley
Cadence Motley on 3 Apr 2019
Edited: Cadence Motley on 3 Apr 2019
Awesome, thanks Im having one more error now. When I try to run the calculation Matlab is now trying to convert my sym elements into double arrays. How can I tell it not to do this and maintain the global sym variables?
"The following error occurred converting from sym to double:
Unable to convert expression into double array.
Error in Jacobian_Calculator_Func (line 18)
Jv(1:3,t)=cross(T(1:3,(4*t)),T(1:3,(4*length(Joints)))-T(1:3,(4*t))); %takeing the cross product"
I added this under the Preallocating section of the function in hopes that it would force the function to recognize my sym variable and not try to convert them but it didnt work this time. Any other recomendations?
global a
global o
global y
global i
global p
global d
global c

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!