3D prismatic links

Build 3D prismatic links
0 solutions submitted (max: Unlimited)

Take in a set of link vectors and create hexagonal prism (6-corner cylinder in Matlab) to represent that link as a surface. If the link is prismatic, represent it as two prisms, with a smaller "piston" sliding inside a larger "base".
Function
function link_set = threeD_build_links_prismatic(link_vectors,link_extensions,prismatic)
% Take a set of link vectors and create a cylinder pointing in the
% direction of that link. If the link is prismatic, represent the link
% using two cylinders:
% The base of the link is a cylinder that is 3/4 the length of the
% zero-extension link length.
% The moving part of the link is a cylinder 1/2 the diameter of the
% base-cylinder for the link, 1/2 as long as the zero-extension link
% length, and offset along the link vector by 1/2 the zero-extension
% length, plus the link extension
%
% Input:
%
% link_vectors: A 1xn cell array in which each entry is a 3x1 link vector
%
% Output:
%
% link_set: A cell array the same size as link_vectors in which each
% entry is itself a cell array whose entries are the X,Y, and Z point
% matrices for a hexagonal prism shell around the link vector.
% If the link is prismatic, these the X, Y, and Z matrices should
% be built by first constructing them for the individual link
% pieces, and then combining them into a single matrix for each
% component, using a column of NaN values to separate them.
%%%%%%%%%%%%%%
% Use the 'cell' 'and 'size' commands to create an empty cell array the
% same size as link_vectors, named 'link_set'
%%%%%%%%%%%
% Create a hexagonal prism with unit radius, oriented along the x axis
% (use the cylinder command with radius 1 and 6 points around the
% circumference). Setting the outputs as [Z,Y,X] makes the cylinder axis
% parallel with the x direction.

%%%%%%%%%%%%%%
% Loop over vectors in link_set, scaling and stretching the basic link
% shape to fit each link. Prismatic links can be drawn as two cylinders
% with different radius.
%   This can be achieved by:
%
%   1. Using the function 'norm' to get the length of the link vector
%   for that link, saving this value into a variable named 'link_length'
%
%   2. Checking the 'prismatic' value for this link. If it is 0 (a rigid
%   link), then
%
%       A. Scale the cylinder along its axis by multiplying its X
%           points by link_length
%
%       B. Scale the radius of the cylinder by multiplying its Y and Z
%          points by link_length/20
%       
%       C. Save the X,Y, and Z values as a cell array named 'link'
%       
%    If it is 1 (an extendable link), then
%
%       A. Scale the cylinder along its axis by multiplying its X
%           points by 3/4 * link_length
%
%       B. Scale the radius of the cylinder by multiplying its Y and Z
%          points by link_length/20
%
%       C. Generate a second copy of the cylinder, and scale it along
%          its axis by multiplying its X points by 1/2 * link_length
%
%       D. Scale the radius of the second cylinder by multiplying its Y
%          and Z points by link_length/40
%
%       E. Add link_length/2 + the extension of the link to the X value of the
%          cylinder to place this moving portion of the link
%
%       F. Combine the two sets of X points into a single matrix with a
%          column of NaN values between them. Do the same for the Y and
%          Z sets
%
%       G. Save the X,Y, and Z values as a cell array named 'link'
%
%   4. Using the function 'orthonormal_basis_from_vector' (provided
%   with the course materials) to generate a rotation matrix 'B' whose
%   first column is aligned with the link vector
%
%   5. Using rotate_surface and the B matrix on the 'link' cell array
%   to align the cylinder with the link vector, and then save the
%   result as a cell array inside the corresponding cell of 'link_set'


% Loop over each link vector

    % Get the length of the vector using 'norm'
    % Create a rotation matrix whose first column is aligned with the
    % link vector using 'orthonormal_basis_from_vector'

    % If the link is prismatic
        % Make a set of X_base, Y_base, and Z_base matrices for the
        % first part of the link that scale the generic X, Y, and Z
        % matrices by 3/4 the link length in X and 1/20 the link length
        % in Y and Z
        % Make a set of X_piston, Y_piston, and Z_piston matrices for the
        % second part of the link that scale the generic X, Y, and Z
        % matrices by 1/2 the link length in X and 1/40 the link length
        % in Y and Z


        % Add half the link length plus the link's extension to the
        % X_piston value to position it
        % Create a "spacer" that is a column of NaN values with same
        % number of rows as the cylinder coordinate matrices
        % Make combined X_link, Y_link, and Z_link matrices whose
        % columns are the base matrices, the spacer, and the piston
        % matrices

    % Else (for non-prismatic links)

        % Make X_link, Y_link, and Z_link matrices by scaling X by the
        % link length, and Y and Z by 1/20 the link length


    end

    % Place the X_link, Y_link, and Z_link matrices into a cell array
    % named 'link'

    % Rotate the prism points by the orthogonal basis (to line up what
    % we were calling the x direction with the actual link vector)
