D6Joint frames

mephisto

07-03-2011 16:56:17

I am working on a vehicle controller using D6Joint as link between wheel ( CapsuleShape ) and chassis ( BoxShape ). I have limited the joint to 3 DOFs :

- swing1motion = free, to rotate wheels.

- swing2motion= free, to turn wheels.

( those two swings are inverted because initialy the capsule shape Height is perpendicular to axis X, so I rotate the capsule around the X axis 90 degrees);

- zMotion - spring damper. ( also z instead y because of capsule rotation );

Joints are fixed at the center of wheels.

Spring damper and rotations works OK. But I am having problem with direction : the problem is that when the wheel rotates and I want to change direction the wheel turns around his local axis and considering that his local axis is changing with rotation..the behaviour is odd. The objective is to make the wheel change direction around a global axis. I tried SlerpDrive it works but only with 3 angular DOF free.


Thanks.

mephisto

08-03-2011 21:10:58

Betajaen, you was right. I have spent a lot of time by searching the problem and i failed. Although that in the docs its clearly said that joints transformations are done by taking reference of the body[ 0 ] ( chassis ).

My conclusion is that its better to dont try something complicated if you are not a PRO :D

But I am having a question : if i use spherical joint and wheelshape, will the wheelShape's spring damper system work with sphere joint? Or i need to use D6joint and make my own spring damper system?

Thanks

betajaen

08-03-2011 21:17:39

Which is why I leave the D6 joint well alone. ;)

You don't use any joints with the WheelShapes, you just attach them normally to your car chassis Actor like any other shape. But if you really really want an Actor per wheel, I honestly don't know. I do know that the WheelShape has a suspension/spring system, so I'd try that first.

mephisto

08-03-2011 21:27:56

Oh, I want 1 actor per wheel just because in some tutorial I have read that there is no way for now to render the wheel. But if you say this , I am wrong.

betajaen

08-03-2011 21:31:26

You are. It's very easy to render wheels in NxOgre. We have a class called Machine that does it for you.

mephisto

08-03-2011 22:16:40

I have just tried d6joint with wheel shape and it didnt work. The wheelshape simply doesnt interact with the world ( certainly because it have additional tune to make it work as one shape pere body ).
But I tried with spheres and I am satisfied from the result, I obtained some drifts :D ( the behaviour isnt same as with capsule ). I will try the sphere-joint system before definitely resign myself with use of WheelShape system :D

betajaen

08-03-2011 22:23:02

No, it wouldn't of. The WheelShape needs another Shape attached with it, for a physical presence.

mephisto

13-03-2011 22:41:40

I have finally resigned myself with joints. I have seen your machine classes and they look like very good. I am having a questions about :
- a vehicle should inherit the Machine class.?

- a wheel should inherit the MachinePart.?

( The question is more about the method, the "getting started" )
Should I firt create a multiShape car ( with wheelShape ) and then use machine functions ( createWheelPart, etc.. ) . RotatorMachinePart and MoverMachinePart should be created for each wheel if yes how I link them with wheelpart?

mephisto

15-03-2011 07:03:06

I am having a precise question :
My class Vehicle inherits from Machine ... then to create a WheelMachinePart I need a "PointRenderable". How to create the PointRenderable?

betajaen

15-03-2011 08:07:30

In Critter.

mephisto

15-03-2011 12:02:40

Oh ok cheers, PointRenderable is a helper class , my "graphic wheel" should inherit the PointRenderable class.

betajaen

15-03-2011 14:27:38

Let me see if I can dig up some code for you.

mephisto

15-03-2011 18:11:26

I hope I am on a right way... :


#ifndef __MACHINE_VEHICLE_H__
#define __MACHINE_VEHICLE_H__

#include "MachineWheel.h"
#include <Critter.h>

