%% Attach Rigid Body and Joint to Rigid Body Tree
% Add a rigid body and corresponding joint to a rigid body tree. Each rigidBody object contains a rigidBodyJoint object and must be added to the rigidBodyTree using addBody.
% Create a rigid body tree.

rbtree = rigidBodyTree;

%
% Create a rigid body with a unique name.

body1 = rigidBody('b1');

%
% Create a revolute joint. By default, the rigidBody object comes with a fixed joint. Replace the joint by assigning a new rigidBodyJoint object to the body1.Joint property.

jnt1 = rigidBodyJoint('jnt1','revolute');
body1.Joint = jnt1;

%
% Add the rigid body to the tree. Specify the body name that you are attaching the rigid body to. Because this is the first body, use the base name of the tree.

basename = rbtree.BaseName;
addBody(rbtree,body1,basename)

%
% Use showdetails on the tree to confirm the rigid body and joint were added properly.

showdetails(rbtree)

% Copyright 2012 The MathWorks, Inc.