replaceBody
Replace body on robot
Description
Examples
Specify Dynamics Properties to Rigid Body Tree
To use dynamics functions to calculate joint torques and accelerations, specify the dynamics properties for the rigidBodyTree
object and rigidBody
.
Create a rigid body tree model. Create two rigid bodies to attach to it.
robot = rigidBodyTree('DataFormat','row'); body1 = rigidBody('body1'); body2 = rigidBody('body2');
Specify joints to attach to the bodies. Set the fixed transformation of body2
to body1
. This transform is 1m in the x-direction.
joint1 = rigidBodyJoint('joint1','revolute'); joint2 = rigidBodyJoint('joint2'); setFixedTransform(joint2,trvec2tform([1 0 0])) body1.Joint = joint1; body2.Joint = joint2;
Specify dynamics properties for the two bodies. Add the bodies to the robot model. For this example, basic values for a rod (body1
) with an attached spherical mass (body2
) are given.
body1.Mass = 2; body1.CenterOfMass = [0.5 0 0]; body1.Inertia = [0.001 0.67 0.67 0 0 0]; body2.Mass = 1; body2.CenterOfMass = [0 0 0]; body2.Inertia = 0.0001*[4 4 4 0 0 0]; addBody(robot,body1,'base'); addBody(robot,body2,'body1');
Compute the center of mass position of the whole robot. Plot the position on the robot. Move the view to the xy plane.
comPos = centerOfMass(robot); show(robot); hold on plot(comPos(1),comPos(2),'or') view(2)
Change the mass of the second body. Notice the change in center of mass.
body2.Mass = 20; replaceBody(robot,'body2',body2) comPos2 = centerOfMass(robot); plot(comPos2(1),comPos2(2),'*g') hold off
Input Arguments
robot
— Robot model
rigidBodyTree
object
Robot model, specified as a rigidBodyTree
object. The rigid body is added
to this object and attached at the rigid body specified by bodyname
.
bodyname
— Body name
string scalar | character vector
Body name, specified as a string scalar or character vector. This body must be on the robot
model specified in robot
.
Data Types: char
| string
newbody
— Rigid body
rigidBody
object
Rigid body, specified as a rigidBody
object.
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
Usage notes and limitations:
When creating the rigidBodyTree
object, use the syntax that specifies the
MaxNumBodies
as an upper bound for adding bodies to the robot model.
You must also specify the DataFormat
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"
.
The show
and showdetails
functions do not support code generation.
Version History
Introduced in R2016b
See Also
rigidBodyJoint
| rigidBody
| replaceJoint
| addBody
| removeBody
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)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)