www.gusucode.com > robotics 案例源码程序 matlab代码 > robotics/AttachARigidBodyAndJointToARigidBodyTreeExample.m
%% 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 |Joint| object and % must be added to the |RigidBodyTree| using |addBody|. %% % Create a rigid body tree. rbtree = robotics.RigidBodyTree; %% % Create a rigid body with a unique name. body1 = robotics.RigidBody('b1'); %% % Create a revolute joint. By default, the |RigidBody| object comes with a % fixed joint. Replace the joint by assigning a new |Joint| object to the % |body1.Joint| property. jnt1 = robotics.Joint('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)