3 Mechanical Models I

3.6 Attachments

ArtiSynth provides the ability to rigidly attach dynamic components to other dynamic components, allowing different parts of a model to be connected together. Attachments are made by adding to a MechModel special attachment components that manage the attachment physics as described briefly in Section 1.2.

3.6.1 Point attachments

Point attachments allow particles and other point-based components to be attached to other, more complex components, such as frames, rigid bodies, or finite element models (Section 6.4). Point attachments are implemented by creating attachment components that are instances of PointAttachment. Modeling applications do not generally handle the attachment components directly, but instead create them implicitly using the following MechModel method:

  attachPoint (Point p1, PointAttachable comp);

This attaches a point p1 to any component which implements the interface PointAttachable, indicating that it is capable creating an attachment to a point. Components that implement PointAttachable currently include rigid bodies, particles, and finite element models. The attachment is created based on the the current position of the point and component in question. For attaching a point to a rigid body, another method may be used:

  attachPoint (Point p1, RigidBody body, Point3d loc);

This attaches p1 to body at the point loc specified in body coordinates. Finite element attachments are discussed in Section 6.4.

Once a point is attached, it will be in the attached state, as described in Section 3.1.3. Attachments can be removed by calling

  detachPoint (Point p1);

3.6.2 Example: model with particle attachments

Figure 3.28: ParticleAttachment model loaded into ArtiSynth.

A model illustrating particle-particle and particle-rigid body attachments is defined in

  artisynth.demos.tutorial.ParticleAttachment

and most of the code is shown here:

1    public Particle addParticle (MechModel mech, double x, double y, double z) {
2       // create a particle at x, y, z and add it to mech
3       Particle p = new Particle (/*name=*/null, /*mass=*/.1, x, y, z);
4       mech.addParticle (p);
5       return p;
6    }
7
8    public AxialSpring addSpring (MechModel mech, Particle p1, Particle p2){
9       // create a spring connecting p1 and p2 and add it to mech
10       AxialSpring spr = new AxialSpring (/*name=*/null, /*restLength=*/0);
11       spr.setMaterial (new LinearAxialMaterial (/*k=*/20, /*d=*/10));
12       spr.setPoints (p1, p2);
13       mech.addAxialSpring (spr);
14       return spr;
15    }
16
17    public void build (String[] args) {
18
19       // create MechModel and add to RootModel
20       MechModel mech = new MechModel ("mech");
21       addModel (mech);
22
23       // create the components
24       Particle p1 = addParticle (mech, 0, 0, 0.55);
25       Particle p2 = addParticle (mech, 0.1, 0, 0.35);
26       Particle p3 = addParticle (mech, 0.1, 0, 0.35);
27       Particle p4 = addParticle (mech, 0, 0, 0.15);
28       addSpring (mech, p1, p2);
29       addSpring (mech, p3, p4);
30       // create box and set its pose (position/orientation):
31       RigidBody box =
32          RigidBody.createBox ("box", /*wx,wy,wz=*/0.5, 0.3, 0.3, /*density=*/20);
33       box.setPose (new RigidTransform3d (/*x,y,z=*/0.2, 0, 0));
34       mech.addRigidBody (box);
35
36       p1.setDynamic (false);               // first particle set to be fixed
37
38       // set up the attachments
39       mech.attachPoint (p2, p3);
40       mech.attachPoint (p4, box, new Point3d (0, 0, 0.15));
41
42       // increase model bounding box for the viewer
43       mech.setBounds (/*min=*/-0.5, 0, -0.5, /*max=*/0.5, 0, 0);
44       // set render properties for the components
45       RenderProps.setSphericalPoints (mech, 0.06, Color.RED);
46       RenderProps.setCylindricalLines (mech, 0.02, Color.BLUE);
47    }

The code is very similar to ParticleSpring and RigidBodySpring described in Sections 3.1.2 and 3.2.2, except that two convenience methods, addParticle() and addSpring(), are defined at lines 1-15 to create particles and spring and add them to a MechModel. These are used in the build() method to create four particles and two springs (lines 24-29), along with a rigid body box (lines 31-34). As with the other examples, particle p1 is set to be non-dynamic (line 36) in order to fix it in place and provide a ground.

The attachments are added at lines 39-40, with p2 attached to p3 and p4 connected to the box at the location (0,0,0.15) in box coordinates.

Finally, render properties are set starting at line 43. In this example, point and line render properties are set for the entire MechModel instead of individual components. Since render properties are inherited, this will implicitly set the specified render properties in all sub-components for which these properties are not explicitly set (either locally or in an intermediate ancestor).

To run this example in ArtiSynth, select All demos > tutorial > ParticleAttachment from the Models menu. The model should load and initially appear as in Figure 3.28. Running the model (Section 1.5.3) will cause the box to fall and swing under gravity.

3.6.3 Frame attachments

Frame attachments allow rigid bodies and other frame-based components to be attached to other components, including frames, rigid bodies, or finite element models (Section 6.6). Frame attachments are implemented by creating attachment components that are instances of FrameAttachment.

As with point attachments, modeling applications do not generally handle frame attachment components directly, but instead create and add them implicitly using the following MechModel methods:

  attachFrame (Frame frame, FrameAttachable comp);
  attachFrame (Frame frame, FrameAttachable comp, RigidTransform3d TFW);

These attach frame to any component which implements the interface FrameAttachable, indicating that it is capable of creating an attachment to a frame. Components that implement FrameAttachable currently include frames, rigid bodies, and finite element models. For the first method, the attachment is created based on the the current position of the frame and component in question. For the second method, the attachment is created so that the initial pose of the frame (in world coordinates) is described by TFW.

Once a frame is attached, it will be in the attached state, as described in Section 3.1.3. Frame attachments can be removed by calling

  detachFrame (Frame frame);

While it is possible to create composite rigid bodies using FrameAttachments, this is much less computationally efficient (and less accurate) than creating a single rigid body through mesh merging or similar techniques.

3.6.4 Example: model with frame attachments

Figure 3.29: FrameBodyAttachment model loaded into ArtiSynth.

A model illustrating rigidBody-rigidBody and frame-rigidBody attachments is defined in

  artisynth.demos.tutorial.FrameBodyAttachment

Most of the code is identical to that for RigidBodyJoint as described in Section 3.3.5, except that the joint is further to the left and connects bodyB to ground, rather than to bodyA, and the initial pose of bodyA is changed so that it is aligned vertically. bodyA is then connected to bodyB, and an auxiliary frame is created and attached to bodyA, using code at the end of the build() method as shown here:

1    public void build (String[] args) {
2
3       ... create model mostly similar to RigidBodyJoint ...
4
5       // now connect bodyA to bodyB using a FrameAttachment
6       mech.attachFrame (bodyA, bodyB);
7
8       // create an auxiliary frame and add it to the mech model
9       Frame frame = new Frame();
10       mech.addFrame (frame);
11
12       // set the frames axis length > 0 so we can see it
13       frame.setAxisLength (4.0);
14       // set the attached frame’s pose to that of bodyA ...
15       RigidTransform3d TFW = new RigidTransform3d (bodyA.getPose());
16       // ... plus a translation of lenx2/2 along the x axis:
17       TFW.mulXyz (lenx2/2, 0, 0);
18       // finally, attach the frame to bodyA
19       mech.attachFrame (frame, bodyA, TFW);
20    }

To run this example in ArtiSynth, select All demos > tutorial > FrameBodyAttachment from the Models menu. The model should load and initially appear as in Figure 3.28. The frame attached to bodyA is visible in the lower right corner. Running the model (Section 1.5.3) will cause both bodies to fall and swing about the joint under gravity.