0% found this document useful (0 votes)
47 views

Robotics Lab Lecture #3: Purpose of This Lecture

This lecture discusses drawing cylinders in MATLAB to represent robotic joints and links. It provides code for a function that draws a cylinder and allows controlling its appearance and position. The document then presents two programs that use this function to draw single and multiple cylinders at different positions and orientations. It describes how to draw a robotic arm by projecting individual cylinder components into different frames and reference frames based on rotational matrices. Finally, an example program is given to draw the second link of a robotic arm by manipulating the cylinder representation through homogeneous transformations.

Uploaded by

Sonoso
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views

Robotics Lab Lecture #3: Purpose of This Lecture

This lecture discusses drawing cylinders in MATLAB to represent robotic joints and links. It provides code for a function that draws a cylinder and allows controlling its appearance and position. The document then presents two programs that use this function to draw single and multiple cylinders at different positions and orientations. It describes how to draw a robotic arm by projecting individual cylinder components into different frames and reference frames based on rotational matrices. Finally, an example program is given to draw the second link of a robotic arm by manipulating the cylinder representation through homogeneous transformations.

Uploaded by

Sonoso
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Robotics Lab

Lecture #3

Purpose of This Lecture:


- Learn how to draw a cylinder and control its appearance, change its position using
transitional and rotational movement.

- Learn how to use this code in order to make a good software that will eventually be used to
animate a robot-like form.

Programs Practice:

Part 1: Programs
The following function is a simple function used to draw and control the cylinder appearance
and its position.

function drawingCy( R,rad,face,scale )


[x,y,z] = cylinder(rad,face);
x=x*scale(1);
y=y*scale(2);
z=z*scale(3);
[m,n]=size(x);
x1 = []; y1 = []; z1 = [];

for i = 1:m
cylin =R*[x(i,:); y(i,:); z(i,:); ones(1,face+1)];
x1 = [x1; cylin(1,:)];
y1 = [y1; cylin(2,:)];
z1 = [z1; cylin(3,:)];

end
surf(x1,y1,z1,'FaceColor','r','Facealpha',0.6, ...
'EdgeColor','black','AmbientStrength',0.4);
end
……………………………
Notes :
1- The following experiments will be built upon this function.
2- Most of the code’s logic will be explained later.

1
Program number 1:
function exp3()
rad=[0.6 0.2 0.4 0.3];
face=10;
scale=[0.4 0.4 0.4];
hold on;
R=eye(4);
drawingCy( R,rad,face,scale);
R=[1 0 0 0;0 cosd(90) -sind(90) 0;
0 sind(90) cosd(90) 0;0 0 0 1];
drawingCy( R,rad,face,scale);
R=[1 0 0 0.5;0 1 0 0.5;0 0 1 0.5;0 0 0 1];
drawingCy( R,rad,face,scale);
axis([-0.5 1 -0.5 1 -0.5 1]),grid;
xlabel('X');
ylabel('Y');
zlabel('Z');
end

Testing program 1:
clear; clc;
exp3(); % Or exp4(); when testing exp4()…

Program number 2:
function exp4()
R=[1 0 0 0;
0 cosd(90) -sind(90) 0.2;
0 sind(90) cosd(90) 0;
0 0 0 1];
%R=[1 0 0 0;0 1 0 0;0 0 1 0; 0 0 0 1];
rad=[0 0.2 0.3 0.3 0.3 0.3 0.3 0.2 0];
face=30;
scale=[0.4 0.4 0.4];
hold on;
drawingCy( R,rad,face,scale);
axis([-0.8 0.8 -0.8 0.8 0 1.2]),grid;
xlabel('X');
ylabel('Y');
zlabel('Z');
end

2
drawing the robot in MATLAB
This phase consists of 3 stages:

1) draw the body of each of the joints independently :

The principles of drawing any 3D object easy to implement in MATLAB. The function used
to draw the robotic arm is (cylinder).

[X,Y,Z] = cylinder(r,n)

Cylinder generates x-, y-, and z-coordinates of a unit cylinder. You can draw the cylindrical
object using surf or mesh, or draw it immediately by not providing output arguments.

[X,Y,Z] = cylinder(r,n) returns the x-, y-, and z-coordinates of a cylinder based on the profile
curve defined by vector r. The cylinder has n equally spaced points around its circumference.

2) project them based on their frame :

You can do that by scaling the input ([x,y,z]T ) that’s used to draw the arm, then multiplying
the resulting input with a rotational matrix that’s created to rotate the 3-D object into the right
orientation based on their frame and then move the 3-D object to the right position.

An example will be shown on how this operation is done in MATLAB.

3) project them based on reference frame (frame 0):

After the second stage, you can manipulate the 3-D object in the same way, by multiplying
the resulting input [x y z]T with after adjusting the input by making a 4th row in the
bottom of the [x y z]T matrix and fill it with ones .

The result can be easily printed in a 3D plotting tool in MATLAB using surf command.

The following example shows how the second joint is printed as an output of this procedure:

function exp6()
d1=0.6;
d3=1;%longest destance!
A10=DHhomomatrix(90,d1,90,0);
A21=DHhomomatrix(90,0,90,0);
H10=A10;
H20=A10*A21;
R=[1 0 0 0;0 cosd(90) -sind(90) 0.2;
0 sind(90) cosd(90) 0;0 0 0 1];
[x1,y1,z1]=cylinder([0 0.2 0.3 0.3 0.3 0.3 0.3 0.2 0],30);

3
x1=x1*0.4; y1=y1*0.4; z1=z1*0.4;
x2 = []; y2 = []; z2 = [];
for i = 1:9
cylin =H20*R*[x1(i,:); y1(i,:); z1(i,:); ones(1,31)];
x2 = [x2; cylin(1,:)];
y2 = [y2; cylin(2,:)];
z2 = [z2; cylin(3,:)];
end
surf(x2,y2,z2,'FaceColor','c',...
'EdgeColor','r','AmbientStrength',0.4),
grid, axis([-0.8 0.8 -0.8 0.8 0 1.2]),
daspect([1 1 1]), grid;
hold on;
end
function H=DHhomomatrix(thetazd,jointoff,thetaxd,linklen)
cz=cos(thetazd);cx=cosd(thetaxd);
sz=sin(thetazd);sx=sind(thetaxd);
d=jointoff;a=linklen;
H =[cz,-cx*sz,sx*sz,a*cz;sz,cx*cz,-cz*sx,a*sz;
0,sx,cx,d;0,0,0,1];
end

The result of this code is shown in this figure:

Figure: Drawing the robot in MATLAB

You might also like