Search in sources :

Example 26 with MechModel

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

the class SimpleCollide method removeObject.

private void removeObject(ModelComponent comp, ObjectType type) {
    MechModel mechMod = (MechModel) models().get(0);
    ComponentList<Probe> myProbes = getInputProbes();
    for (Probe p : myProbes) {
        System.out.println("type's name: " + type.name());
        System.out.println("probe's name: " + p.getName());
        if (type.name().equals(p.getName())) {
            removeInputProbe(p);
        }
    }
    switch(type) {
        case FemEllipsoid:
        case FemSphere:
        case FemCube:
            {
                mechMod.removeModel((FemModel3d) comp);
                break;
            }
        case Box:
        case Molar:
        case Bin:
        case Paw:
        case House:
            {
                mechMod.removeRigidBody((RigidBody) comp);
                break;
            }
        default:
            {
                throw new InternalErrorException("Unimplemented type " + type);
            }
    }
}
Also used : MechModel(artisynth.core.mechmodels.MechModel) FemModel3d(artisynth.core.femmodels.FemModel3d) RigidBody(artisynth.core.mechmodels.RigidBody) InternalErrorException(maspack.util.InternalErrorException) Probe(artisynth.core.probes.Probe) NumericInputProbe(artisynth.core.probes.NumericInputProbe)

Example 27 with MechModel

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

the class MechModelCollide method build.

