3 Mechanical Models I

3.10 Attached frames

In the same sense that a Marker is a point attached to another dynamic component, an AttachedFrame is a coordinate frame attached to a dynamic component.

3.10.1 Frame attached frames

A FrameAttachedFrame is an AttachedFrame that is rigidly connected to a master Frame (which includes RigidBody as a subclass), in the same way that a FrameMarker is a point attached to a Frame. Once attached, the FrameAttachedFrame moves rigidly with its master frame. The relative pose of the attached frame with respect to its master is described by the transform {\bf T}_{FM}, referred to in the code examples as TFM.

FrameAttachedFrame objects can be created using a variety of constructors, including

FrameAttachedFrame ()
FrameAttachedFrame (String name)
FrameAttachedFrame (RigidTransform3d TFW)
FrameAttachedFrame (Frame frame, RigidTransform3d TFW)

where FrameAttachedFrame() creates a default frame with no master assigned, FrameAttachedFrame(name) adds a name, and FrameAttachedFrame(TFW) initializes the world pose to TFW. The last constructor also attaches the frame to frame, with {\bf T}_{FM} computed from the two frames’ current world poses. After construction, the master frame can be set and queried using

void setFrame (Frame frame)
Frame getFrame ()

where setFrame(frame) computes {\bf T}_{FM} from the attached frame’s current world pose and the master’s world pose. The transform {\bf T}_{FM} and the world pose {\bf T}_{FW} can also be set and queried directly:

RigidTransform3d getTFM ()

Returns {\bf T}_{FM}.

void setTFM (RigidTransform3d TFM)

Sets {\bf T}_{FM} and updates {\bf T}_{FW}.

void setTFW (RigidTransform3d TFW)

Sets {\bf T}_{FW} and updates {\bf T}_{FM} accordingly.

Note there is no need for a getTFW() method because that is the same as the frame’s getPose() method, whereas setTFW() differs from setPose(TFW) because the former updates {\bf T}_{FM} to accommodate the new value of {\bf T}_{FW}, while the latter does not and so the frame will revert back to the pose imparted by the master.

Created FrameAttachedFrame objects must be added to the MechModel. One way to do this is to add them to the model’s frames container, which is managed using the MechModel methods:

void addFrame (Frame frame)

Adds frame frame to the container.

boolean removeFrame (Frame frame)

Removes frame frame from the container.

void clearFrames()

Removes all frames.

RenderableComponentList<Frame> frames()

Returns the frames container.

FrameAttachedFrame objects can be added directly to a Frame component, which maintains an attachedFrames container as a subcomponent. Attached frames can be added to this list using

void addAttachedFrame (FrameAttachedFrame frm)

Adds an existing FrameAttachedFrame to a frame, setting its master to frame if necessary.

FrameAttachedFrame addAttachedFrame ( MRigidTransform3d TFM)

Creates a FrameAttachedFrame at pose {\bf T}_{FM} with respect to frame coordinates.

FrameAttachedFrame addAttachedFrameWorld ( MRigidTransform3d TFW)

Creates a FrameAttachedFrame at pose {\bf T}_{FW} with respect to world coordinates.

The attachedFrames container can be accessed and frames removed using

RenderableComponentList<FrameAttachedFrame> MgetAttachedFrames ()

Returns the frame’s attachedFrames container.

boolean removeAttachedFrame ( MFrameAttachedFrame frm)

Removes frm from the container; returns true if it was present.

void clearAttachedFrames ()

Removes all frames from the container.

3.10.2 Example: attached frames for a rigid body

Figure 3.39: RigidBodyAttachedFrames model loaded into ArtiSynth.

A model demonstrating the attachment of frames to a rigid body is defined in

  artisynth.demos.tutorial.RigidBodyAttachedFrames

This subclasses RigidBodyJoint (Section 3.4.6) and extends its build() method to add two FrameAttachedFrames to bodyA, one specified via {\bf T}_{FM} and one via the world pose {\bf T}_{FW}:

1    public void build (String[] args) {
2
3       // build the base scene (two rigid bodies + hinge joint)
4       super.build (args);
5
6       // Add a FrameAttachedFrame via TFM: positioned at the tip of bodyA
7       // along its local x-axis (half of lenx2 from the body origin).
8       RigidTransform3d TFM1 = new RigidTransform3d (lenx2/2, 0, 0);
9       FrameAttachedFrame frm1 = bodyA.addAttachedFrame (TFM1);
10       frm1.setName ("frameAtTip");
11       frm1.setAxisLength (4.0);
12       frm1.setAxisDrawStyle (AxisDrawStyle.ARROW);
13
14       // Add a FrameAttachedFrame via TFW: placed in world coordinates at the
15       // center of bodyA’s current world pose.
16       RigidTransform3d TFW = new RigidTransform3d (bodyA.getPose());
17       FrameAttachedFrame frm2 = bodyA.addAttachedFrameWorld (TFW);
18       frm2.setName ("frameAtCenter");
19       frm2.setAxisLength (4.0);
20       frm2.setAxisDrawStyle (AxisDrawStyle.ARROW);
21    }

The first attached frame, frameAtTip, is created using addAttachedFrame(TFM), with {\bf T}_{FM} placing it at the tip of bodyA along its local x-axis. The second, frameAtCenter, is created using addAttachedFrameWorld(TFW), with its world pose set to match the current pose of bodyA, so it sits at the body’s origin. Both frames are rendered as solid arrow triads (AxisDrawStyle.ARROW).

To run this example in ArtiSynth, select All demos > tutorial > RigidBodyAttachedFrames from the Models menu. The model should load and initially appear as in Figure 3.39. Running the model will cause bodyA to swing under gravity, with both attached frames moving rigidly with it.