Main Content

Obtain Collision Data for Manipulator Collision Checking

This example shows three ways to obtain a rigidBodyTree model with collision data. To see more in-depth examples that check for self-collisions or environment collision detection, see these other examples:

URDF Import

Many robots come with collision meshes or primitives specified in the Unified Robot Definition Format (URDF) file.

The KUKA® IIWA robot comes with a set of collision meshes which are simplified versions of the visual meshes. Call the importrobotfunction to generate a rigidBodyTree object from the URDF file. Set the output format for configurations to "column".

iiwa = importrobot("iiwa14.urdf");
iiwa.DataFormat = "column";

Visually inspect the collision meshes of the robot.

show(iiwa,"Visuals","off","Collisions","on");

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, iiwa_link_0_coll_mesh, iiwa_link_1_coll_mesh, iiwa_link_2_coll_mesh, iiwa_link_3_coll_mesh, iiwa_link_4_coll_mesh, iiwa_link_5_coll_mesh, iiwa_link_6_coll_mesh, iiwa_link_7_coll_mesh.

Check for Self-Collisions at a Specified Configuration

Specify a configuration that has a self collision. The checkCollision function indicates whether a robot is colliding with itself in a particular configuration. Visualize the configuration.

config = [0 -pi/4 pi 0.9*pi 0 -pi/2 0]';
checkCollision(iiwa,config,'SkippedSelfCollisions','parent')
ans = logical
   1

show(iiwa,config,"Visuals","off","Collisions","on");

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, iiwa_link_0_coll_mesh, iiwa_link_1_coll_mesh, iiwa_link_2_coll_mesh, iiwa_link_3_coll_mesh, iiwa_link_4_coll_mesh, iiwa_link_5_coll_mesh, iiwa_link_6_coll_mesh, iiwa_link_7_coll_mesh.

Load Provided Models

Robotics System Toolbox™ provides common robot models with collision data accessed using the loadrobot function.

kukaIiwa14 = loadrobot("kukaIiwa14","DataFormat","column");
checkCollision(kukaIiwa14,config,'SkippedSelfCollisions','parent')
ans = logical
   1

config = [0 -pi/4 pi 0.9*pi 0 -pi/2 0]';

Visualize the robot with the collision meshes visible.

show(kukaIiwa14,config,"Visuals","off","Collisions","on");

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, iiwa_link_0_coll_mesh, iiwa_link_1_coll_mesh, iiwa_link_2_coll_mesh, iiwa_link_3_coll_mesh, iiwa_link_4_coll_mesh, iiwa_link_5_coll_mesh, iiwa_link_6_coll_mesh, iiwa_link_7_coll_mesh.

Adding Individual Collision Objects

The addCollision function enables you to add collision objects to any rigid body on the robot as basic shapes (box, sphere, cylinder). You could build your entire robot with these collision geometries, but this is generally less accurate than higher fidelity mesh definitions.

For this example, notice that the loaded IIWA robot model is missing a gripper. Add a gripper made of collision primitives to the iiwa_link_ee body on the robot.

addCollision(iiwa.Bodies{end},"cylinder",[0.06,0.05])
addCollision(iiwa.Bodies{end},"box",[0.02,0.02,0.15],trvec2tform([0.03,0,0.05]))
addCollision(iiwa.Bodies{end},"box",[0.02,0.02,0.15],trvec2tform([-0.03,0,0.05]))

Visualize the robot. Notice the gripper is attached.

show(iiwa,"Visuals","off","Collisions","on");

Figure contains an axes object. The axes object with xlabel X, ylabel Y contains 32 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, iiwa_link_0_coll_mesh, iiwa_link_1_coll_mesh, iiwa_link_2_coll_mesh, iiwa_link_3_coll_mesh, iiwa_link_4_coll_mesh, iiwa_link_5_coll_mesh, iiwa_link_6_coll_mesh, iiwa_link_7_coll_mesh, iiwa_link_ee_kuka_coll_mesh.

See Also

|

Related Topics