public void build(String[] args) {
    MechModel mechMod = new MechModel("mechMod");
    // mechMod.setProfiling (true);
    mechMod.setGravity(0, 0, -98);
    // mechMod.setRigidBodyDamper (new FrameDamper (1.0, 4.0));
    mechMod.setFrameDamping(1.0);
    mechMod.setRotaryDamping(4.0);
    RigidTransform3d XMB = new RigidTransform3d();
    RigidTransform3d XLW = new RigidTransform3d();
    RigidTransform3d TCA = new RigidTransform3d();
    RigidTransform3d TCB = new RigidTransform3d();
    RigidTransform3d XAB = new RigidTransform3d();
    PolygonalMesh mesh;
    // number of slices for approximating a circle
    int nslices = 16;
    // // set view so tha points upwards
    // X.R.setAxisAngle (1, 0, 0, -Math.PI/2);
    // viewer.setTransform (X);
    double lenx0 = 30;
    double leny0 = 30;
    double lenz0 = 2;
    RigidBody base = RigidBody.createBox("base", lenx0, leny0, lenz0, 0.2);
    base.setDynamic(false);
    mechMod.setDefaultCollisionBehavior(true, 0.20);
    RenderProps props;
    // first link
    double lenx1 = 10;
    double leny1 = 2;
    double lenz1 = 3;
    RigidBody link1 = new RigidBody("link1");
    link1.setInertia(SpatialInertia.createBoxInertia(10, lenx1, leny1, lenz1));
    mesh = MeshFactory.createRoundedBox(lenx1, leny1, lenz1, nslices / 2);
    XMB.setIdentity();
    XMB.R.setAxisAngle(1, 1, 1, 2 * Math.PI / 3);
    mesh.transform(XMB);
    // mesh.setRenderMaterial (Material.createSpecial (Material.GRAY));
    link1.setMesh(mesh, /* fileName= */
    null);
    XLW.R.setAxisAngle(1, 0, 0, Math.PI / 2);
    // XLW.R.mulAxisAngle (0, 1, 0, Math.PI/4);
    XLW.p.set(0, 0, 1.5 * lenx1);
    link1.setPose(XLW);
    mechMod.addRigidBody(link1);
    // second link
    double lenx2 = 10;
    double leny2 = 2;
    double lenz2 = 2;
    RigidBody link2 = new RigidBody("link2");
    if (// useSphericalJoint)
    false) {
        mesh = MeshFactory.createRoundedCylinder(leny2 / 2, lenx2, nslices, /*nsegs=*/
        1, /*flatBottom=*/
        false);
        link2.setInertia(SpatialInertia.createBoxInertia(10, leny2, leny2, lenx2));
        XLW.R.setAxisAngle(1, 0, 0, Math.PI / 2);
        XLW.p.set(lenx1 / 2, lenx2 / 2, lenx1);
        link2.setPose(XLW);
    }
    mesh = MeshFactory.createRoundedCylinder(leny2 / 2, lenx2, nslices, /*nsegs=*/
    1, /*flatBottom=*/
    false);
    mesh.transform(XMB);
    link2.setInertia(SpatialInertia.createBoxInertia(10, lenx2, leny2, lenz2));
    XLW.R.setAxisAngle(1, 0, 0, Math.PI / 2);
    XLW.p.set(lenx1 / 2 + lenx2 / 2, 0, 1.5 * lenx1);
    if (useSphericalJoint) {
        // Math.PI/4;
        double ang = 0;
        XLW.R.mulAxisAngle(0, 1, 0, ang);
        XLW.p.y += Math.sin(ang) * lenx2 / 2;
        XLW.p.x -= (1 - Math.cos(ang)) * lenx2 / 2;
    }
    link2.setPose(XLW);
    link2.setMesh(mesh, /* fileName= */
    null);
    mechMod.addRigidBody(link2);
    if (transparentLinks) {
        RenderProps.setFaceStyle(link1, Renderer.FaceStyle.NONE);
        RenderProps.setDrawEdges(link1, true);
        RenderProps.setFaceStyle(link2, Renderer.FaceStyle.NONE);
        RenderProps.setDrawEdges(link2, true);
    }
    BodyConnector joint2 = null;
    // joint 2
    if (useSphericalJoint) {
        TCA.setIdentity();
        TCA.p.set(-lenx2 / 2, 0, 0);
        XAB.mulInverseLeft(link1.getPose(), link2.getPose());
        TCB.mul(XAB, TCA);
        SphericalJoint sjoint = new SphericalJoint(link2, TCA, link1, TCB);
        // RevoluteJoint joint2 = new RevoluteJoint (link2, TCA, TCB);
        sjoint.setName("joint2");
        // RenderProps.setLineRadius(sjoint, 0.2);
        sjoint.setAxisLength(4);
        mechMod.addBodyConnector(sjoint);
        joint2 = sjoint;
    } else {
        TCA.setIdentity();
        TCA.p.set(-lenx2 / 2, 0, 0);
        // TCA.R.mulAxisAngle (1, 0, 0, -Math.toRadians(90));
        XAB.mulInverseLeft(link1.getPose(), link2.getPose());
        TCB.mul(XAB, TCA);
        RevoluteJoint rjoint = new RevoluteJoint(link2, TCA, link1, TCB);
        rjoint.setName("joint2");
        rjoint.setAxisLength(4);
        RenderProps.setLineRadius(rjoint, 0.2);
        mechMod.addBodyConnector(rjoint);
        rjoint.setTheta(35);
        joint2 = rjoint;
    }
    mechMod.transformGeometry(new RigidTransform3d(-5, 0, 10, 1, 1, 0, Math.toRadians(30)));
    mechMod.addRigidBody(base);
    mechMod.setCollisionBehavior(link1, link2, false);
    CollisionManager cm = mechMod.getCollisionManager();
    RenderProps.setVisible(cm, true);
    RenderProps.setLineWidth(cm, 3);
    RenderProps.setLineColor(cm, Color.RED);
    cm.setDrawContactNormals(true);
    mechMod.setPenetrationTol(1e-3);
    // try {
    // MechSystemSolver.setLogWriter (
    // ArtisynthIO.newIndentingPrintWriter ("solve.txt"));
    // }
    // catch (Exception e)  {
    // }
    addModel(mechMod);
    // mechMod.setIntegrator (Integrator.ForwardEuler);
    // addBreakPoint (0.51);
    // mechMod.setProfiling (true);
    addControlPanel(mechMod);
}
Also used : MechModel(artisynth.core.mechmodels.MechModel) SphericalJoint(artisynth.core.mechmodels.SphericalJoint) CollisionManager(artisynth.core.mechmodels.CollisionManager) RevoluteJoint(artisynth.core.mechmodels.RevoluteJoint) RigidBody(artisynth.core.mechmodels.RigidBody) BodyConnector(artisynth.core.mechmodels.BodyConnector) RevoluteJoint(artisynth.core.mechmodels.RevoluteJoint) WayPoint(artisynth.core.probes.WayPoint) SphericalJoint(artisynth.core.mechmodels.SphericalJoint)

