Search in sources :

Example 31 with RigidBody

use of artisynth.core.mechmodels.RigidBody in project artisynth_core by artisynth.

the class SegmentedPlaneDemo method build.

public void build(String[] args) {
    // set up the mechmodel
    MechModel mechMod = new MechModel("mechMod");
    mechMod.setGravity(0, 0, -9.8);
    mechMod.setFrameDamping(1.0);
    mechMod.setRotaryDamping(4.0);
    mechMod.setIntegrator(MechSystemSolver.Integrator.BackwardEuler);
    // set up the rigid body and the plane constraint
    double lenx = 10;
    double leny = 5;
    double lenz = 3;
    RigidBody box = new RigidBody("box");
    RigidTransform3d XBoxToWorld = new RigidTransform3d();
    box.setInertia(SpatialInertia.createBoxInertia(10, lenx, leny, lenz));
    PolygonalMesh mesh = MeshFactory.createBox(lenx, leny, lenz);
    box.setMesh(mesh, /* fileName= */
    null);
    XBoxToWorld.p.set(0, 0, lenz / 2);
    box.setPose(XBoxToWorld);
    mechMod.addRigidBody(box);
    // FrameMarker mkr = new FrameMarker (box, -5, 2.5, 1.5);
    // mechMod.addFrameMarker (mkr);
    // RenderProps props = mkr.createRenderProps();
    // props.setPointColor (Color.blue);
    // props.setPointStyle (RenderProps.PointStyle.SPHERE);
    // props.setPointRadius (0.25);
    // mkr.setRenderProps (props);
    RigidTransform3d XPlanesToWorld = new RigidTransform3d();
    // XPlanesToWorld.R.setAxisAngle(0,1,0,Math.PI);
    SegmentedPlanarConnector segPlanes = new SegmentedPlanarConnector(box, new Vector3d(-5, 2.5, 1.5), XPlanesToWorld, new double[] { -6, 4, -3, 1, -1, 0, 1, 0, 3, 1, 6, 4 });
    segPlanes.setUnilateral(true);
    segPlanes.setPlaneSize(10);
    RenderProps props = segPlanes.createRenderProps();
    props.setPointColor(Color.blue);
    props.setPointStyle(PointStyle.SPHERE);
    props.setPointRadius(0.25);
    segPlanes.setRenderProps(props);
    // mechMod.addRigidBody (box);
    mechMod.addBodyConnector(segPlanes);
    addModel(mechMod);
    addControlPanel(mechMod);
// AffineTransform3d X = new AffineTransform3d ();
// X.applyScaling (1, 1, 2);
// mechMod.transformGeometry (X);
// RigidTransform3d X = new RigidTransform3d (0, 0, 1.5);
// box.transformGeometry (X);
}
Also used : MechModel(artisynth.core.mechmodels.MechModel) RigidBody(artisynth.core.mechmodels.RigidBody) SegmentedPlanarConnector(artisynth.core.mechmodels.SegmentedPlanarConnector)

Example 32 with RigidBody

use of artisynth.core.mechmodels.RigidBody in project artisynth_core by artisynth.

the class SkinDemo method addAntagonist.

public void addAntagonist() {
    RigidBody lowerArm = model.rigidBodies().get("lower");
    if (lowerArm == null) {
        return;
    }
    Point3d markerBodyPos = new Point3d(-size.x / 2, 0, 0);
    // Point3d markerBodyPos = new Point3d(-size.x,0,-(size.z/2.0)/1.2);
    FrameMarker marker = new FrameMarker();
    model.addFrameMarker(marker, lowerArm, markerBodyPos);
    Particle fixed = new Particle(1.0, new Point3d(-size.z / 4, 0, -size.z / 2.0));
    // Particle fixed = new Particle(1.0,new Point3d(size.z/4,0,size.z));
    fixed.setDynamic(false);
    model.addParticle(fixed);
    AxialSpring spring = new AxialSpring(100.0, 2.0, 0.0);
    spring.setFirstPoint(marker);
    spring.setSecondPoint(fixed);
    RenderProps rp = new RenderProps(model.getRenderProps());
    rp.setLineStyle(Renderer.LineStyle.SPINDLE);
    rp.setShading(Renderer.Shading.FLAT);
    rp.setLineColor(Color.WHITE);
    spring.setRenderProps(rp);
    model.addAxialSpring(spring);
}
Also used : Particle(artisynth.core.mechmodels.Particle) FrameMarker(artisynth.core.mechmodels.FrameMarker) Point3d(maspack.matrix.Point3d) RenderProps(maspack.render.RenderProps) RigidBody(artisynth.core.mechmodels.RigidBody) AxialSpring(artisynth.core.mechmodels.AxialSpring)

Example 33 with RigidBody

use of artisynth.core.mechmodels.RigidBody in project artisynth_core by artisynth.

the class SkinDemo method addMuscle.

