Make wheels spin down slowly once off the ground
This commit is contained in:
parent
1a0537e493
commit
a26a5d741b
3 changed files with 31 additions and 14 deletions
|
@ -20,7 +20,7 @@ Gear::Gear()
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
for(i=0; i<3; i++)
|
for(i=0; i<3; i++)
|
||||||
_pos[i] = _cmpr[i] = 0;
|
_pos[i] = _cmpr[i] = 0;
|
||||||
_spring = 1;
|
_spring = 1;
|
||||||
_damp = 0;
|
_damp = 0;
|
||||||
_sfric = 0.8f;
|
_sfric = 0.8f;
|
||||||
|
@ -48,7 +48,7 @@ Gear::Gear()
|
||||||
_ignoreWhileSolving = 0;
|
_ignoreWhileSolving = 0;
|
||||||
|
|
||||||
for(i=0; i<3; i++)
|
for(i=0; i<3; i++)
|
||||||
_global_ground[i] = _global_vel[i] = 0;
|
_global_ground[i] = _global_vel[i] = 0;
|
||||||
_global_ground[2] = 1;
|
_global_ground[2] = 1;
|
||||||
_global_ground[3] = -1e3;
|
_global_ground[3] = -1e3;
|
||||||
}
|
}
|
||||||
|
@ -181,7 +181,7 @@ void Gear::setGlobalGround(double *global_ground, float* global_vel,
|
||||||
_global_x = globalX;
|
_global_x = globalX;
|
||||||
_global_y = globalY;
|
_global_y = globalY;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Gear::getPosition(float* out)
|
void Gear::getPosition(float* out)
|
||||||
{
|
{
|
||||||
|
@ -192,7 +192,7 @@ void Gear::getPosition(float* out)
|
||||||
void Gear::getCompression(float* out)
|
void Gear::getCompression(float* out)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
for(i=0; i<3; i++) out[i] = _cmpr[i];
|
for(i=0; i<3; i++) out[i] = _cmpr[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
void Gear::getGlobalGround(double* global_ground)
|
void Gear::getGlobalGround(double* global_ground)
|
||||||
|
@ -278,17 +278,29 @@ float Gear::getBumpAltitude()
|
||||||
//values
|
//values
|
||||||
float h = Math::sin(x)+Math::sin(7*x)+Math::sin(8*x)+Math::sin(13*x);
|
float h = Math::sin(x)+Math::sin(7*x)+Math::sin(8*x)+Math::sin(13*x);
|
||||||
h += Math::sin(2*y)+Math::sin(5*y)+Math::sin(9*y*x)+Math::sin(17*y);
|
h += Math::sin(2*y)+Math::sin(5*y)+Math::sin(9*y*x)+Math::sin(17*y);
|
||||||
|
|
||||||
return h*(1/8.)*_ground_bumpiness*maxGroundBumpAmplitude;
|
return h*(1/8.)*_ground_bumpiness*maxGroundBumpAmplitude;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Gear::integrate(float dt)
|
||||||
|
{
|
||||||
|
// Slowly spin down wheel
|
||||||
|
if (_rollSpeed > 0) {
|
||||||
|
// The brake factor of 13.0 * dt was copied from JSBSim's FGLGear.cpp and seems to work reasonably.
|
||||||
|
// If more precise control is needed, then we need wheel mass and diameter parameters.
|
||||||
|
_rollSpeed -= (13.0 * dt + 1300 * _brake * dt);
|
||||||
|
if (_rollSpeed < 0) _rollSpeed = 0;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
void Gear::calcForce(RigidBody* body, State *s, float* v, float* rot)
|
void Gear::calcForce(RigidBody* body, State *s, float* v, float* rot)
|
||||||
{
|
{
|
||||||
// Init the return values
|
// Init the return values
|
||||||
int i;
|
int i;
|
||||||
for(i=0; i<3; i++) _force[i] = _contact[i] = 0;
|
for(i=0; i<3; i++) _force[i] = _contact[i] = 0;
|
||||||
|
|
||||||
// Don't bother if it's not down
|
// Don't bother if gear is retracted
|
||||||
if(_extension < 1)
|
if(_extension < 1)
|
||||||
{
|
{
|
||||||
_wow = 0;
|
_wow = 0;
|
||||||
|
@ -309,7 +321,7 @@ void Gear::calcForce(RigidBody* body, State *s, float* v, float* rot)
|
||||||
// The ground plane transformed to the local frame.
|
// The ground plane transformed to the local frame.
|
||||||
float ground[4];
|
float ground[4];
|
||||||
s->planeGlobalToLocal(_global_ground, ground);
|
s->planeGlobalToLocal(_global_ground, ground);
|
||||||
|
|
||||||
// The velocity of the contact patch transformed to local coordinates.
|
// The velocity of the contact patch transformed to local coordinates.
|
||||||
float glvel[3];
|
float glvel[3];
|
||||||
s->velGlobalToLocal(_global_vel, glvel);
|
s->velGlobalToLocal(_global_vel, glvel);
|
||||||
|
@ -325,12 +337,11 @@ void Gear::calcForce(RigidBody* body, State *s, float* v, float* rot)
|
||||||
}
|
}
|
||||||
_compressDist = -a;
|
_compressDist = -a;
|
||||||
if(a > 0) {
|
if(a > 0) {
|
||||||
_wow = 0;
|
_wow = 0;
|
||||||
_frac = 0;
|
_frac = 0;
|
||||||
_compressDist = 0;
|
_compressDist = 0;
|
||||||
_rollSpeed = 0;
|
|
||||||
_casterAngle = 0;
|
_casterAngle = 0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now a is the distance from the tip to ground, so make b the
|
// Now a is the distance from the tip to ground, so make b the
|
||||||
|
@ -347,7 +358,7 @@ void Gear::calcForce(RigidBody* body, State *s, float* v, float* rot)
|
||||||
else
|
else
|
||||||
_frac = a/(a-b);
|
_frac = a/(a-b);
|
||||||
for(i=0; i<3; i++)
|
for(i=0; i<3; i++)
|
||||||
_contact[i] = _pos[i] + _frac*_cmpr[i];
|
_contact[i] = _pos[i] + _frac*_cmpr[i];
|
||||||
|
|
||||||
// Turn _cmpr into a unit vector and a magnitude
|
// Turn _cmpr into a unit vector and a magnitude
|
||||||
float cmpr[3];
|
float cmpr[3];
|
||||||
|
@ -416,7 +427,7 @@ void Gear::calcForce(RigidBody* body, State *s, float* v, float* rot)
|
||||||
Math::cross3(skid, gup, steer); // skid cross up == steer
|
Math::cross3(skid, gup, steer); // skid cross up == steer
|
||||||
|
|
||||||
if(_rot != 0) {
|
if(_rot != 0) {
|
||||||
// Correct for a rotation
|
// Correct for a rotation
|
||||||
float srot = Math::sin(_rot);
|
float srot = Math::sin(_rot);
|
||||||
float crot = Math::cos(_rot);
|
float crot = Math::cos(_rot);
|
||||||
float tx = steer[0];
|
float tx = steer[0];
|
||||||
|
@ -462,7 +473,7 @@ void Gear::calcForce(RigidBody* body, State *s, float* v, float* rot)
|
||||||
}
|
}
|
||||||
if(vsteer > 0) fsteer = -fsteer;
|
if(vsteer > 0) fsteer = -fsteer;
|
||||||
if(vskid > 0) fskid = -fskid;
|
if(vskid > 0) fskid = -fskid;
|
||||||
|
|
||||||
//reduce friction if wanted by _reduceFrictionByExtension
|
//reduce friction if wanted by _reduceFrictionByExtension
|
||||||
float factor = (1-_frac)*(1-_reduceFrictionByExtension)+_frac*1;
|
float factor = (1-_frac)*(1-_reduceFrictionByExtension)+_frac*1;
|
||||||
factor = Math::clamp(factor,0,1);
|
factor = Math::clamp(factor,0,1);
|
||||||
|
|
|
@ -70,6 +70,7 @@ public:
|
||||||
float getBumpAltitude();
|
float getBumpAltitude();
|
||||||
bool getGroundIsSolid();
|
bool getGroundIsSolid();
|
||||||
float getGroundFrictionFactor() { return (float)_ground_frictionFactor; }
|
float getGroundFrictionFactor() { return (float)_ground_frictionFactor; }
|
||||||
|
void integrate(float dt);
|
||||||
|
|
||||||
// Takes a velocity of the aircraft relative to ground, a rotation
|
// Takes a velocity of the aircraft relative to ground, a rotation
|
||||||
// vector, and a ground plane (all specified in local coordinates)
|
// vector, and a ground plane (all specified in local coordinates)
|
||||||
|
|
|
@ -136,6 +136,11 @@ void Model::initIteration()
|
||||||
_turb->offset(toff);
|
_turb->offset(toff);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for(i=0; i<_gears.size(); i++) {
|
||||||
|
Gear* g = (Gear*)_gears.get(i);
|
||||||
|
g->integrate(_integrator.getInterval());
|
||||||
|
}
|
||||||
|
|
||||||
for(i=0; i<_hitches.size(); i++) {
|
for(i=0; i<_hitches.size(); i++) {
|
||||||
Hitch* h = (Hitch*)_hitches.get(i);
|
Hitch* h = (Hitch*)_hitches.get(i);
|
||||||
h->integrate(_integrator.getInterval());
|
h->integrate(_integrator.getInterval());
|
||||||
|
|
Loading…
Reference in a new issue