Main Content

Execute Transformation Trajectory Using Manipulator and Inverse Kinematics

This example shows how to generate a transformation trajectory using the Transform Trajectory block and execute it for a manipulator robot using inverse kinematics.

Generate two homogenous transformations for the start and end points of the trajectory.

tform1 = trvec2tform([0.25 -0.25 1])
tform1 = 4×4

    1.0000         0         0    0.2500
         0    1.0000         0   -0.2500
         0         0    1.0000    1.0000
         0         0         0    1.0000

tform2 = trvec2tform([0.25 0.25 0.5])
tform2 = 4×4

    1.0000         0         0    0.2500
         0    1.0000         0    0.2500
         0         0    1.0000    0.5000
         0         0         0    1.0000

Import the robot model and specify the data format for Simulink®.

robot = importrobot('iiwa14.urdf');
robot.DataFormat = 'column';
show(robot);

Figure contains an axes object. The axes object with xlabel X, ylabel Y contains 29 objects of type patch, line. These objects represent world, iiwa_link_0, iiwa_link_1, iiwa_link_2, iiwa_link_3, iiwa_link_4, iiwa_link_5, iiwa_link_6, iiwa_link_7, iiwa_link_ee, iiwa_link_ee_kuka, iiwa_link_0_mesh, iiwa_link_1_mesh, iiwa_link_2_mesh, iiwa_link_3_mesh, iiwa_link_4_mesh, iiwa_link_5_mesh, iiwa_link_6_mesh, iiwa_link_7_mesh.

Open the model. The Transform Trajectory block interpolates between the initial and final transformation specified in the block mask. These transformations are fed to the Inverse Kinematics block to solve for the robot configuration that makes the end effector reach the desired transformation. The configurations are output to the workspace as configurations.

open_system('transform_traj_ex1.slx')

Run the simulation and get the robot configurations.

simOut = sim('transform_traj_ex1.slx')
simOut = 
  Simulink.SimulationOutput:
         configurations: [7x1x52 double] 
                   tout: [52x1 double] 

     SimulationMetadata: [1x1 Simulink.SimulationMetadata] 
           ErrorMessage: [0x0 char] 

Show the robot configurations to animate the robot going through the trajectory.

for i = 1:numel(simOut.configurations)/7
    currConfig = simOut.configurations(:,:,i);
    show(robot,currConfig);
    drawnow
end

Figure contains an axes object. The axes object with xlabel X, ylabel Y contains 29 objects of type patch, line. These objects represent world, iiwa_link_0, iiwa_link_1, iiwa_link_2, iiwa_link_3, iiwa_link_4, iiwa_link_5, iiwa_link_6, iiwa_link_7, iiwa_link_ee, iiwa_link_ee_kuka, iiwa_link_0_mesh, iiwa_link_1_mesh, iiwa_link_2_mesh, iiwa_link_3_mesh, iiwa_link_4_mesh, iiwa_link_5_mesh, iiwa_link_6_mesh, iiwa_link_7_mesh.