Roboter Simulation Servo Problem

Hallo guys,



first a little overview for you that would hopefully describe the situation:



I built a model of a human robot in blender and export it with hottbj-0.3e.

After loading the Spatials of the roboter-jme.xml file and adding the DynamicPhysicsNodes and Joints

the robot is correctly shown and the rotation axis are correct too.



The problem, that I

Why do you call .rest() ?

Because you want to have it stand still?



Than you should use:

physicsNode.clearDynamics();



It will reset (like the JavaDoc) sais, all Forces, Torques and Velocities.
If you just want to reset the forces,
call clearForces();

thanks for the hint.



yes, i wanted the parts of the robot to stagnate, which have achieved their goal position.



setting countReset = 1; in the Servo class and calling the new update method achieves that e.g.

the arms holds the goal postion at 45

hi all,



seem so that i

Hi cubido,



Use HingeConstraint.class to connect two rigid bodies with a hinge. Use this constructor:


HingeConstraint(RigidBody rbA, RigidBody rbB, Vector3f pivotInA, Vector3f pivotInB, Vector3f axisInA, Vector3f axisInB)


The pivot points will be in the same position in world coordinates and the pivot axis will be collinear. Axis must point to the same direction. Make sure that the rigid bodies do not collide with these rules. Otherwise you get problems.

I can provide a simple example of my JBullet integration that I  use in my robot game http://www.jmonkeyengine.com/forum/index.php?topic=10743.0. I try to post the example on Saturday.

hi mazander,



i

cupido,



  Firstly, if you pull down the latest JMEPhysics trunk, JBullet is already integrated for you using the same JMEPhysics API you tried in the first place.



  However, if you're wanting to try to use the hinge constraint from JBullet, here's a quick tip or two:


  1. when posting code, you might want to remove all the commented out code.  It makes it easier to read and won't drive people away from your problem.



    The code you posted boils down to :


private HingeConstraint createHingeConstraint(
            String name, RigidBody rigidBody, Transform transform,
            Vector3f rotationAxis, Spatial spatial,
            String connectToName, RigidBody connectToBody,
            Vector3f connectToRotationAxis) {

        HingeConstraint hingeConstraint = null;

        if (connectToBody == null) {
            } else {

            Transform connectTransform = new Transform();
            connectToBody.getMotionState().getWorldTransform(connectTransform);

            if ((connectToName != null) && (connectToRotationAxis != null)) {

                Spatial connectToSpatial = fileNode.getChild(connectToName);

                Spatial connectHelpRotSpatial = fileNode.getChild("h" + name);
                com.jme.math.Vector3f connectRotationAxisPosJME =
                        connectHelpRotSpatial.getLocalTranslation();

                connectRotationAxisPosJME =
                        (jmeVector3f) connectHelpRotSpatial.getLocalTranslation().
                        subtract(connectToSpatial.getLocalTranslation());
               

                Vector3f connectRotationAxisPos = new Vector3f(
                        connectRotationAxisPosJME.x,
                        connectRotationAxisPosJME.y,
                        connectRotationAxisPosJME.z);

                Spatial helpRotSpatial = fileNode.getChild("h" + name);
                com.jme.math.Vector3f rotationAxisPosJME =
                        (jmeVector3f) helpRotSpatial.getLocalTranslation().
                        subtract(spatial.getLocalTranslation());
                Vector3f rotationAxisPos = new Vector3f(
                        rotationAxisPosJME.x,
                        rotationAxisPosJME.y,
                        rotationAxisPosJME.z);

                /*HingeConstraint     (
                btRigidBody       rbA,
                btRigidBody      rbB,
                const btVector3      pivotInA,
                const btVector3      pivotInB,
                btVector3      axisInA,
                btVector3      axisInB,
                bool  useReferenceFrameA = false )
                hinge constraint between two rigidbodies each with a pivotpoint that
                descibes the axis location in local space axis defines the orientation
                of the hinge axis*/
                hingeConstraint = new HingeConstraint(
                        rigidBody, connectToBody,
                        rotationAxisPos, connectRotationAxisPos,
                        rotationAxis, connectToRotationAxis);
                }
        }
        return hingeConstraint;
    }



2) There's seems to be a lot of context missing for this code snippet.  I'm not exactly sure what your arguments are that you're handing in, and you seem to be referencing some member variables.  (specifically fileNode, though I kinda get the gist of what's happening.)  Makes it tough to see what's going on.

3) From what it looks like, you're passing in local translations to JBullet, though what JBullet is expecting is world translations.  Remember that JBullet has no idea about your scenegraph, so ALL your interactions with it are going to be in world coordinates.  Same goes for rotations.

4) The constructor you're using has the slight limitation of assuming that the current orientation of your objects is the '0' position.  As the joint flexes and bends, your limits of +PI/2 to -PI/2 or whatever you set up for your joint limits is going to be based on the CURRENT orientation being 0.  If you use the HingeConstraint(RigidBody a, RigidBody b, Transform frameA, Transform frameB) constructor, you can get past that limitation, though it may take a wee bit of math on your part to set up the constraint frames correctly.  However . . . this constructor will work if all your joints REALLY ARE oriented at 0.

5) Finally . . . I'm sure you're doing this elsewhere, but don't forget to add the constraint to your dynamicsWorld.  If you don't take that step, JBullet won't even know you've built it.

