Robotics CITS3241


Exercise Sheet 2: Homogeneous Transforms

Aim of the lab: To become familiar with Homogeneous Transforms and generate some M files that will be useful for future work.

  1. Write MATLAB M files which define the following functions for calculating 4x4 Homogeneous transformation matrices [T].
    function [T] = rotx(angle)      % Homogeneous transform for rotation about x axis
    function [T] = roty(angle)      % Rotation about y
    function [T] = rotz(angle)      % Rotation about z
    function [T] = trans(x, y, z)   % Translation by vector x,y,z
    

    Each function is to return a 4x4 Homogeneous transformation matrix [T]. When writing your functions you should exploit MATLAB's nice syntax for specifying matrices. See section 4.6 in your copy of "Elements of MATLAB".

    Reminder:

    rotx(theta) = 
    
    | 1     0           0        0 |
    | 0  cos(theta) -sin(theta)  0 |
    | 0  sin(theta)  cos(theta)  0 |
    | 0     0           0        1 |
    

    Having defined these functions you should be able to write expressions of the form:

    T = rotx(pi/4) * trans(.2, 3, 0) * rotz(.2) ...  etc etc
    

  2. Write an M file that plots (in 3D) a coordinate frame specified by a homogeneous transform T
    function plotframe(T)
    %    T     - 4x4 homogeneous transform
    

    This function should draw lines of length 1 running out along the x, y, and z axes of the frame specified by T. It is suggested that you use the MATLAB function 'line' rather than 'plot3' to draw the axes as 'line' always overlays graphics over the current plot without clearing it (do a 'help line' to find out more). You should also use the function 'text' to label the x, y, and z axes.

    Once you have this function running I suggest you enhance it so that it can take an optional extra two parameters.

    function plotframe(T, len, label)
    %    T     - 4x4 homogeneous transform
    %    len   - length of axis arms to plot (defaults to 1)
    %    label - text string to append to x,y,z labels on axes
    %
    %   len and label are optional and default to 1 and '' respectively
    
    In MATLAB you can determine the number of arguments passed to a function by the function nargin. For example to set the default value of len to one if its value is not supplied you would use the following
      if nargin < 2
         len = 1;
      end
    

    With these enhancements you will be able to plot coordinate frames at any size you desire and you will be able to label the axes 'x1', 'y2' etc.

  3. Write a MATLAB script to test your functions. Your function should first set the axis bounds (in 3D) to ensure you have a 'workspace' in which to draw your coordinate frames.
    axis equal;                            % make x y and z tick sizes equal
    axis([XMIN XMAX YMIN YMAX ZMIN ZMAX]); % set ranges in x y and z
    hold on;                               % freeze the current axis settings
    

    Note: The call to 'axis equal' should be done before setting the axis ranges. You may also want to use the 'box on' and 'grid on' commands to help with the visualisation of your frames. If you type the command 'rotate3d on' you can also interactively rotate the image by clicking on the image and moving the mouse.

    Generate and draw a base frame (- a base Homogeneous Transform given by an identity matrix - use the MATLAB function 'eye'), then apply various transforms to the base frame and draw them with your plotframe function to verify that you get what you expect. Try some transformations that are extended sequences of rotx, roty, rotz and trans transformations.

Portfolio Note

Save listings of rotx, roty, rotz, trans and plotframe. They will be required for your portfolio.


Copyright © 2002-2007
School of Computer Science & Software Engineering,
The University of Western Australia.