Example 28 with MechModel

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

the class CompliantConstraintDemo method build.

public void build(String[] args) {
    MechModel mechMod = new MechModel("mechMod");
    // mechMod.setProfiling (true);
    mechMod.setGravity(0, 0, -50);
    // mechMod.setRigidBodyDamper (new FrameDamper (1.0, 4.0));
    mechMod.setFrameDamping(1.0);
    mechMod.setRotaryDamping(4.0);
    mechMod.setIntegrator(MechSystemSolver.Integrator.SymplecticEuler);
    RigidTransform3d XMB = new RigidTransform3d();
    RigidTransform3d XLW = new RigidTransform3d();
    RigidTransform3d TCA = new RigidTransform3d();
    RigidTransform3d TCB = new RigidTransform3d();
    RigidTransform3d XAB = new RigidTransform3d();
    PolygonalMesh mesh;
    // number of slices for approximating a circle
    int nslices = 16;
    // // set view so tha points upwards
    // X.R.setAxisAngle (1, 0, 0, -Math.PI/2);
    // viewer.setTransform (X);
    double lenx0 = 15;
    double leny0 = 15;
    double lenz0 = 1.5;
    RenderProps props;
    double ks = 10;
    double ds = 10;
    // mechMod.addRigidBody (base);
    // first link
    double lenx1 = 10;
    double leny1 = 2;
    double lenz1 = 3;
    RigidBody link1 = new RigidBody("link1");
    link1.setInertia(SpatialInertia.createBoxInertia(10, lenx1, leny1, lenz1));
    mesh = MeshFactory.createRoundedBox(lenx1, leny1, lenz1, nslices / 2);
    XMB.setIdentity();
    XMB.R.setAxisAngle(1, 1, 1, 2 * Math.PI / 3);
    mesh.transform(XMB);
    // mesh.setRenderMaterial (Material.createSpecial (Material.GRAY));
    link1.setMesh(mesh, /* fileName= */
    null);
    XLW.R.setAxisAngle(1, 0, 0, Math.PI / 2);
    // XLW.R.mulAxisAngle (0, 1, 0, Math.PI/4);
    XLW.p.set(0, 0, 1.5 * lenx1);
    link1.setPose(XLW);
    mechMod.addRigidBody(link1);
    // joint 1
    BodyConnector joint1 = null;
    RevoluteJoint rjoint = null;
    TCA.setIdentity();
    TCA.p.set(-lenx1 / 2, 0, 0);
    // TCA.R.mulAxisAngle (0, 1, 0, Math.PI/4);
    TCB.set(link1.getPose());
    TCB.mul(TCA);
    rjoint = new RevoluteJoint(link1, TCA, TCB);
    rjoint.setName("joint1");
    rjoint.setAxisLength(4);
    RenderProps.setLineRadius(rjoint, 0.2);
    joint1 = rjoint;
    // second link
    double lenx2 = 10;
    double leny2 = 2;
    double lenz2 = 2;
    RigidBody link2 = new RigidBody("link2");
    if (// useSphericalJoint)
    false) {
        mesh = MeshFactory.createRoundedCylinder(leny2 / 2, lenx2, nslices, /*nsegs=*/
        1, /*flatBottom=*/
        false);
        link2.setInertia(SpatialInertia.createBoxInertia(10, leny2, leny2, lenx2));
        XLW.R.setAxisAngle(1, 0, 0, Math.PI / 2);
        XLW.p.set(lenx1 / 2, lenx2 / 2, lenx1);
        link2.setPose(XLW);
    }
    mesh = MeshFactory.createRoundedCylinder(leny2 / 2, lenx2, nslices, /*nsegs=*/
    1, /*flatBottom=*/
    false);
    mesh.transform(XMB);
    link2.setInertia(SpatialInertia.createBoxInertia(10, lenx2, leny2, lenz2));
    XLW.R.setAxisAngle(1, 0, 0, Math.PI / 2);
    XLW.p.set(lenx1 / 2 + lenx2 / 2, 0, 1.5 * lenx1);
    if (useSphericalJoint) {
        // Math.PI/4;
        double ang = 0;
        XLW.R.mulAxisAngle(0, 1, 0, ang);
        XLW.p.y += Math.sin(ang) * lenx2 / 2;
        XLW.p.x -= (1 - Math.cos(ang)) * lenx2 / 2;
    }
    link2.setPose(XLW);
    link2.setMesh(mesh, /* fileName= */
    null);
    mechMod.addRigidBody(link2);
    BodyConnector joint2 = null;
    // joint 2
    if (useSphericalJoint) {
        TCA.setIdentity();
        TCA.p.set(-lenx2 / 2, 0, 0);
        XAB.mulInverseLeft(link1.getPose(), link2.getPose());
        TCB.mul(XAB, TCA);
        SphericalJoint sjoint = new SphericalJoint(link2, TCA, link1, TCB);
        // RevoluteJoint joint2 = new RevoluteJoint (link2, TCA, TCB);
        sjoint.setName("joint2");
        // RenderProps.setLineRadius(sjoint, 0.2);
        sjoint.setAxisLength(4);
        joint2 = sjoint;
    } else {
        TCA.setIdentity();
        TCA.p.set(-lenx2 / 2, 0, 0);
        // TCA.R.mulAxisAngle (1, 0, 0, -Math.toRadians(90));
        XAB.mulInverseLeft(link1.getPose(), link2.getPose());
        TCB.mul(XAB, TCA);
        rjoint = new RevoluteJoint(link2, TCA, link1, TCB);
        rjoint.setName("joint2");
        rjoint.setAxisLength(4);
        RenderProps.setLineRadius(rjoint, 0.2);
        joint2 = rjoint;
    }
    mechMod.addBodyConnector(joint1);
    if (joint2 != null) {
        mechMod.addBodyConnector(joint2);
    }
    mechMod.transformGeometry(new RigidTransform3d(0, 0, 0, 0, Math.toRadians(75), 0));
    addModel(mechMod);
    addControlPanel(mechMod);
}
Also used : MechModel(artisynth.core.mechmodels.MechModel) SphericalJoint(artisynth.core.mechmodels.SphericalJoint) RevoluteJoint(artisynth.core.mechmodels.RevoluteJoint) RigidBody(artisynth.core.mechmodels.RigidBody) BodyConnector(artisynth.core.mechmodels.BodyConnector) RevoluteJoint(artisynth.core.mechmodels.RevoluteJoint) WayPoint(artisynth.core.probes.WayPoint) SphericalJoint(artisynth.core.mechmodels.SphericalJoint)