public void addMuscle() {
    RigidBody upperArm = model.rigidBodies().get("upper");
    RigidBody lowerArm = model.rigidBodies().get("lower");
    if (upperArm == null || lowerArm == null) {
        return;
    }
    Point3d markerBodyPos = new Point3d(-size.x / 2, 0, (size.z / 2.0) / 1.2);
    FrameMarker u = new FrameMarker();
    model.addFrameMarker(u, upperArm, markerBodyPos);
    u.setName("upperAttachment");
    markerBodyPos = new Point3d(size.x / 2, 0, -(size.z / 2.0) / 2);
    FrameMarker l = new FrameMarker();
    model.addFrameMarker(l, lowerArm, markerBodyPos);
    l.setName("lowerAttachment");
    Muscle muscle = new Muscle("muscle");
    muscle.setPeckMuscleMaterial(20.0, 22.0, 30, 0.2, 0.5, 0.1);
    muscle.setFirstPoint(u);
    muscle.setSecondPoint(l);
    RenderProps rp = new RenderProps(model.getRenderProps());
    rp.setLineStyle(Renderer.LineStyle.SPINDLE);
    rp.setLineRadius(len / 20);
    // rp.setLineSlices(10);
    rp.setShading(Renderer.Shading.SMOOTH);
    rp.setLineColor(Color.RED);
    muscle.setRenderProps(rp);
    model.addAxialSpring(muscle);
    if (addCompression) {
        markerBodyPos = new Point3d(size.x / 2, 0, +size.z / 2.0);
        FrameMarker l2 = new FrameMarker();
        model.addFrameMarker(l2, lowerArm, markerBodyPos);
        l2.setName("lowerAttachmentCompressor");
        double len = u.getPosition().distance(l2.getPosition());
        AxialSpring s = new AxialSpring(10, 0, 50);
        s.setFirstPoint(u);
        s.setSecondPoint(l2);
        model.addAxialSpring(s);
        RenderProps props = new RenderProps();
        props.setLineStyle(Renderer.LineStyle.CYLINDER);
        props.setLineRadius(0.0);
        s.setRenderProps(props);
    }
}
Also used : FrameMarker(artisynth.core.mechmodels.FrameMarker) Point3d(maspack.matrix.Point3d) RenderProps(maspack.render.RenderProps) Muscle(artisynth.core.mechmodels.Muscle) RigidBody(artisynth.core.mechmodels.RigidBody) AxialSpring(artisynth.core.mechmodels.AxialSpring)

Example 34 with RigidBody

use of artisynth.core.mechmodels.RigidBody in project artisynth_core by artisynth.

the class SkinDemo method addEndPoint.

public void addEndPoint() {
    RigidBody lowerArm = model.rigidBodies().get("lower");
    if (lowerArm == null) {
        return;
    }
    FrameMarker endPoint = new FrameMarker();
    endPoint.setName("endPoint");
    endPoint.setFrame(lowerArm);
    endPoint.setLocation(new Point3d(0, 0, len / 2));
    model.addFrameMarker(endPoint);
    // lowerArm.addMarker(endPoint);
    RenderProps rp = new RenderProps(model.getRenderProps());
    rp.setShading(Renderer.Shading.SMOOTH);
    rp.setPointColor(Color.ORANGE);
    rp.setPointRadius(len / 20);
    endPoint.setRenderProps(rp);
}
Also used : FrameMarker(artisynth.core.mechmodels.FrameMarker) Point3d(maspack.matrix.Point3d) RenderProps(maspack.render.RenderProps) RigidBody(artisynth.core.mechmodels.RigidBody)

Example 35 with RigidBody

use of artisynth.core.mechmodels.RigidBody in project artisynth_core by artisynth.

the class SkinDemo method addBody.

public RigidBody addBody(String name, RigidTransform3d pose, String meshName) {
    // add a simple rigid body to the simulation
    RigidBody rb = new RigidBody();
    rb.setName(name);
    rb.setPose(pose);
    model.addRigidBody(rb);
    PolygonalMesh mesh;
    try {
        String meshFilename = ArtisynthPath.getHomeRelativePath("src/artisynth/demos/mech/geometry/", ".") + meshName;
        mesh = new PolygonalMesh();
        mesh.read(new BufferedReader(new FileReader(new File(meshFilename))));
        rb.setMesh(mesh, meshFilename);
    } catch (IOException e) {
        System.out.println(e.getMessage());
        mesh = MeshFactory.createBox(size.x, size.y, size.z);
        rb.setMesh(mesh, null);
    }
    rb.setInertia(SpatialInertia.createBoxInertia(10.0, size.x, size.y, size.z));
    RenderProps rp = new RenderProps(model.getRenderProps());
    rp.setFaceColor(Color.GRAY);
    rp.setShading(Renderer.Shading.FLAT);
    rb.setRenderProps(rp);
    rb.setFrameDamping(10);
    rb.setRotaryDamping(1000.0);
    return rb;
}
Also used : BufferedReader(java.io.BufferedReader) RenderProps(maspack.render.RenderProps) FileReader(java.io.FileReader) RigidBody(artisynth.core.mechmodels.RigidBody) IOException(java.io.IOException) PolygonalMesh(maspack.geometry.PolygonalMesh) File(java.io.File)

Aggregations

RigidBody (artisynth.core.mechmodels.RigidBody)55 MechModel (artisynth.core.mechmodels.MechModel)25 RigidTransform3d (maspack.matrix.RigidTransform3d)18 FrameMarker (artisynth.core.mechmodels.FrameMarker)11 RenderProps (maspack.render.RenderProps)11 Point3d (maspack.matrix.Point3d)10 PolygonalMesh (maspack.geometry.PolygonalMesh)9 RevoluteJoint (artisynth.core.mechmodels.RevoluteJoint)8 Vector3d (maspack.matrix.Vector3d)8 FemModel3d (artisynth.core.femmodels.FemModel3d)7 FemNode3d (artisynth.core.femmodels.FemNode3d)7 SphericalJoint (artisynth.core.mechmodels.SphericalJoint)7 WayPoint (artisynth.core.probes.WayPoint)6 AxialSpring (artisynth.core.mechmodels.AxialSpring)5 Particle (artisynth.core.mechmodels.Particle)5 Color (java.awt.Color)5 CollisionManager (artisynth.core.mechmodels.CollisionManager)4 File (java.io.File)4 IOException (java.io.IOException)4 AxisAngle (maspack.matrix.AxisAngle)4