end

end
1
2
3
4
5
6
7
8
9
10
Code to call your function
% This code builds links around three vectors
link_vectors = {[1;0;0],[0;2;0],[0;0;3]};
link_extensions = [0;.25;-.25];
prismatic = [0;1;1]
link_set = threeD_build_links_prismatic(link_vectors,link_extensions,prismatic);
link_set{2}{:}
1
2
3
4
5


Generate and place 3D prismatic arm links
0 solutions submitted (max: Unlimited)

Use the build and place link functions you created above to find the start and endpoints of the links in a 3D arm.
In addition to standard Matlab functions, your code may assume that you have access to the functions you created in previous assignments (some of these you will call directly in this assignment, some will only be called by other functions that you call). Remember that for these functions, the grading script will use the instructor's copy of the functions:
 vector_set_rotate
 vector_set_cumulative_sum
 threeD_rotation_set
 Rx
 Ry
 Rz
 rotation_set_cumulative_product
 threeD_build_links
 threeD_place_links
 orthonormal_basis_from_vector
 rotate_surface
 surface_set_rotate
Function
function [link_set,…
R_joints,…
R_links,…
link_set_local,…
link_vectors_in_world,…
links_in_world,…
link_end_set,…
link_end_set_with_base] = threeD_robot_arm_links_prismatic(link_vectors,joint_angles,joint_axes,link_extensions, prismatic)
% Take a set of link vectors and joint angles, and return a cell array of
% cell arrays, where the outer set of cells corresponds to the links, and
% the inner set contains the X, Y, and Z data for surfaces illustrating
% those links
%
% Inputs:
%
% link_vectors: a 1xn cell array, each element of which is a 3x1 vector
% describing the vector from the base of the corresponding link to
% its end
% joint_angles: a nx1 vector, each element of which is the joint angle
% preceeding the corresponding link
%
% Outputs:
%
% links: a 1xn cell array, each element of which is 2x2 matrix, whose
% columns are the endpoints of the corresponding link
%
% Additional outputs (These are intermediate variables. Having the option
% to return them as outputs lets our automatic code checker tell you
% where problems are in your code):
%
% R_joints: The rotation matrices associated with the joints
% R_links: The rotation matrices for the link orientations
% link_set_local: The link vectors augmented with a zero vector that
% represents the start of the link
% link_vectors_in_world: The link vectors in their current orientations
% links_in_world: The link start and end points in their current
% orientations
% link_end_set: The endpoints of the links after taking the cumulative
% sum of link vectors
%%%%%%%%
% First, use 'threeD_rotation_set' to generate a cell array named
% 'R_joints' that contains a set of rotation matrices corresponding to
% the joint angles and axes

%%%%%%%%
% Second, use 'rotation_set_cumulative_product' to generate a cell
% array named 'R_links' that contains the orientations of the link
% frames by taking the cumulative products of the joint rotation
% matrices



%%%%%%%%
% Third, use 'threeD_build_links_prismatic' to generate a cell array named
% 'link_set_local' that contains the surfaces for the links (cell
% arrays of the X, Y, and Z data for the surfaces)


%%%%%%%%
% Fourth, use 'vector_set_extend' to generate a cell array named
% 'link_vectors_extended' that contains the link vectors extended by
% the values in link_extensions

%%%%%%%%
% Fifth, use 'vector_set_rotate' to generate a cell array named
% 'link_vectors_in_world' that contains the (extended) link vectors
% rotated by the rotation matrices for the links

%%%%%%%%
% Sixth, use 'surface_set_rotate' to generate a cell array named
% 'links_in_world' that contains the link surface matrices rotated by
% the rotation matrices for the links (the extension of these links
% should already have been handled by threeD_build_links_prismatic)

%%%%%%%%
% Seventh, use 'vector_set_cumulative_sum' to generate a cell array
% named 'link_end_set' that contains the endpoints of each link



%%%%%%%%
% Eighth, add a cell containing a  zero vector (for the origin point at
% the base of the first link) to the beginning oflink_end_set, saving
% the result in a cell array named 'link_end_set_with_base'


%%%%%%%%
% Ninth, use 'threeD_place_links' to generate a cell array named
% 'link_set' by adding the base location of each link to the surface
% matrices of that link

