# Revolutions per minute of PhysicsVehicleWheel

Hi,

is there any way to calculate the current revolutions per minute of a PhysicsVehicleWheel?

I found deltaRotation in the wheel’s wheelInfo, but I have no idea what that value means. Is thought its just the difference between the current rotation and the last rotation calculated by jbullet. Is that value dependent on the ticks per frame value?

Thanks,

Niclas

Yeah, why not just check the local rotation of the wheel spatial?

I read a bit about quaternions, but I didn’t understand how I am able to get a scalar value of the rotation (an angle, or something like that). Could you help me with this? Should I save the current local rotation of the wheel on each update and then calculate the difference between these two quaternions?

Thank you very much,

Niclas

I tested a bit more and I think the best solution would be a new field “rotationVelocity” in the wheelInfo class, but that would require changes in jbullet code, right? Does jme3 use any specific version of the jbullet library? I took a short look at the recent jbullet sourcecode and found some differences to the one that jme3 uses.

What I actually need is a rotation velocity for each wheel and I think the best way would be to store this in wheelInfo as it is calculated in com.bulletphysics.dynamics.vehicle.RaycastVehicle line 343 to 365:

[java]

WheelInfo wheel = wheelInfo.getQuick(i);

Vector3f relpos = Stack.alloc(Vector3f.class);

relpos.sub(wheel.raycastInfo.hardPointWS, getRigidBody().getCenterOfMassPosition(tmp));

Vector3f vel = getRigidBody().getVelocityInLocalPoint(relpos, Stack.alloc(Vector3f.class));

if (wheel.raycastInfo.isInContact) {

Transform chassisWorldTransform = getChassisWorldTransform(Stack.alloc(Transform.class));

Vector3f fwd = Stack.alloc(Vector3f.class);

fwd.set(

chassisWorldTransform.basis.getElement(0, indexForwardAxis),

chassisWorldTransform.basis.getElement(1, indexForwardAxis),

chassisWorldTransform.basis.getElement(2, indexForwardAxis));

float proj = fwd.dot(wheel.raycastInfo.contactNormalWS);

tmp.scale(proj, wheel.raycastInfo.contactNormalWS);

fwd.sub(tmp);

float proj2 = fwd.dot(vel);

wheel.deltaRotation = (proj2 * step) / (wheel.wheelsRadius);

wheel.rotation += wheel.deltaRotation;

}

[/java]

If I understood that correctly, the wheel.deltaRotation without the step factor would be exactly what is needed to calculate a rotation velocity, so adding a field and storing the value like (analogous to line 363 RaycastVehicle.java)

[java]

[/java]

I tried to do the same (in a very ugly way) in the simpleUpdate method of PhysicsVehicleTest.java:

[java]

PhysicsVehicleWheel wheel = vehicle.getWheel(0);

javax.vecmath.Vector3f relpos = new javax.vecmath.Vector3f();

javax.vecmath.Vector3f tmp = new javax.vecmath.Vector3f();

relpos.sub(wheel.getWheelInfo().raycastInfo.hardPointWS,vehicle.getRigidBody().getCenterOfMassPosition(tmp));

Vector3f vel = Converter.convert(vehicle.getRigidBody().getVelocityInLocalPoint(relpos, new javax.vecmath.Vector3f()));

float rotationVelocity = vehicle.getForwardVector(null).dot(vel) / wheel.getWheelInfo().wheelsRadius;

[/java]

Can someone try to check if I am correct at all that this calculates a rotation velocity, so that I can calculate the revolutions per minute of a wheel.

Thanks,

Niclas

We use the current mtn vcs version of jbullet in a slightly adapted version, its hosted at http://jbullet-jme.googlecode.com/ As for the wheel rotation, when you find out tell me how i can change the jme api so you dont need to access the native bullet objects.

Ok, I’ll post a patch as soon as I can.

I checked out the latest svn revision of jbullet-jme (jbullet branch) and the jme3 branch of jmonkeyengine, but there is an error with the DiscreteDynamicsWorld, in com.jme3.bullet PhysicsSpace.java in line 273 my netbeans is complaining about a missing method “setPreTickCallback”:

[java]

dynamicsWorld.setPreTickCallback(callback2);

[/java]

is that correct? Should I wait until this is fixed? Or am I using the wrong versions/branches?

I checked out:

