Вы находитесь на странице: 1из 4

Lab Assignment 1

Directions: Complete the following steps using MATLAB and any provided functions that you write. You
should create a lab report which describes your answers and findings for each step.

The report must be turned in on Moodle as a zip file containing your report (in PDF or MS Word format),
any MATLAB m-files used to complete the assignment (including files for generating figures), and any
results (including, e.g., videos, plots, etc.).

In general, if you do not know how a built-in function in MATLAB works, type “help fname” at the
command prompt, where fname is the name of the function you want to look up. MATLAB will provide
you with documentation explaining how to use the function.

1. For the 3R robot shown on the next page, create a table of D-H parameters describing the forward
kinematics of the robot up to the end-effector or tool coordinate frame, shown as {𝑥4 , 𝑦4 , 𝑧4 }. The
frame {𝑥0 , 𝑦0 , 𝑧0 } is the stationary base frame. Do not forget to include the variable angles 𝜃𝑖∗ for
the three revolute joints. Your table of parameters should have four rows, representing the
transformations between coordinate systems 0→1, 1→2, 2→3, and 3→4.

2. On the course moodle, you will find a few MATLAB scripts to help you with the next parts.
Download the package of files labeled for LAB 1 and make sure that they are all visible to MATLAB.
A description of the packaged files is included as a text file with the package, labeled README.txt.
You will also need the functions previously provided for working with homogeneous transformation
matrices.

3. Write a function called DHTrans that takes in the four D-H parameters for a line of the table,
(𝑑, 𝜃, 𝑎, 𝛼), and returns the standard D-H transformation matrix,

𝑖−1
𝑇𝑖 = Trans𝑍 (𝑑)Rot 𝑍 (𝜃)Trans𝑋 (𝑎)Rot𝑋 (𝛼)

This function may be just one line long, but remember to include it in your report. Check that your
result is correct by verifying that it produces the following result:
>> DHTrans(1,pi/4,-2,3*pi/4)

ans =

0.7071 0.5000 0.5000 -1.4142


0.7071 -0.5000 -0.5000 -1.4142
0 0.7071 -0.7071 1.0000
0 0 0 1.0000

4. In order to draw the robot links in a simulation, you will need to know the following coordinate
transformations 0 𝑇1 , 0 𝑇2 , and 0 𝑇3 . To show the location of the tool coordinate system, you will
also need 0 𝑇4 . Write a function that returns all four of these matrices using only the input angles
for the robot:
function [T01,T02,T03,T04] = MyRobot(theta)
%T01,…,T04: Transformation matrices representing links 1-3 and the tool
%theta: 3 x 1 vector containing the joint angles in the natural ordering
Note that to do this, the function will need to know the constant parameters in the D-H table. You
can simply hard code these in to the function, but it is better to create a function that can “read in”
a DH table.

5. The joint angles are at (𝜋/4,𝜋/4,𝜋⁄4). You have located a point with coordinates (1,1,1) with
respect to coordinate frame 0. What are the coordinates of this point with respect to coordinate
frame 4?

6. The joint angles are at (𝜋/2,−𝜋/4,-𝜋⁄4). You have located a point with coordinates (1,1,1) with
respect to coordinate frame 4. What are the coordinates of this point with respect to coordinate
frame 0?

7. Use the read_wobj and draw_wobj to read the link1.obj file and draw it in MATLAB’s 3D figure
window. Afterwards, use the following commands to make the figure look significantly better.
%prepare3D.m
axis equal %makes axes have same scale
axis vis3d %prevents zooming when rotating axes
lighting gouraud %shades objects to look 3D
set(gca,‘Clipping’,‘off’) %makes sure object is always visible
xlabel(‘x’);
ylabel(‘y’);
zlabel(‘z’); %label axes
light %turn on a light for reflections
I recommend saving these commands as a script called prepare3D.m in your MATLAB folder within
your Documents folder. You can also use the commands xlim, ylim, and zlim to set the lengths of
the axes of the figure.

8. Write a function or script that can draw the complete robot with arbitrary joint variable values. To
do this, you will create a handle graphics object that represents a coordinate transformation, and
then set the correct coordinate transformation to be the “Parent” of each link. To get you started,
consider the following code sample:size_
Link1 = read_wobj(‘link1.obj’); %read in the mesh data for the graphics
hLink1 = draw_obj(Link1); %draw the object
hCopy = draw_obj(Link1); %draw a second copy of the object
T01 = TransY(4); %we will move the second copy 4 along Y
hT = hgtransform(‘Matrix’,T01); %create a graphics transform based on T01
set(hCopy, ‘Parent’, hT); %after this, the original data is
%displayed as though it was in the
%coordinate frame 1
After the robot has been drawn once (one draw_obj function call for each link), do not call
draw_obj again unless the figure window is closed. If you want to move the robot to a new
configuration, simply re-calculate the transformation matrices and use the ‘set’ function to change
the matrix of the graphics transformation objects:

set(hT, ‘Matrix’, <variable with new t-form here>);


In your report, provide a drawing of the robot at joint angles of your choice; do not use a
configuration close to the home configuration. Using the drawFrame function, overlay the
coordinate frames 0 through 4 with the simulation of the robot (try scale 5 to make them visible).

9. Using a “for” loop, simulate the robot rotating all of its joints simultaneously by the functions

𝜃1 (𝑡) = 2𝑡
𝜃2 (𝑡) = 3𝑡
𝜃3 (𝑡) = 5𝑡
The following skeleton may help you get started:

timestep = 1/60; %1/60 second simulated for each frame drawn

for i=0:N
t = i*timestep; %simulated time for this loop iteration
theta_1 = 2*t; %calculate functions of time
%<fill in others here>

%get the robot shape


[T01,T02,T03,T04] = MyRobot([theta_1, theta_2, theta_3]);

%<set the graphics transforms to have matrices T01, …, T04 as


%appropriate>

%these functions force MATLAB to re-draw and then pause briefly so that
%the ‘movie’ doesn’t run too fast
drawnow
pause(1/60)
end
When the code runs successfully, you will see the robot moving in the figure window. Considering
that all the joint variables run through at least one full rotation of 2𝜋 radians, does the robot
appear to hit itself at any point during the simulation if it runs for 10 seconds of simulated time?

Вам также может понравиться