Robot Simulation in Matlab V2
Robot Simulation in Matlab V2
This tutorial will discuss some of the basic steps in creating a virtual robot control and
simulation environment in Matlab. This tutorial consists of several parts:
>patch(‘Vertices’,vertices_link1,’Faces’,faces_link1,’faceColor’,[RGB values])
‘Vertices’: vertices_link1 is a matrix that contains all the vertices used to describe the
object. The size of vertices_link1 is nx3 where n is the number of vertices, 3 is the
number of coordinates for each vertex (x,y,z). Each row corresponds to a vertex and each
column to its x,y,z coordinate.
‘Faces’: face_link1 is a matrix that defines each face of the object in terms of the vertices
that lie on the face. Each row of this matrix corresponds to a face, the columns contain
the vertices that define the face.
‘FaceColor’: gives one means of defining the coloring of the object. It can be in terms of
the faces, vertices, etc., or a single overall color (as used here). The examples that follow
use a single color defined in terms of RGB values.
Now for an example: First we will create a cylinder to represent the base of our robot.
The cylinder will be represented with a certain number of faces defined by a certain
number of vertices. It helps to sketch your primitive and label the vertices and faces as in
figure 1:
18 17 16
19 15
20 F14 14
21
22 24 13
23
3-7
8 2
9 1
10
11 12 x
This cylinder will be defined in parametric fashion based on radius (r1) and length (l1).
The vertices matrix will look something like:
Face_link1=[1,2,3,4,5,6,7,8,9,10,11,12
1,2,14,13,13,13,13,13,13,13,13,13
etc
These are defined in matlab, and plotted using the patch command to yield the following
result:
A second link is created, this one looks like a bar with rounded ends, with parameters r2
(end radius), l2 (bar length) t2 (bar thickness) to yield the following result (plotted with
the cylinder):
One final note is made in defining these objects. Each object is defined relative to its
own frame and has an origin location. Subsequent rotation operations will act on this
frame and about this origin. Therefore, locate the origin and z axis of the body to align
with a joint that could be envisioned on the body.
An example of object drawing for a cylinder and rounded bar is shown in the attached
code, draw_robot.m
where R is 3x3 rotation matrix, d is the 3x1 translation vector, and the ‘ indicates
transpose. Note that the rotation operation provides a rigid body rotation to all vertices
about the origin of the object, and the translation provides a rigid body translation or
offset to all points. Also note that we have acted on the original vertices to create a new
or current vertex matrix. A rotation of 45 degrees is applied to the bar (link 2) and
plotted as shown in the following figure.
y
Assignment:
Create a virtual robot in Matlab based on the SCARA configuration (you may choose
another robot, with a min. of 4 dof). Your first task is to write a program to allow a user
to type values for theta 1,2,4 and d3, and then plot the robot.