This example showcases how to manage frames within a rigid body, covering operations such as adding, removing, and updating frames, as well as retrieving transforms between them.
Create a rigid body robot model and display initial frame information.
A rigid body can contain multiple frames used to define coordinate systems for attaching sensors, tools, or other components.
rbFrame = struct with fields:
Name: 'rb'
RigidTransform: [4×4 double]
ParentFrame: ''
ChildFrames: {1×0 cell}
Add a new frame named test
to the rigid body rb
, defining its position with a translation relative to the root frame rb
.
Next, add another frame, test1
, which is positioned relative to the newly added frame test
using a combination of translation and rotation.
Each frame is defined by its name, parent frame, and rigid transform.
Display information about these added frames to verify their properties and confirm their placement within the rigid body.
testFrame = struct with fields:
Name: 'test1'
RigidTransform: [4×4 double]
ParentFrame: 'test'
ChildFrames: {1×0 cell}
You can also remove frames, which updates the frame tree to maintain its kinematic structure. Remove the frame test
and observe its effect on test1
frame.
frameAfterRemove = struct with fields:
Name: 'test1'
RigidTransform: [4×4 double]
ParentFrame: 'rb'
ChildFrames: {1×0 cell}
Now, modify existing frames by updating their properties, such as the name, parent frame, or rigid transform.
First, rename test1
frame to test2
.
Add a new frame test3
and update test2
to use it as the parent frame.
Display updated frame information.
frameAfterUpdate = struct with fields:
Name: 'test2'
RigidTransform: [4×4 double]
ParentFrame: 'test3'
ChildFrames: {1×0 cell}