Main Content

removeBody

Remove body from robot

Description

removeBody(robot,bodyname)removes the body and all subsequently attached bodies from the robot model.

example

newSubtree= removeBody(robot,bodyname)returns the subtree created by removing the body and all subsequently attached bodies from the robot model.

Examples

collapse all

Make changes to an existingrigidBodyTreeobject. You can get replace joints, bodies and subtrees in the rigid body tree.

Load example robots asrigidBodyTreeobjects.

loadexampleRobots.mat

View the details of the Puma robot usingshowdetails.

showdetails(puma1)
-------------------- Robot: (6 bodies) Idx Body Name Joint Name Joint Type Parent Name(Idx) Children Name(s) --- --------- ---------- ---------- ---------------- ---------------- 1 L1 jnt1 revolute base(0) L2(2) 2 L2 jnt2 revolute L1(1) L3(3) 3 L3 jnt3 revolute L2(2) L4(4) 4 L4 jnt4 revolute L3(3) L5(5) 5 L5 jnt5 revolute L4(4) L6(6) 6 L6 jnt6 revolute L5(5) --------------------

Get a specific body to inspect the properties. The only child of theL3body is theL4body. You can copy a specific body as well.

body3 = getBody(puma1,'L3'); childBody = body3.Children{1}
childBody = rigidBody with properties: Name: 'L4' Joint: [1x1 rigidBodyJoint] Mass: 1 CenterOfMass: [0 0 0] Inertia: [1 1 1 0 0 0] Parent: [1x1 rigidBody] Children: {[1x1 rigidBody]} Visuals: {} Collisions: {}
body3Copy = copy(body3);

Replace the joint on theL3body. You must create a newJointobject and usereplaceJointto ensure the downstream body geometry is unaffected. CallsetFixedTransformif necessary to define a transform between the bodies instead of with the default identity matrices.

newJoint = rigidBodyJoint('prismatic'); replaceJoint(puma1,'L3',newJoint); showdetails(puma1)
-------------------- Robot: (6 bodies) Idx Body Name Joint Name Joint Type Parent Name(Idx) Children Name(s) --- --------- ---------- ---------- ---------------- ---------------- 1 L1 jnt1 revolute base(0) L2(2) 2 L2 jnt2 revolute L1(1) L3(3) 3 L3 prismatic fixed L2(2) L4(4) 4 L4 jnt4 revolute L3(3) L5(5) 5 L5 jnt5 revolute L4(4) L6(6) 6 L6 jnt6 revolute L5(5) --------------------

Remove an entire body and get the resulting subtree usingremoveBody. The removed body is included in the subtree.

subtree = removeBody(puma1,'L4')
子树= rigidBodyTree with properties: NumBodies: 3 Bodies: {[1x1 rigidBody] [1x1 rigidBody] [1x1 rigidBody]} Base: [1x1 rigidBody] BodyNames: {'L4' 'L5' 'L6'} BaseName: 'L3' Gravity: [0 0 0] DataFormat: 'struct'

Remove the modifiedL3body. Add the original copiedL3body to theL2body, followed by the returned subtree. The robot model remains the same. See a detailed comparison throughshowdetails.

removeBody(puma1,'L3'); addBody(puma1,body3Copy,'L2') addSubtree(puma1,'L3',subtree) showdetails(puma1)
-------------------- Robot: (6 bodies) Idx Body Name Joint Name Joint Type Parent Name(Idx) Children Name(s) --- --------- ---------- ---------- ---------------- ---------------- 1 L1 jnt1 revolute base(0) L2(2) 2 L2 jnt2 revolute L1(1) L3(3) 3 L3 jnt3 revolute L2(2) L4(4) 4 L4 jnt4 revolute L3(3) L5(5) 5 L5 jnt5 revolute L4(4) L6(6) 6 L6 jnt6 revolute L5(5) --------------------

Input Arguments

collapse all

Robot model, specified as arigidBodyTreeobject.

Body name, specified as a string scalar character vector. This body must be on the robot model specified inrobot.

Data Types:char|string

Output Arguments

collapse all

Robot subtree, returned as arigidBodyTreeobject. This new subtree uses the parent name of the body specified bybodynameas the base name. All bodies that are attached in the previous robot model (including the body withbodynamespecified) are added to the subtree.

Extended Capabilities

版本历史

Introduced in R2016b