



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




Robot Simulation in Matlab 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 n x3 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:
Figure 1: Link 1, a cylinder This cylinder will be defined in parametric fashion based on radius (r1) and length (l1). The vertices matrix will look something like: vert_link1=[ r1cos(0), r1sin(0), 0 r1cos(30), r1sin(30), 0 etc The faces matrix will look like: Face_link1=[1,2,3,4,5,6,7,8,9,10,11, 1,2,14,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: 1 2 11 12 10 9 8 3- 13 14 19 18 17 16 15 20 (^21 ) 23 24 x z F F10 F11^ F12^ F F
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 Part 2: Manipulating 3D objects in Matlab: Once the objects are created, they can easily be manipulated by operating on the vertices with rigid body transformations (rotation + translastion). Each vertex (corresponding to each row in the vertex matrix) is operated on. A few lines of pseudo code demonstrating this process follow: For i=1 to # of rows of vertex_link vertex_link1(i,:) = ( R *vertex_link_o(i,:)’)’ + d end 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.
An example of object manipulation is shown in the attached code, draw_robot.m Part 3: Animating a robot move Animation is simply a sequence of rigid body motions performed in a continuous manner. This can be performed by embedding the transformation and drawing commands in a loop that slowly increments the amount of rotation/translation. A few side notes on animation;