How to pre-allocate an array for 6 DOF PUMA robot?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I am trying to prepare a neural network for 6 DOF robot. I have written a following program, but since I am not able to pre-allocate the array size, this program is taking too many days to run. Even after that it is not giving me the results & gets hanged in between.
Below is the program I have written - *****************************************************************************
% Constants as defined by for PUMA robot
a2 = 431.8;
a3 = -20.32;
d2 = 149.09;
d4 = 433.07;
d6 = 56.25;
% Joint Range of an angle Theta for PUMA Robot links.
T1=-160*pi/180:10*pi/180:160*pi/180;%Convert to radians.
T2=-225*pi/180:10*pi/180:45*pi/180;%Convert to radians.
T3=-45*pi/180:10*pi/180:225*pi/180;%Convert to radians.
T4=-110*pi/180:10*pi/180:70*pi/180;%Convert to radians.
T5=-100*pi/180:10*pi/180:100*pi/180;%Convert to radians.
% Index used
i=1;
j=1;
k=1;
l=1;
m=1;
n=1;
% Calculating the length of Joint range.
L1=(length(T1));
L2=(length(T2));
L3=(length(T3));
L4=(length(T4));
L5=(length(T5));
% Loop to calculate the X,Y&Z coordinates.
for i=1:1:L1
for j=1:1:L2
for k=1:1:L3
for l=1:1:L4
for m=1:1:L5
% Equations used to calculate Coordinates for PUMA robot with T Matrix
% X = COS1[d6(COS23*COS4*SIN5+SIN23*COS5)+
% (SIN23*d4)+(a3*COS23)+(a2*COS2)]-
% [SIN1(d6*SIN4*SIN5+d2)] (based on this formula.)
X= cos(T1(i))*(d6*((cos(T2(j)+T3(k))*cos(T4(l))*sin(T5(m)))+
(sin(T2(j)+T3(k))*cos(T5(m))))+(sin(T2(j)+T3(k))*d4)+
(a3*cos(T2(j)+T3(k)))+(a2*cos(T2(j))))-
sin(T1(i))*(d6*sin(T4(l))*sin(T5(m))+d2);
% Y = SIN1[d6(COS23*COS4*SIN5+SIN23*COS5)+
% (SIN23*d4)+(a3*COS23)+(a2*COS2)]+
% [COS1(d6*SIN4*SIN5+d2)] (based on this formula.)
Y= sin(T1(i))*(d6*((cos(T2(j)+T3(k))*cos(T4(l))*sin(T5(m)))+
(sin(T2(j)+T3(k))*cos(T5(m))))+(sin(T2(j)+T3(k))*d4)+
(a3*cos(T2(j)+T3(k)))+(a2*cos(T2(j))))+
cos(T1(i))*(d6*sin(T4(l))*sin(T5(m))+d2);
% Z = [d6(COS23*COS5-SIN23*COS4*SIN5)]+
(COS23*d4)-(a3*SIN23)-(a2*SIN2) (based on this formula.)
Z= d6*((cos(T2(j)+T3(k))*cos(T5(m)))-
(sin(T2(j)+T3(k))*cos(T4(l))*sin(T5.(m))))+
(cos(T2(j)+T3(k))*d4)-(a3*sin(T2(j)+T3(k)))-(a2*sin(T2(j)));
% Storing values of X, Y & Z coordinates. Also respective angle of the same.
[aa(n)]=[X];
[bb(n)]=[Y];
[cc(n)]=[Z];
tt1(n)=T1(i);
tt2(n)=T2(j);
tt3(n)=T3(k);
tt4(n)=T4(l);
tt5(n)=T5(m);
n=n+1;
end
end
end
end
end
****************************************************************************
I have Matlab 7.0 version.
13 Kommentare
dpb
am 11 Jul. 2013
Excepting for leaving in an inordinate number of blank lines...
I thought I made the following comment before but I don't see it...
% Equations used to calculate Coordinates for PUMA robot with T Matrix
% X = COS1[d6(COS23*COS4*SIN5+SIN23*COS5)+
% (SIN23*d4)+(a3*COS23)+(a2*COS2)]-
% [SIN1(d4*SIN4*SIN5+d2)] (based on this formula.)
X= cos(T1(i))*(d6*((cos(T2(j)+T3(k))*cos(T4(l))*sin(T5(m)))+
(sin(T2(j)+T3(k))*cos(T5(m))))+(sin(T2(j)+T3(k))*d4)+
(a3*cos(T2(j)+T3(k)))+(a2*cos(T2(j))))-
sin(T1(i))*(d6*sin(T4(l))*sin(T5(m))+d2);
In comparing the definition equation to your code, the term SIN1[d4...
on the third line seems to be sin(T1*d6... in the code. But if d6 is really d4 then it would seem the COS1[d6 in the first line should be implemented as cos(T1*d4... so I'm left to conclude either the comment is wrong or the code doesn't match the comment.
Looks to me like you first need to really double-check the equations.
Akzeptierte Antwort
Jan
am 10 Jul. 2013
A demonstration of how to avoid repeated calculations:
for i=1:1:L1
c1 = cos(T1(i));
c5 = sin(T1(i));
for j=1:1:L2
c7 = a2*cos(T2(j));
for k=1:1:L3
c2 = cos(T2(j)+T3(k));
c4 = sin(T2(j)+T3(k));
for l=1:1:L4
c3 = cos(T4(l)) * c2;
c6 = c5*(d6*sin(T4(l));
for m=1:1:L5
X = c1 * (d6 * (c3 * sin(T5(m)) + (c4 * cos(T5(m)))) + ...
(c4 * d4) + (a3 * c2) + c7) - c6 * sin(T5(m)) + d2);
etc.
Weitere Antworten (1)
Jan
am 10 Jul. 2013
The missing readability of the code discourages me to read it. But I can see two problems which reduces the speed at first glance:
- Avoid repeated calculations, e.g. cos(T2(j)+T3(k)) is calculated several times. Using a temporary variable instead is much better.
- Pre-allocate the outputs. There is no efficient way if you omit this.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Install Products finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!