How to generate 3D surface or robot workspace?
53 views (last 30 days)
Show older comments
I have a 4 DOF robot with variables t1,t2,d3 and t4. I used linspace to generate values for the variables, and also I calculated the positions, resulting 90x90x90 matrices (for X, Y and Z). Now how could I do a work-space with this data? Obviously plot3 or surf does not work. I searched the answers and the one with example is no longer valid. Can please help me with some examples or code?
l1=500;l2=600;l3=400;l4=191.03;
t1=linspace(-180,180,90)*pi/180;
t2=linspace(-90,90,90)*pi/180;
d3=linspace(-200,200,90);
t4=linspace(-180,180,90)*pi/180;
nt1=length(t1);
nt2=length(t2);
nd3=length(d3);
for i=1:nt1
for j=1:nt2
for k=1:nd3
xM(i,j,k)=round((-cos(t1(i)).*cos(t2(j))).*((d3(k) + l2 + l3 + l4)));
yM(i,j,k)= round((-cos(t2(j)).*sin(t1(i))).*(d3(k) + l2 + l3 + l4));
zM(i,j,k)=round((l1 - l4.*sin(t2(j)) - sin(t2(j)).*(d3(k) + l2 + l3)));
end
end
end
Clarifications:
- What is workspace of a robot? Forward kinematics uses the kinematic equations of a robot to compute the position of the end-effector from specified values for the joint parameters. The dimensions of the robot and its kinematics equations define the volume of space reachable by the robot, known as its workspace. Or, as Amid said: the space that the robot gripper can reach, all way around (visualize all the points that the robot could reach, giving us a 3D space).
- The workspace using these dimensions will be a sphere. Why? The robot is a spherical robot (with two rotary joints and one prismatic).
- The parameter t4 does not appear in the equations, it's just the orientation of the final element (end-effector), thus it does not influence the workspace.
- The values of the variable parameters (t1,t2,d3) are maximum. This does not happen in real life, due to mechanical restrictions or space consideration. Modifying these parameters with more realistic values will result in a sphere with cut off top and bottom. This is normal, and that's how it should look.
Thank you very much for the help!
3 Comments
Accepted Answer
hmi amid
on 8 May 2017
Edited: hmi amid
on 8 May 2017
Hi Cristina, I think I understand the question. You mean by workspace, the space the robot arm can reach? If yes, this is the correction you should start with. Actually, don't use 3 for loops. Never do that in Matlab... It will slow down your process. Use in this case, NDGRID. Here is the code
l1=500;l2=600;l3=400;l4=191.03;
t1=linspace(-180,180,90)*pi/180;
t2=linspace(-90,90,90)*pi/180;
d3=linspace(-200,200,90);
t4=linspace(-180,180,90)*pi/180;
[T1,T2,D3]=ndgrid(t1,t2,d3); % This will create matrices of 90x90x90 for each variable
xM = round((-cos(T1).*cos(T2)).*((D3 + l2 + l3 + l4)));
yM = round((-cos(T2).*sin(T1)).*(D3 + l2 + l3 + l4));
zM = round((l1 - l4.*sin(T2) - sin(T2).*(D3 + l2 + l3)));
plot3(xM(:),yM(:),zM(:),'.') % This is the plot type you should be using.
% With a '.' as an argument to show only locations and not lines
% Also, (:) converts any matrix into a list of its elements in one single column.
Anyway it is interesting, the output is a sphere of about 3000 diameter. If you want to incorporate t4 also just add it in NDGRID
l1=500;l2=600;l3=400;l4=191.03;
t1=linspace(-180,180,90)*pi/180;
t2=linspace(-90,90,90)*pi/180;
d3=linspace(-200,200,90);
t4=linspace(-180,180,90)*pi/180;
[T1,T2,D3,T4]=ndgrid(t1,t2,d3,t4); % Add t4 here
xM = round((-cos(T1).*cos(T2)).*((D3 + l2 + l3 + l4))); % and use it in x y z as T4
yM = round((-cos(T2).*sin(T1)).*(D3 + l2 + l3 + l4));
zM = round((l1 - l4.*sin(T2) - sin(T2).*(D3 + l2 + l3)));
plot3(xM(:),yM(:),zM(:),'.')
Amid.
4 Comments
Anoop Kumar Sinha
on 15 Dec 2020
Hi Amid,
Is this method of plotting workspace called Monte Carlo Method?
Regrads,
Anoop
Jacopo Podavini
on 8 May 2021
Hi Amid or whoever is reading this that used this ndgrid method, is there a way to obtain from those matrixes a vector with every position for each X,Y,Z coordinate?
Thank you very much
More Answers (3)
Omer Oztoprak
on 22 Dec 2020
Hi Cristina and everyone
do you know now how to plot workspace
0 Comments
Daniele Poli
on 6 Jan 2022
Ciao, purtroppo non mi torna il plot allegato, dovrei fare un workspace di un robot delta.
0 Comments
See Also
Categories
Find more on Coordinate Transformations in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!