removeBody
Remove body from robot
Description
Examples
Modify a Robot Rigid Body Tree Model
Make changes to an existingrigidBodyTree
object. You can get replace joints, bodies and subtrees in the rigid body tree.
Load example robots asrigidBodyTree
objects.
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 theL3
body is theL4
body. 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 theL3
body. You must create a newJoint
object and usereplaceJoint
to ensure the downstream body geometry is unaffected. CallsetFixedTransform
if 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 modifiedL3
body. Add the original copiedL3
body to theL2
body, 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
robot
—Robot model
rigidBodyTree
object
Robot model, specified as arigidBodyTree
object.
bodyname
—Body name
string scalar|character vector
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
newSubtree
— Robot subtree
rigidBodyTree
object
Robot subtree, returned as arigidBodyTree
object. This new subtree uses the parent name of the body specified bybodyname
as the base name. All bodies that are attached in the previous robot model (including the body withbodyname
specified) are added to the subtree.
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
Usage notes and limitations:
When creating therigidBodyTree
object, use the syntax that specifies theMaxNumBodies
as an upper bound for adding bodies to the robot model. You must also specify theDataFormat
property as a name-value pair. For example:
robot = rigidBodyTree("MaxNumBodies",15,"DataFormat","row")
To minimize data usage, limit the upper bound to a number close to the expected number of bodies in the model. All data formats are supported for code generation. To use the dynamics functions, the data format must be set to"row"
or"column"
.
Theshow
andshowdetails
functions do not support code generation.
版本历史
Introduced in R2016b
See Also
Open Example
You have a modified version of this example. Do you want to open this example with your edits?
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select:.
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina(Español)
- Canada(English)
- United States(English)
Europe
- Belgium(English)
- Denmark(English)
- Deutschland(Deutsch)
- España(Español)
- Finland(English)
- France(Français)
- Ireland(English)
- Italia(Italiano)
- Luxembourg(English)
- Netherlands(English)
- Norway(English)
- Österreich(Deutsch)
- Portugal(English)
- Sweden(English)
- Switzerland
- United Kingdom(English)