end
1
2
Code to call your function
More Info
Reset
link_vectors = {[1;0;0],[0;1;0],[0;0;1]};
joint_angles = [pi/4; -pi/2;pi/4];
joint_axes = {'x','y','z'};
link_extensions = [0; 0; .5];
prismatic = [0; 1; 1];
link_set = threeD_robot_arm_links_prismatic(link_vectors,joint_angles,joint_axes,link_extensions,prismatic);
link_set{2}{:}
1
2
3
4
5
6


Product: Draw 3D Arm with prismatic links
0 solutions submitted (max: Unlimited)

Make a plot of a 3D a 3-link arm, with each link drawn as a hexagonal prism. The arm links should be 1, 1, and 0.5 units long. The first two links should be along the x axis of the local frame, and third link should be along the local z axis. The joint angles between the link frames should be 25π, −14π, and 14π, and should be respectively around the z, y, and x axes. Prismatic links should be illustrated as a pair of hexgonal prisms, with a smaller "piston" sliding inside a larger "base". The second and third links should be prismatic, with extensions of 0.2 and -0.2 units.
In addition to standard Matlab functions, your code may assume that you have access to the functions you created in previous assignments (some of these you will call directly in this assignment, some will only be called by other functions that you call). Remember that for these functions, the grading script will use the instructor's copy of the functions:
 vector_set_rotate
 vector_set_cumulative_sum
 rotation_set_cumulative_product
 create_axes
 threeD_rotation_set
 Rx
 Ry
 Rz
 threeD_robot_arm_endpoints
 threeD_robot_arm_links_prismatic
 threeD_build_links_prismatic
 threeD_place_links
 threeD_draw_links
 arm_Jacobian
 threeD_robot_arm_links
 orthonormal_basis_from_vector
 rotate_surface
 surface_set_rotate
 vector_set_difference
 vector_set_extend
If your code is correct, the output should resemble the figure below. Note that your parameters(joint_angles, link_vector or link_color) may differ from those in the example.

Function
function [link_vectors,…
joint_angles,…
joint_axes,…
link_extensions,…
prismatic,…
link_colors,…
link_set,…
ax,…
l,…
l3] = ME317_Assignment_draw_3D_arm_individual_links_prismatic
% Draw the arm as a set of hexagonal prisms, with a pair of prisms
% representing an extendable link
%%%%%%%%%%
% Specify link vectors as a 1x3 cell array of 3x1 vectors, named
% 'link_vectors'
%%%%%%%%%%
% Specify joint angles as a 3x1 vector, named 'joint_angles'
%%%%%%%%%%
% Specify joint axes as a 3x1 cell array, named 'joint_axes'
%%%%%%%%%%
% Specify colors of links as a 1x3 cell array named 'link_colors'. Each
% entry can be either a standard matlab color string (e.g., 'k' or 'r')
% or a 1x3 vector of the RGB values for the color (range from 0 to 1)

%%%%%%%%%%
% Specify link extensions as a 3x1 vector, named 'link_extensions'
%%%%%%%%%%
% Specify which links are prismatic as a 3x1 vector named 'prismatic',
% with values of 0 for a rigid link or 1 for a link that can extend
%%%%%%%%%
% Generate a cell array named 'link_set' containing start-and-end
% points for the links, named link_set
%%%%%%%%%%
% Use arm_Jacobian to get link_ends and joint_axis_vectors_R (we will
% use these to draw the axes onto the plot, so that it's easier to see
% how each joint rotates). Any value of 'link_number' should be good
% for this

%%%%%%%%%
% Create figure and axes for the plot, and store the handle in a
% variable named 'ax'
%%%%%%%%%
% Draw a surface for each link, and save the handles to these surfaces
% in a cell array named 'l'
%%%%%%%%%
% Use 'view(ax,3)' to get a 3-dimensional view angle on the plot

% Use axis(ax,'vis3d') to make the arm stay the same size as you rotate
% it

%%%%%%%%%
% Loop over the locations of the joints (the base points of
% the links), and draw a dashed line from that joint to the point one
% unit from the joint in the direction of that joint's axis
%
% Save the handles to these lines into a cell array called 'l3'.
%
% As you make these lines, set their color property to be the
% same as the link immediately after the joint

end
1
2
3
4
10
11
12
19
20
21
22
23
24
25
26
27
28
29
30
31
32
Code to call your function
[link_vectors,…
joint_angles,…
joint_axes,…
link_extensions,…
prismatic,…
link_colors,…
link_set,…
ax,…
l,…
l3] = ME317_Assignment_draw_3D_arm_individual_links_prismatic;
1
2
3
4
5