How to pre-allocate an array for 6 DOF PUMA robot?

조회 수: 2 (최근 30일)
Prashant Chopade
Prashant Chopade 2013년 7월 5일
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
dpb
dpb 2013년 7월 11일
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.
Prashant Chopade
Prashant Chopade 2013년 7월 16일
@dpb - Yes that was a typo error in definition equation. I have corrected now. Thanks for your comments.

댓글을 달려면 로그인하십시오.

채택된 답변

Jan
Jan 2013년 7월 10일
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.
  댓글 수: 2
Prashant Chopade
Prashant Chopade 2013년 7월 16일
@Jan - Thanks for your inputs, I will try this one.
Prashant Chopade
Prashant Chopade 2013년 7월 17일
편집: Prashant Chopade 2013년 7월 17일
@Jan - Hey Thanks buddy for your input, I am able to successfully run above 5 "for loops" within around 3 to 4 mins. :)
But now I am facing one more problem of Out of Memory. getting an error as below -
??? Error using ==> horzcat
Out of memory. Type HELP MEMORY for your options.
I have a matlab installed with 32 bit option. My system is 64 bit with 3 gb Ram. So could you please suggest me what I can do here?

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Jan
Jan 2013년 7월 10일
The missing readability of the code discourages me to read it. But I can see two problems which reduces the speed at first glance:
  1. Avoid repeated calculations, e.g. cos(T2(j)+T3(k)) is calculated several times. Using a temporary variable instead is much better.
  2. Pre-allocate the outputs. There is no efficient way if you omit this.

카테고리

Help CenterFile Exchange에서 Install Products에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by