Skip to content

Commit

Permalink
Attempts to reproduce the problem
Browse files Browse the repository at this point in the history
  • Loading branch information
tzaeschke committed Jan 19, 2025
1 parent 7ffe0a1 commit fffde4a
Show file tree
Hide file tree
Showing 6 changed files with 418 additions and 47 deletions.
2 changes: 1 addition & 1 deletion core/src/main/java/org/ode4j/ode/internal/DxQuickStep.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ private enum ReorderingMethod {
// uncomment the following line to randomly reorder constraint rows
// during the solution. depending on the situation, this can help a lot
// or hardly at all, but it doesn't seem to hurt.
private static final ReorderingMethod CONSTRAINTS_REORDERING_METHOD = ReorderingMethod.REORDERING_METHOD__RANDOMLY;
private static final ReorderingMethod CONSTRAINTS_REORDERING_METHOD = ReorderingMethod.REORDERING_METHOD__DONT_REORDER;

// #if CONSTRAINTS_REORDERING_METHOD == REORDERING_METHOD__RANDOMLY
// #if !defined(RANDOM_CONSTRAINTS_REORDERING_FREQUENCY)
Expand Down
45 changes: 17 additions & 28 deletions demo/src/main/java/org/ode4j/demo/DemoBuggy.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,7 @@
import org.ode4j.math.DQuaternion;
import org.ode4j.math.DVector3;
import org.ode4j.math.DVector3C;
import org.ode4j.ode.DPlane;
import org.ode4j.ode.DSphere;
import org.ode4j.ode.OdeConstants;
import org.ode4j.ode.OdeHelper;
import org.ode4j.ode.OdeMath;
import org.ode4j.ode.DBody;
import org.ode4j.ode.DBox;
import org.ode4j.ode.DContact;
import org.ode4j.ode.DContactBuffer;
import org.ode4j.ode.DGeom;
import org.ode4j.ode.DHinge2Joint;
import org.ode4j.ode.DJointGroup;
import org.ode4j.ode.DJoint;
import org.ode4j.ode.DMass;
import org.ode4j.ode.DSpace;
import org.ode4j.ode.DWorld;
import org.ode4j.ode.*;
import org.ode4j.ode.DGeom.DNearCallback;

import static org.ode4j.drawstuff.DrawStuff.*;
Expand Down Expand Up @@ -75,7 +60,7 @@ class DemoBuggy extends dsFunctions {
private static DWorld world;
private static DSpace space;
private static DBody[] body = new DBody[4];
private static DHinge2Joint[] joint = new DHinge2Joint[3]; // joint[0] is the front wheel
private static DHingeJoint[] joint = new DHingeJoint[3]; // joint[0] is the front wheel
private static DJointGroup contactgroup;
private static DPlane ground;
private static DSpace car_space;
Expand Down Expand Up @@ -150,6 +135,7 @@ public void command (char cmd)
switch (cmd) {
case 'a': case 'A':
speed += 0.3;
System.out.println("speed=" + speed);
break;
case 'z': case 'Z':
speed -= 0.3;
Expand Down Expand Up @@ -187,19 +173,19 @@ private void simLoop (boolean pause)
int i;
if (!pause) {
// motor
joint[0].setParamVel2 (-speed);
joint[0].setParamFMax2 (0.1);
joint[0].setParamVel (-speed);
joint[0].setParamFMax (0.1);

// steering
double v = steer - joint[0].getAngle1();
double v = steer - joint[0].getAngle();
if (v > 0.1) v = 0.1;
if (v < -0.1) v = -0.1;
v *= 10.0;
joint[0].setParamVel (v);
joint[0].setParamFMax (0.2);
joint[0].setParamLoStop (-0.75);
joint[0].setParamHiStop (0.75);
joint[0].setParamFudgeFactor (0.1);
//joint[0].setParamFudgeFactor (0.1);

space.collide(null,nearCallback);
world.step(0.05);
Expand Down Expand Up @@ -264,18 +250,21 @@ private void demo(String[] args) {

// front and back wheel hinges
for (i=0; i<3; i++) {
joint[i] = OdeHelper.createHinge2Joint (world,null);
joint[i] = OdeHelper.createHingeJoint (world,null);
joint[i].attach(body[0],body[i+1]);
final DVector3C a = body[i+1].getPosition();
DHinge2Joint h2 = joint[i];
DHingeJoint h2 = joint[i];
h2.setAnchor (a);
h2.setAxes (zunit, yunit);
//h2.setAxes (zunit, yunit);
// h2.setAxis (yunit);
h2.setAxis (yunit);
}
//DHinge2Joint h; h.set

// set joint suspension
for (i=0; i<3; i++) {
joint[i].setParamSuspensionERP (0.4);
joint[i].setParamSuspensionCFM (0.8);
// joint[i].setParamSuspensionERP (0.4);
// joint[i].setParamSuspensionCFM (0.8);
}

// lock back wheels along the steering axis
Expand All @@ -285,8 +274,8 @@ private void demo(String[] args) {
joint[i].setParamHiStop (0);
// the following alternative method is no good as the wheels may get out
// of alignment:
// dJointSetHinge2Param (joint[i],dParamVel,0);
// dJointSetHinge2Param (joint[i],dParamFMax,dInfinity);
joint[i].setParamVel(0);
joint[i].setParamFMax(Double.POSITIVE_INFINITY);// dJointSetHinge2Param (joint[i],dParamFMax,dInfinity);
}

// create car space and add it to the top level space
Expand Down
34 changes: 18 additions & 16 deletions demo/src/main/java/org/ode4j/demo/DemoCrash.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class DemoCrash extends dsFunctions {
private static boolean BALLSTACK = false;
private static boolean ONEBALL = true;
private static boolean CENTIPEDE = true;
private static boolean CANNON = true;
private static boolean CANNON = !true;

// dynamics and collision objects (chassis, 3 wheels, environment)

Expand Down Expand Up @@ -641,21 +641,23 @@ private void simLoop (boolean pause)
for (i=0; i< spheres; i++) dsDrawSphere (sphere[i].getPosition(),
sphere[i].getRotation(),RADIUS);

// draw the cannon
dsSetColor (1,1,0);
DMatrix3 R2 = new DMatrix3(), R3 = new DMatrix3(), R4 = new DMatrix3();
dRFromAxisAndAngle (R2,0,0,1,cannon_angle);
dRFromAxisAndAngle (R3,0,1,0,cannon_elevation);
dMultiply0 (R4,R2,R3);
DVector3 cpos = new DVector3(CANNON_X,CANNON_Y,1);
DVector3 csides = new DVector3(2,2,2);
dsDrawBox (cpos,R2,csides);
for (i=0; i<3; i++) cpos.add(i, 1.5*R4.get(i, 2));//[i*4+2]);
dsDrawCylinder (cpos,R4,3f,0.5f);

// draw the cannon ball
dsDrawSphere (cannon_ball_body.getPosition(),cannon_ball_body.getRotation(),
CANNON_BALL_RADIUS);
if (CANNON) {
// draw the cannon
dsSetColor (1,1,0);
DMatrix3 R2 = new DMatrix3(), R3 = new DMatrix3(), R4 = new DMatrix3();
dRFromAxisAndAngle (R2,0,0,1,cannon_angle);
dRFromAxisAndAngle (R3,0,1,0,cannon_elevation);
dMultiply0 (R4,R2,R3);
DVector3 cpos = new DVector3(CANNON_X,CANNON_Y,1);
DVector3 csides = new DVector3(2,2,2);
dsDrawBox (cpos,R2,csides);
for (i=0; i<3; i++) cpos.add(i, 1.5*R4.get(i, 2));//[i*4+2]);
dsDrawCylinder (cpos,R4,3f,0.5f);

// draw the cannon ball
dsDrawSphere(cannon_ball_body.getPosition(), cannon_ball_body.getRotation(),
CANNON_BALL_RADIUS);
}
}

public static void main(String[] args) {
Expand Down
160 changes: 160 additions & 0 deletions demo/src/main/java/org/ode4j/demo/DemoHingeX.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
/*************************************************************************
* *
* Open Dynamics Engine, Copyright (C) 2001,2002 Russell L. Smith. *
* All rights reserved. Email: [email protected] Web: www.q12.org *
* Open Dynamics Engine 4J, Copyright (C) 2009-2014 Tilmann Zaeschke *
* All rights reserved. Email: [email protected] Web: www.ode4j.org *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of EITHER: *
* (1) The GNU Lesser General Public License as published by the Free *
* Software Foundation; either version 2.1 of the License, or (at *
* your option) any later version. The text of the GNU Lesser *
* General Public License is included with this library in the *
* file LICENSE.TXT. *
* (2) The BSD-style license that is included with this library in *
* the file ODE-LICENSE-BSD.TXT and ODE4J-LICENSE-BSD.TXT. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files *
* LICENSE.TXT, ODE-LICENSE-BSD.TXT and ODE4J-LICENSE-BSD.TXT for more *
* details. *
* *
*************************************************************************/
package org.ode4j.demo;

import org.ode4j.math.DQuaternion;
import org.ode4j.math.DVector3;
import org.ode4j.math.DVector3C;
import org.ode4j.ode.*;

import static org.ode4j.drawstuff.DrawStuff.*;
import static org.ode4j.ode.OdeMath.dQFromAxisAndAngle;


/**
* Hinge demo.
*/
public class DemoHingeX extends dsFunctions {
private static final double SIDE = 5; // side length of a box
private static final double MASS = 125; // mass of a box


// dynamics and collision objects
private DWorld world;
private final DBody[] body = new DBody[3];
private DFixedJoint fixed0;
private DHingeJoint hinge01;
private DHingeJoint hinge12;

// start simulation - set viewpoint
private static final float[] xyz = {5.0382f, -5.0811f, 18.4700f};
private static final float[] hpr = {135.0000f, -19.5000f, 0.0000f};

@Override
public void start() {
dsSetViewpoint(xyz, hpr);
System.out.println("Press 'e' to start/stop occasional error.");
}

// called when a key pressed
@Override
public void command(char cmd) {
if (cmd == 'e' || cmd == 'E') {
//TZ occasional_error ^= 1;
}
}

// simulation loop
private static double a = 0;

private void simLoop(boolean pause) {
final double kd = -0.3; // angular damping constant
if (!pause) {
// add an oscillating torque to body 0, and also damp its rotational motion
final DVector3C w = body[0].getAngularVel();
//body[0].addTorque ( kd*w.get0(), kd*w.get1()+10.1*Math.cos(a), kd*w.get2()+10.1*Math.sin(a));
body[1].addTorque(0, 0, kd * w.get2() + 10 * Math.sin(a));
world.step(0.05);
a += 0.01;
}

DVector3 sides0 = new DVector3(SIDE, SIDE, SIDE);
DVector3 sides1 = new DVector3(SIDE, SIDE, SIDE * 0.8f);
DVector3 sides2 = new DVector3(SIDE, SIDE, SIDE);
dsSetTexture(DS_TEXTURE_NUMBER.DS_WOOD);
dsSetColor(1, 1, 0);
dsDrawBox(body[0].getPosition(), body[0].getRotation(), sides0);
dsSetColor(0, 1, 1);
dsDrawBox(body[1].getPosition(), body[1].getRotation(), sides1);
dsSetColor(1, 0, 1);
dsDrawBox(body[2].getPosition(), body[2].getRotation(), sides2);
}


/**
* @param args args
*/
public static void main(String[] args) {
new DemoHingeX().demo(args);
}

private void demo(String[] args) {
// create world
OdeHelper.initODE2(0);
world = OdeHelper.createWorld();

DMass m = OdeHelper.createMass();
m.setBox(1, SIDE, SIDE, SIDE);
m.adjust(MASS);

DQuaternion q = new DQuaternion();
dQFromAxisAndAngle(q, 1, 1, 0, 0. * Math.PI);

body[0] = OdeHelper.createBody(world);
body[0].setMass(m);
body[0].setPosition(0, 0, 3);
//body[0].setQuaternion (q);

fixed0 = OdeHelper.createFixedJoint(world, null);
fixed0.attach(null, body[0]);
fixed0.setFixed();

body[1] = OdeHelper.createBody(world);
body[1].setMass(m);
body[1].setPosition(SIDE, SIDE, 3);
//body[1].setQuaternion (q);

hinge01 = OdeHelper.createHingeJoint(world, null);
hinge01.attach(body[0], body[1]);
hinge01.setAnchor(0.5 * SIDE, 0.5 * SIDE, 3);
hinge01.setAxis(0, 0, 1);

body[2] = OdeHelper.createBody(world);
body[2].setMass(m);
body[2].setPosition(2.0 * SIDE, 2.0 * SIDE, 3);
//body[2].setQuaternion (q);

hinge12 = OdeHelper.createHingeJoint(world, null);
hinge12.attach(body[1], body[2]);
hinge12.setAnchor(1.5 * SIDE, 1.5 * SIDE, 3);
hinge12.setAxis(0, 0, 1);

// run simulation
dsSimulationLoop(args, 640, 480, this);

world.destroy();
OdeHelper.closeODE();
}

@Override
public void step(boolean pause) {
simLoop(pause);
}

@Override
public void stop() {
// Nothing to do
}
}
Loading

0 comments on commit fffde4a

Please sign in to comment.