Moderator: Alain
Julio Jerez
The wheel are so big and heavy than when turning the distance that a wheel in one side of the axel travel in very different that the distance that the wheel in the other side travel, that is why they react funny when turning.
class CustomMultiBodyTire;
#define MULTI_BODY_VEHICLE_MAX_TIRES 16
class JOINTLIBRARY_API CustomMultiBodyVehicle: public NewtonCustomJoint
{
public:
CustomMultiBodyVehicle(const dMatrix& chassisMatrix, const NewtonBody* carBody);
virtual ~CustomMultiBodyVehicle(void);
void AddSingleSuspensionTire (void* userData, const dVector& localPosition,
dFloat mass, dFloat radius, dFloat with,
dFloat suspensionLength, dFloat springConst, dFloat springDamper);
int GetTiresCount() const ;
const NewtonBody* GetTireBody(int tireIndex) const;
dFloat GetSpeed() const;
virtual void SetTorque (dFloat torque);
virtual void SetSteering (dFloat angle);
protected:
virtual void SubmitConstrainst (dFloat timestep);
virtual void GetInfo (NewtonJointRecord* info) const;
int m_tiresCount;
CustomMultiBodyTire* m_tires[MULTI_BODY_VEHICLE_MAX_TIRES];
dMatrix m_localFrame;
};
#define MIN_JOINT_PIN_LENGTH 50.0f
class CustomMultiBodyTire: public NewtonCustomJoint
{
public:
CustomMultiBodyTire(const NewtonBody* hubBody, const NewtonBody* tire)
:NewtonCustomJoint(5, hubBody, tire)
{
dMatrix pinAndPivotFrame;
NewtonBodyGetMatrix(tire, &pinAndPivotFrame[0][0]);
CalculateLocalMatrix (pinAndPivotFrame, m_localMatrix0, m_localMatrix1);
}
~CustomMultiBodyTire(void)
{
}
void GetInfo (NewtonJointRecord* info) const
{
}
void SubmitConstrainst (dFloat timestep)
{
dMatrix matrix0;
dMatrix matrix1;
// calculate the position of the pivot point and the Jacobian direction vectors, in global space.
CalculateGlobalMatrix (m_localMatrix0, m_localMatrix1, matrix0, matrix1);
// Restrict the movement on the pivot point along all tree orthonormal direction
NewtonUserJointAddLinearRow (m_joint, &matrix0.m_posit[0], &matrix1.m_posit[0], &matrix0.m_front[0]);
NewtonUserJointAddLinearRow (m_joint, &matrix0.m_posit[0], &matrix1.m_posit[0], &matrix0.m_up[0]);
NewtonUserJointAddLinearRow (m_joint, &matrix0.m_posit[0], &matrix1.m_posit[0], &matrix0.m_right[0]);
// get a point along the pin axis at some reasonable large distance from the pivot
dVector q0 (matrix0.m_posit + matrix0.m_front.Scale(MIN_JOINT_PIN_LENGTH));
dVector q1 (matrix1.m_posit + matrix1.m_front.Scale(MIN_JOINT_PIN_LENGTH));
// two constraints row perpendicular to the pin vector
NewtonUserJointAddLinearRow (m_joint, &q0[0], &q1[0], &matrix0.m_up[0]);
NewtonUserJointAddLinearRow (m_joint, &q0[0], &q1[0], &matrix0.m_right[0]);
}
dMatrix m_localMatrix0;
dMatrix m_localMatrix1;
};
CustomMultiBodyVehicle::CustomMultiBodyVehicle(const dMatrix& cordenateSytem, const NewtonBody* carBody)
:NewtonCustomJoint(3, carBody, NULL)
{
dMatrix tmp;
dVector com;
m_tiresCount = 0;
NewtonBodyGetCentreOfMass(m_body0, &com[0]);
com.m_w = 1.0f;
// set the joint reference point at the center of mass of the body
dMatrix chassisMatrix (cordenateSytem);
chassisMatrix.m_posit += chassisMatrix.RotateVector(com);
CalculateLocalMatrix (chassisMatrix, m_localFrame, tmp);
}
CustomMultiBodyVehicle::~CustomMultiBodyVehicle(void)
{
// the joint do not need to be destroyed because the joint destructor takes care of that
m_tiresCount = 0;
}
void CustomMultiBodyVehicle::SubmitConstrainst (dFloat timestep)
{
}
void CustomMultiBodyVehicle::GetInfo (NewtonJointRecord* info) const
{
}
void CustomMultiBodyVehicle::SetTorque (dFloat torque)
{
}
void CustomMultiBodyVehicle::SetSteering (dFloat angle)
{
}
int CustomMultiBodyVehicle::GetTiresCount() const
{
return m_tiresCount;
}
const NewtonBody* CustomMultiBodyVehicle::GetTireBody(int tireIndex) const
{
return m_tires[tireIndex]->GetBody1();
}
void CustomMultiBodyVehicle::AddSingleSuspensionTire (
void* userData,
const dVector& localPosition,
dFloat mass,
dFloat radius,
dFloat width,
dFloat suspensionLength,
dFloat springConst,
dFloat springDamper)
{
dFloat Ixx;
dFloat Iyy;
dFloat Izz;
dMatrix carMatrix;
NewtonBody* tire;
NewtonWorld* world;
NewtonCollision *collision;
world = NewtonBodyGetWorld(GetBody0());
// create the tire RogidBody
collision = NewtonCreateChamferCylinder(world, radius, width, NULL);
//create the rigid body
tire = NewtonCreateBody (world, collision);
// release the collision
NewtonReleaseCollision (world, collision);
// save the user data
NewtonBodySetUserData (tire, userData);
// set the material group id for vehicle
NewtonBodySetMaterialGroupID (tire, 0);
// NewtonBodySetMaterialGroupID (tire, woodID);
// set the force and torque call back function
NewtonBodySetForceAndTorqueCallback (tire, NewtonBodyGetForceAndTorqueCallback (GetBody0()));
// body part do not collision
NewtonBodySetJointRecursiveCollision (tire, 0);
// calculate the moment of inertia and the relative center of mass of the solid
dVector origin;
dVector inertia;
NewtonConvexCollisionCalculateInertialMatrix (collision, &inertia[0], &origin[0]);
Ixx = mass * inertia[0];
Iyy = mass * inertia[1];
Izz = mass * inertia[2];
// set the mass matrix
NewtonBodySetMassMatrix (tire, mass, Ixx, Iyy, Izz);
// calculate the tire local base pose matrix
dMatrix tireMatrix;
tireMatrix.m_front = m_localFrame.m_right;
tireMatrix.m_up = m_localFrame.m_up;
tireMatrix.m_right = tireMatrix.m_front * tireMatrix.m_up;
tireMatrix.m_posit = localPosition;
NewtonBodyGetMatrix(GetBody0(), &carMatrix[0][0]);
tireMatrix = tireMatrix * carMatrix;
// set the matrix for both the rigid body and the graphic body
NewtonBodySetMatrix (tire, &tireMatrix[0][0]);
m_tires[m_tiresCount] = new CustomMultiBodyTire (GetBody0(), tire);
m_tiresCount ++;
}
k00m wrote:I'm able to make the front wheels more solide with solver 1.
In my test I have remove the steer angular row and I have cheat with apply omega value directly.
k00m wrote:the problem the rear wheels coming wrong and it is not able to follow and stay at good position.
When the vehicle turn the rear wheel get big angular error.
Users browsing this forum: No registered users and 2 guests