1
0
Fork 0

Make wheels spin down slowly once off the ground

This commit is contained in:
Viktor Radnai 2016-12-24 04:09:45 +00:00 committed by James Turner
parent 1a0537e493
commit a26a5d741b
3 changed files with 31 additions and 14 deletions

View file

@ -20,7 +20,7 @@ Gear::Gear()
{
int i;
for(i=0; i<3; i++)
_pos[i] = _cmpr[i] = 0;
_pos[i] = _cmpr[i] = 0;
_spring = 1;
_damp = 0;
_sfric = 0.8f;
@ -48,7 +48,7 @@ Gear::Gear()
_ignoreWhileSolving = 0;
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[3] = -1e3;
}
@ -181,7 +181,7 @@ void Gear::setGlobalGround(double *global_ground, float* global_vel,
_global_x = globalX;
_global_y = globalY;
}
}
void Gear::getPosition(float* out)
{
@ -282,13 +282,25 @@ float Gear::getBumpAltitude()
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)
{
// Init the return values
int i;
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)
{
_wow = 0;
@ -325,12 +337,11 @@ void Gear::calcForce(RigidBody* body, State *s, float* v, float* rot)
}
_compressDist = -a;
if(a > 0) {
_wow = 0;
_frac = 0;
_wow = 0;
_frac = 0;
_compressDist = 0;
_rollSpeed = 0;
_casterAngle = 0;
return;
return;
}
// 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
_frac = a/(a-b);
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
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
if(_rot != 0) {
// Correct for a rotation
// Correct for a rotation
float srot = Math::sin(_rot);
float crot = Math::cos(_rot);
float tx = steer[0];

View file

@ -70,6 +70,7 @@ public:
float getBumpAltitude();
bool getGroundIsSolid();
float getGroundFrictionFactor() { return (float)_ground_frictionFactor; }
void integrate(float dt);
// Takes a velocity of the aircraft relative to ground, a rotation
// vector, and a ground plane (all specified in local coordinates)

View file

@ -136,6 +136,11 @@ void Model::initIteration()
_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++) {
Hitch* h = (Hitch*)_hitches.get(i);
h->integrate(_integrator.getInterval());