and made a clean build of jbullet. Then I replaced the jbullet.jar in jme3 with the one of the dist/ folder from the jbullet project.

Thanks,
Niclas

Hm, no i didnt commit these changes yet as I added them myself without looking at how exactly its done in native bullet now…

I’ve put together two patches that add the calculation of the rotation velocity of a wheel to jme3.

Should I open an issue for that? Anyway, I’m posting the patches here, since they’re very small

The rotation velocity is already calculated by jbullet, but not stored anywhere. I’ve added an attribute to WheelInfo to store that value and a line to RaycastVehicle to calculate it. Patch is based on revision 607 of jbullet-jme:

[patch]

Index: src/com/bulletphysics/dynamics/vehicle/WheelInfo.java

===================================================================

— src/com/bulletphysics/dynamics/vehicle/WheelInfo.java (Revision 607)

+++ src/com/bulletphysics/dynamics/vehicle/WheelInfo.java (Arbeitskopie)

@@ -55,6 +55,7 @@

public float steering;

public float rotation;

public float deltaRotation;

• ``````   public float rotationVelocity;<br />
``````

public float rollInfluence;

public float engineForce;

Index: src/com/bulletphysics/dynamics/vehicle/RaycastVehicle.java

===================================================================

— src/com/bulletphysics/dynamics/vehicle/RaycastVehicle.java (Revision 607)

+++ src/com/bulletphysics/dynamics/vehicle/RaycastVehicle.java (Arbeitskopie)

@@ -360,6 +360,7 @@

float proj2 = fwd.dot(vel);

wheel.deltaRotation = (proj2 * step) / (wheel.wheelsRadius);

• ``````                           wheel.rotationVelocity = proj2 / wheel.wheelsRadius;<br />
``````

wheel.rotation += wheel.deltaRotation;

}

[/patch]

I then added a method to VehicleWheel that returns this value from the wheelInfo Object:

[patch]

Index: src/jbullet/com/jme3/bullet/objects/VehicleWheel.java

===================================================================

— src/jbullet/com/jme3/bullet/objects/VehicleWheel.java (Revision 6897)

+++ src/jbullet/com/jme3/bullet/objects/VehicleWheel.java (Arbeitskopie)

@@ -336,6 +336,18 @@

return wheelInfo.skidInfo;

}

• /**
• ``````* returns the rotation velocity of the wheel in degrees (radian) per<br />
``````
• ``````* second. &lt;br&gt; The revolutions per minute of the wheel calculate as follows<br />
``````
• ``````* &lt;pre&gt;<br />
``````
• ``````* float rpm = (wheel.getRotationVelocity() * 60f) / FastMath.TWO_PI;<br />
``````
• ``````* &lt;/pre&gt;<br />
``````
• ``````* @return rotation velocity of the wheel<br />
``````
• ``````*/<br />
``````
• public float getRotationVelocity() {
• ``````   return wheelInfo.rotationVelocity;<br />
``````
• }

+

@Override

public void read(JmeImporter im) throws IOException {

InputCapsule capsule = im.getCapsule(this);

[/patch]

The method getRotationVelocity() returns the rotation velocity of the wheel in degrees per second.

The rpm of a VehicleWheel could then be calculated as follows:

[java]

float rpm = (wheel.getRotationVelocity() * 60f) / FastMath.TWO_PI;

[/java]

I hope that adding two lines of code to the jbullet code isn’t inappropriate, since that makes it much easier to calculate the revolutions of a vehicle wheel.

Oh, if it requires changes that are not yet in the native bullet I will not add these to maintain compatibility to the native branch since jme3 bullet will be moved to native bullet at some point. Maybe suggest this over at the http://bulletphysics.org forums?

Ok, before posting a new topic I searched a bit at the bulletphysics forums and luckily someone already asked for the same thing.

http://bulletphysics.org/Bullet/phpBB3/viewtopic.php?f=9&t=4228&start=0

According to the last post the best way to calculate the angular velocity of the wheel would be

[java]

angular velocity = m_deltaRotation / timeStep

[/java]

so a method in VehicleWheel.java could be like

[java]

public float getRotationVelocity() {

return wheelInfo.deltaRotation / timeStep;

}

[/java]

But is it possible at this point to get the physic step rate that is used by the physics world? I don’t know if there is an easy way in the VehicleWheel class to access this property

You can implement PhysicsTickListener to be called each physics step.

Ah that works

Thank you very much,

Niclas