Example 29 with MechModel

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

the class MenuBarHandler method doBlankMechmodel.

private void doBlankMechmodel() {
    doClearModel();
    myMain.getRootModel().addModel(new MechModel());
}
Also used : MechModel(artisynth.core.mechmodels.MechModel)

Example 30 with MechModel

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

the class TorusWrapTest method build.

public void build(String[] args) {
    MechModel mechMod = new MechModel("mechMod");
    mechMod.setGravity(0, 0, -9.8);
    mechMod.setFrameDamping(10.0);
    mechMod.setRotaryDamping(0.1);
    RigidBody block = new RigidBody("block");
    PolygonalMesh mesh = MeshFactory.createBox(size, size, size);
    block.setMesh(mesh, null);
    block.setInertiaFromDensity(1);
    // mechMod.addRigidBody (block);
    Particle p0 = new Particle(0.1, size * 3, 0, size / 2);
    p0.setDynamic(false);
    mechMod.addParticle(p0);
    Particle p1 = new Particle(0.1, -size * 3, 0, size / 2);
    p1.setDynamic(false);
    mechMod.addParticle(p1);
    Particle p2 = new Particle(0.1, -size * 3, size, size / 2);
    p2.setDynamic(false);
    // mechMod.addParticle (p2);
    Particle p3 = new Particle(0.1, size * 3, size, size / 2);
    p3.setDynamic(false);
    // mechMod.addParticle (p3);
    RigidTorus torus1 = new RigidTorus("torus1", size, size / 3, myDensity, 50, 30);
    RigidTorus torus2 = new RigidTorus("torus2", size, size / 3, myDensity, 50, 30);
    RigidTorus torus3 = new RigidTorus("torus3", size, size / 3, myDensity, 50, 30);
    torus1.setPose(new RigidTransform3d(-2 * size, 0, 0, 0, Math.PI / 2, 0));
    torus2.setPose(new RigidTransform3d(2 * size, 0, 0, 0, Math.PI / 2, 0));
    torus3.setPose(new RigidTransform3d(0, 0, 0, 0, Math.PI / 2, 0));
    mechMod.addRigidBody(torus1);
    mechMod.addRigidBody(torus2);
    mechMod.addRigidBody(torus3);
    mechMod.setDefaultCollisionBehavior(true, 0);
    MultiPointSpring spring = new MultiPointSpring("spring", 100, 0.1, 0);
    spring.addPoint(p0);
    spring.setSegmentWrappable(50);
    spring.addWrappable(torus1);
    spring.addWrappable(torus2);
    spring.addWrappable(torus3);
    spring.addPoint(p1);
    // spring.addPoint (p2);
    // spring.setSegmentWrappable (50);
    // spring.addPoint (p3);
    // spring.setWrapDamping (1.0);
    // spring.setWrapStiffness (10);
    // spring.setWrapH (0.01);
    mechMod.addMultiPointSpring(spring);
    spring.setDrawKnots(false);
    spring.setDrawABPoints(true);
    spring.setWrapDamping(100);
    spring.setMaxWrapIterations(10);
    addModel(mechMod);
    RenderProps.setPointStyle(mechMod, Renderer.PointStyle.SPHERE);
    RenderProps.setPointRadius(mechMod, size / 10);
    RenderProps.setLineStyle(mechMod, Renderer.LineStyle.CYLINDER);
    RenderProps.setLineRadius(mechMod, size / 30);
    RenderProps.setLineColor(mechMod, Color.red);
    createControlPanel(mechMod);
}
Also used : Particle(artisynth.core.mechmodels.Particle) MechModel(artisynth.core.mechmodels.MechModel) RigidTransform3d(maspack.matrix.RigidTransform3d) RigidBody(artisynth.core.mechmodels.RigidBody) PolygonalMesh(maspack.geometry.PolygonalMesh) RigidTorus(artisynth.core.mechmodels.RigidTorus) MultiPointSpring(artisynth.core.mechmodels.MultiPointSpring)