Hope that all helps.  Let us know how your progress goes.

hi falken,



first sorry for answering so late and thanks for your tips.

I tried the JBullet integration from JMEPhysics out and it works better, then the last time i tried JMEPhysics. I will experiment with it and JBullet simultaneously respectively alternate between the two ways.

It would be great if i could make it with the JBullet integration in JMEPhysics.  :)



but unfortunately i

hi all,



i created a site on the jme wikis were publiced the code and the stuff i needed.

i hope this will help others which have similiar problems.



the site is just created (still under construction) and maybe not well disgned until now but you should find all you need if you want to try the simulation run, if you make an project from the java files and add all jars to your project and set the folder natives as dependencies.



http://www.jmonkeyengine.com/wiki/doku.php/starter:move_a_robot_with_jme2physics



regards cupido

Wow!!! What a great contribution, thanks!  You mentioned in the wiki that there may be errors since you are not a native English speaker, I, and probably others as well, would be happy to help tidy up the grammar here and there if you want.

it would be nice if some could throw an eye on it make the english a bit smooth.



as i look for some examples there were only some snippets and i thought it would be nice to have an simple project were someone could oriented and make his one simulation and may post his upgrades on this site.



So it is maybe also possible to develop the physic engine a little easier if some use cases are known and the code too.



ps: the simulation works only fine with the simplified model and boxes as collisionshapes, (in my code boolean boxmodel= true). with the more exat model and

dynPhysNode.generatePhysicsGeometry(true);

there come after some second the error about which i told in a post above. Or if the try catch block is actived my message, but the program still ends.



thanks for answering my question and best regards

cupido

hi,



i

So,



  I can't guarantee that this is the only problem with the code, but here's what I see.



  1) So what it looks like is that you're not setting your rotational axes for the Hinges.  If you provide an identity transform as your frame of reference for the hinge, it assumes that you're rotating around a -Z axis.  What you'll need to do is figure out what rotation you'd need to apply to a -Z axis to arrive at your desired rotational axis.  Then you'll use that as the 'basis' for your transforms for both rigid bodies.  Step 2, is to figure out where your anchor is, (in world coordinates) relative to 0,0,0, and set that as the 'origin' for the transforms.  The ONLY reason that these two transforms should not match, is if they are NOT aligned with their hinge and you want for them to snap in the appropriate alignment IMMEDIATELY once the joint is created.



      What I see in your code is that for a single-body hinge joint, your anchor will ALWAYS be broken.  The reason is that a newly created Transform is initialized to all 0s . . . NOT to an identity transform, which is I think what you want.  (identity transform = no rotation @ 0,0,0)  If you want a -Z-axis hinge with an anchor at 0,0,0 world coordinates, you'd need to call Transform.setIdentity() on your newly created transform before handing it in.  If you want another rotational axis, or an anchor NOT at 0,0,0, you'll need to set the transform appropriately.



      the second thing I see is that for a dual-body hinge joint, you're going to be creating a joint with a rotation in the -Z direction of your connectToBody's local reference frame.  And the joint will be anchored at the center of your rigid body.  Once again, you'll want to create your transforms in EXACTLY the same way as you would for the single-body hinge.  Remember, these constraints are all defined relative to the WORLD.  JBullet has no idea about JME's node heirarchy or each node's local frame of reference.



    2) 

connectTobody.getMotionState().getWorldTransform(connectToTransform);

  This code will APPEAR to do what you want it to, but it could be off a  bit.  The 'MotionState' in JBullet is used ONLY for calculating where to draw graphics connected to the rigid bodies.  It's an INTERPOLATED value which is NOT NECESSARILY an accurate representation of the physics simulation.  However, if your framerate is significantly faster than the physics sim step rate, that interpolated 'MotionState' will make your objects' movements appear to be smooth at all framerates.



  However, you should NEVER use a MotionState to determine a rigid body's current location in the simulation step.  You could end up introducing errors into the physics calculation.  Probably not big ones, but if they keep compounding on each other over time . . . not good.  :slight_smile:



  Anyway . . . that'll hopefully help you with correcting your simulation's problems.



-Falken

Hi all,



i continuing working with the jme-integration of jBullet from Falken and shows my result and the source code on the wiki

http://www.jmonkeyengine.com/wiki/doku.php/starter:move_a_robot_with_jme2physics



if someone is intereseted he/she is welcome to take a closer look and work with the code and post his/her result to on the webpage.



regards cupido


here is the code snippet of JBulletJoint from Falken where i pass the enableAngularMotor methode to make it available for JBulletHingeJoints.

Nevertheless there it is:

in package com.jmex.physics.impl.jbullet.joints;



public void enableAngularMotor(boolean enableMotor, float targetVelocity, float maxMotorImpulse) {
        if (constraint instanceof JBulletHingeJoint) {
            JBulletHingeJoint hinge = (JBulletHingeJoint) constraint;
            hinge.enableAngularMotor(enableMotor, targetVelocity, maxMotorImpulse);
        } else {
            System.out.println("enableAngularMotor(enableMotor, targetVelocity, maxMotorImpulse) " +
                    "is only available for instances of JBulletHingeJoint !");
        }
    }

hi,



there is now a new subsection where you can download a trial bundle and run the programm without any compiling.

http://www.jmonkeyengine.com/wiki/doku.php/starter:move_a_robot_with_jme2physics#trial_bundle



greets cupido