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");

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");

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");

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");