Aggregations

MechModel (artisynth.core.mechmodels.MechModel)59 RigidBody (artisynth.core.mechmodels.RigidBody)25 RigidTransform3d (maspack.matrix.RigidTransform3d)19 FemModel3d (artisynth.core.femmodels.FemModel3d)14 FemNode3d (artisynth.core.femmodels.FemNode3d)8 Particle (artisynth.core.mechmodels.Particle)8 PolygonalMesh (maspack.geometry.PolygonalMesh)8 Vector3d (maspack.matrix.Vector3d)8 RevoluteJoint (artisynth.core.mechmodels.RevoluteJoint)7 LinearMaterial (artisynth.core.materials.LinearMaterial)6 FrameMarker (artisynth.core.mechmodels.FrameMarker)6 CollisionManager (artisynth.core.mechmodels.CollisionManager)5 Color (java.awt.Color)5 AxialSpring (artisynth.core.mechmodels.AxialSpring)4 BodyConnector (artisynth.core.mechmodels.BodyConnector)4 WayPoint (artisynth.core.probes.WayPoint)4 Point3d (maspack.matrix.Point3d)4 MultiPointSpring (artisynth.core.mechmodels.MultiPointSpring)3 PlanarConnector (artisynth.core.mechmodels.PlanarConnector)3 FemElement3d (artisynth.core.femmodels.FemElement3d)2