class MachineVehicle : public NxOgre::Machine
{

Critter::Body* m_Chassis;
NxOgre::ShapeDescriptions m_ShapesDsc;
NxOgre::BoxDescription m_ChassisShapeDsc;
Critter::BodyDescription m_ChassisBodyDsc;
Ogre::SceneNode* m_ChassisNode;
NxOgre::Vec3 m_LocalPos[4];

MachineWheel m_Wheel[ 4 ];

WheelRender m_WheelRender[ 4 ];

public :

MachineVehicle( NxOgre::Scene* _scene, Critter::RenderSystem* _render, NxOgre::Vec3& _size )
{

m_LocalPos[ 0 ] = NxOgre::Vec3( _size.x, _size.y, _size.z );
m_LocalPos[ 1 ] = NxOgre::Vec3( -_size.x, _size.y, _size.z );
m_LocalPos[ 2 ] = NxOgre::Vec3( _size.x, _size.y, -_size.z );
m_LocalPos[ 3 ] = NxOgre::Vec3( -_size.x, _size.y, -_size.z );

m_ChassisShapeDsc.mSize = _size;
m_ChassisShapeDsc.mId = 4;
m_ChassisShapeDsc.mMass = 1000.0f;
m_ChassisBodyDsc.mMass = 500.0f;
m_ChassisBodyDsc.mWakeUpCounter = 1E8;
m_ChassisBodyDsc.mMassLocalPose = NxOgre::Vec3( 0.0f, -_size.y / 2.0f, 0.0f );


for( int i = 0; i < 4; i++ )
{
m_Wheel[ i ].m_WheelDsc.mLocalPose = m_LocalPos[ i ];
m_Wheel[ i ].m_WheelDsc.mMass = 3.0f;
m_Wheel[ i ].m_WheelDsc.mBrakeTorque = 10.0f;
m_Wheel[ i ].m_WheelDsc.mId = i;
m_Wheel[ i ].m_WheelDsc.mWheelFlags |= NxOgre::Enums::WheelFlags_AxleSpeedOverride;
m_Wheel[ i ].m_WheelDsc.mLongitudalTireFunction.mStiffnessFactor = 10000.0f;

m_ShapesDsc.push_back( &m_Wheel[ i ].m_WheelDsc );

}

m_Chassis = _render->createBody( m_ShapesDsc, NxOgre::Vec3( 0.0f, 2.0f, 0.0f ), m_ChassisBodyDsc );
m_ChassisNode = m_Chassis->getNode()->getSceneNode();

Ogre::Vector3 pos[4];

for( int i = 0; i < 4; i++ )
{

pos[ i ].x = m_LocalPos[ i ].x;
pos[ i ].y = m_LocalPos[ i ].y;
pos[ i ].z = m_LocalPos[ i ].z;

m_Wheel[ i ].m_Wheel = static_cast< NxOgre::Wheel* >( m_Chassis->getShapeById( i ) );

m_WheelRender[ i ].create( m_Chassis->getNode(), Ogre::String("wheel"+i), i, pos[ i ] );

}

}

void drive( NxOgre::Vec3& _vec3 )
{

for( int i = 0; i < 4; i++ )
{

m_Wheel[ i ].m_Wheel->setAxleSpeed( _vec3.z );

m_Wheel[ i ].m_Wheel->setMotorTorque( 10.0f );

}

}

void steer( NxOgre::Vec3 _vec3 )
{

for( int i=0; i<2; i++)
m_Wheel[ i ].m_Wheel->setSteeringAngle( NxOgre::Radian( _vec3.y ) );

}

};

#endif //__MACHINE_VEHICLE_H__

mephisto

15-03-2011 18:12:19

#ifndef __MACHINE_WHEEL_H__
#define __MACHINE_WHEEL_H__


class MachineWheel : public NxOgre::MachinePart
{

public :

NxOgre::Wheel* m_Wheel;
NxOgre::WheelDescription m_WheelDsc;

// should I make my own render and simulate , and why render if we have PointRenderable ?

};



class WheelRender : public NxOgre::PointRenderable
{

public :

Ogre::SceneNode* m_WheelSceneNode;
Ogre::Entity* m_WheelEntity;
Critter::Node* m_Node;


void create( Critter::Node* _node, Ogre::String& _name, int _id, Ogre::Vector3& _pos )
{

m_WheelEntity = _node->getSceneNode()->getCreator()->createEntity( _name, "ellipsoid.mesh" );

m_WheelSceneNode = _node->getSceneNode()->createChildSceneNode(
_pos,
_node->getSceneNode()->getOrientation() );

m_WheelSceneNode->attachObject( m_WheelEntity );


}

void render( const NxOgre::Vec3& _vec3, const NxOgre::Quat& _quat )
{

// fail ! how to create a Node ?
m_Node->setPose( _vec3, _quat );

}

};

#endif //__MACHINE_WHEEL_H__

mephisto

24-04-2011 17:47:16

WheelShape use : Does somebody know how to get instant suspension travel or something like this. I need to update graphicWheel position.
getLocalPositon return the localPosition attached to the rigidBody. ( chassis )

mephisto

24-04-2011 18:51:21

Problem resolved, there is a structure that keeps rayCastInfo called NxWheelContactData :


void ShapeVehicleWheel::updateGraphicSuspension()
{

static Ogre::Vector3 vector3;

vector3 = m_Wheel->getLocalPose().translation_as< Ogre::Vector3 >();

static NxWheelContactData contact_data;

m_Wheel->getWheelShape()->getContact( contact_data );

vector3.y = -contact_data.contactPosition;

m_ChildSceneNode->setPosition( vector3 );

}

mephisto

07-05-2011 15:23:08

does somebody know how to correctly update graphic wheel spin? I use the function getAxleSpeed() but my wheel graphic wheel rotates faster that the wheel shape. I have took this code from an example. May be, the velocity can also be update by getting the linearVelocity of the rigid body, but things like drifts will be locked.

rotDist = m_Wheel->getAxleSpeed() * diff;

rotAngleRAD += rotDist;

if ( rotAngleRAD > Ogre::Math::PI * 2 )
rotAngleRAD -= Ogre::Math::PI * 2;
else if ( rotAngleRAD < -Ogre::Math::PI * 2 )
rotAngleRAD += Ogre::Math::PI * 2;

steerAngle = m_Wheel->getSteeringAngle();

x.FromEulerAnglesXYZ( Ogre::Radian( rotAngleRAD ),
Ogre::Radian(),
Ogre::Radian() );

z.FromEulerAnglesXYZ( Ogre::Radian(),
Ogre::Radian( steerAngle ),
Ogre::Radian() );

x = z * x;

y.FromRotationMatrix( x );

m_ChildSceneNode->setOrientation( y );

mephisto

07-05-2011 15:45:01

FIXED, I have found solution loocking on wikipedia . getAxleSpeed() - returns angular speed. We need to convert it to rotational speed :
( rotSpeed = angularSpeed / twoPi )

rotDist = m_Wheel->getAxleSpeed() * diff / NxOgre::Math::TwoPi;

rotAngleRAD += rotDist;