AI: Fix unit problems for AIBase::vs
It was supposed to be in ft/min, but everything except AIAircraft was using it as ft/sec. Change the name to AIBase::vs_fps and ensure the same unit is used everywhere.
This commit is contained in:
parent
130cd2ae41
commit
9008b3194f
10 changed files with 33 additions and 34 deletions
|
@ -1329,10 +1329,10 @@ void FGAIAircraft::updateActualState(double dt)
|
|||
roll = _performance->actualBankAngle(this, tgt_roll, dt);
|
||||
|
||||
// adjust altitude (meters) based on current vertical speed (fpm)
|
||||
altitude_ft += vs / 60.0 * dt;
|
||||
altitude_ft += vs_fps * dt;
|
||||
pos.setElevationFt(altitude_ft);
|
||||
|
||||
vs = _performance->actualVerticalSpeed(this, tgt_vs, dt);
|
||||
vs_fps = _performance->actualVerticalSpeed(this, tgt_vs, dt) / 60;
|
||||
pitch = _performance->actualPitch(this, tgt_pitch, dt);
|
||||
}
|
||||
|
||||
|
|
|
@ -98,7 +98,7 @@ public:
|
|||
inline double getRoll() const { return roll; };
|
||||
inline double getPitch() const { return pitch; };
|
||||
inline double getAltitude() const { return altitude_ft; };
|
||||
inline double getVerticalSpeed() const { return vs; };
|
||||
inline double getVerticalSpeedFPM() const { return vs_fps * 60; };
|
||||
inline double altitudeAGL() const { return props->getFloatValue("position/altitude-agl-ft");};
|
||||
inline double airspeed() const { return props->getFloatValue("velocities/airspeed-kt");};
|
||||
const std::string& atGate();
|
||||
|
|
|
@ -225,7 +225,7 @@ void FGAIBallistic::bind() {
|
|||
tie("position/global-z",
|
||||
SGRawValueMethods<FGAIBase,double>(*this, &FGAIBase::_getCartPosZ, 0));
|
||||
tie("velocities/vertical-speed-fps",
|
||||
SGRawValuePointer<double>(&vs));
|
||||
SGRawValueMethods<FGAIBase,double>(*this, &FGAIBase::_getVS_fps, &FGAIBase::_setVS_fps));
|
||||
tie("velocities/true-airspeed-kt",
|
||||
SGRawValuePointer<double>(&speed));
|
||||
tie("velocities/horizontal-speed-fps",
|
||||
|
@ -780,8 +780,8 @@ void FGAIBallistic::Run(double dt) {
|
|||
normal_force_lbs = 0;
|
||||
|
||||
pos.setElevationFt(0 + _ground_offset);
|
||||
if (vs < 0)
|
||||
vs = -vs * 0.5;
|
||||
if (vs_fps < 0)
|
||||
vs_fps *= -0.5;
|
||||
|
||||
// Calculate friction. We assume a static coefficient of
|
||||
// friction (mu) of 0.62 (wood on concrete)
|
||||
|
@ -844,10 +844,10 @@ void FGAIBallistic::Run(double dt) {
|
|||
|
||||
// adjust vertical speed for acceleration of gravity, buoyancy, and vertical force
|
||||
double gravity = SG_METER_TO_FEET * (Environment::Gravity::instance()->getGravity(pos));
|
||||
vs -= (gravity - _buoyancy - v_force_acc_fpss - normal_force_fpss) * dt;
|
||||
vs_fps -= (gravity - _buoyancy - v_force_acc_fpss - normal_force_fpss) * dt;
|
||||
|
||||
if (vs <= 0.00001 && vs >= -0.00001)
|
||||
vs = 0;
|
||||
if (vs_fps <= 0.00001 && vs_fps >= -0.00001)
|
||||
vs_fps = 0;
|
||||
|
||||
// set new position
|
||||
if (_slave_load_to_ac) {
|
||||
|
@ -878,19 +878,19 @@ void FGAIBallistic::Run(double dt) {
|
|||
pos.setLongitudeDeg( pos.getLongitudeDeg()
|
||||
+ (speed_east_deg_sec - wind_speed_from_east_deg_sec
|
||||
+ force_speed_east_deg_sec + friction_force_speed_east_deg_sec) * dt );
|
||||
pos.setElevationFt(pos.getElevationFt() + vs * dt);
|
||||
pos.setElevationFt(pos.getElevationFt() + vs_fps * dt);
|
||||
}
|
||||
|
||||
// cout << _name << " run hs " << hs << " vs " << vs << endl;
|
||||
|
||||
// recalculate total speed
|
||||
if ( vs == 0 && hs == 0)
|
||||
if ( vs_fps == 0 && hs == 0)
|
||||
speed = 0;
|
||||
else
|
||||
speed = sqrt( vs * vs + hs * hs) / SG_KT_TO_FPS;
|
||||
speed = sqrt( vs_fps * vs_fps + hs * hs) / SG_KT_TO_FPS;
|
||||
|
||||
// recalculate elevation and azimuth (velocity vectors)
|
||||
_elevation = atan2( vs, hs ) * SG_RADIANS_TO_DEGREES;
|
||||
_elevation = atan2( vs_fps, hs ) * SG_RADIANS_TO_DEGREES;
|
||||
_azimuth = atan2((_speed_east_fps + force_speed_east_fps + friction_force_speed_east_fps),
|
||||
(_speed_north_fps + force_speed_north_fps + friction_force_speed_north_fps))
|
||||
* SG_RADIANS_TO_DEGREES;
|
||||
|
@ -1147,10 +1147,10 @@ void FGAIBallistic::calcVSHS() {
|
|||
double speed_fps = speed * SG_KT_TO_FPS;
|
||||
|
||||
if (speed == 0.0) {
|
||||
hs = vs = 0.0;
|
||||
hs = vs_fps = 0.0;
|
||||
}
|
||||
else {
|
||||
vs = sin( _elevation * SG_DEGREES_TO_RADIANS ) * speed_fps;
|
||||
vs_fps = sin( _elevation * SG_DEGREES_TO_RADIANS ) * speed_fps;
|
||||
hs = cos( _elevation * SG_DEGREES_TO_RADIANS ) * speed_fps;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -136,7 +136,7 @@ FGAIBase::FGAIBase(object_type ot, bool enableHot) :
|
|||
_otype(ot)
|
||||
{
|
||||
tgt_heading = hdg = tgt_altitude_ft = tgt_speed = 0.0;
|
||||
tgt_roll = roll = tgt_pitch = tgt_yaw = tgt_vs = vs = pitch = 0.0;
|
||||
tgt_roll = roll = tgt_pitch = tgt_yaw = tgt_vs = vs_fps = pitch = 0.0;
|
||||
bearing = elevation = range = rdot = 0.0;
|
||||
x_shift = y_shift = rotation = 0.0;
|
||||
in_range = false;
|
||||
|
@ -946,7 +946,7 @@ double FGAIBase::_getRdot() const {
|
|||
}
|
||||
|
||||
double FGAIBase::_getVS_fps() const {
|
||||
return vs/60.0;
|
||||
return vs_fps;
|
||||
}
|
||||
|
||||
double FGAIBase::_get_speed_east_fps() const {
|
||||
|
@ -958,7 +958,7 @@ double FGAIBase::_get_speed_north_fps() const {
|
|||
}
|
||||
|
||||
void FGAIBase::_setVS_fps( double _vs ) {
|
||||
vs = _vs*60.0;
|
||||
vs_fps = _vs;
|
||||
}
|
||||
|
||||
double FGAIBase::_getAltitude() const {
|
||||
|
|
|
@ -192,7 +192,7 @@ protected:
|
|||
double pitch; // degrees, nose-down is negative
|
||||
double speed; // knots true airspeed
|
||||
double altitude_ft; // feet above sea level
|
||||
double vs; // vertical speed, feet per minute
|
||||
double vs_fps; // vertical speed
|
||||
double speed_north_deg_sec;
|
||||
double speed_east_deg_sec;
|
||||
double turn_radius_ft; // turn radius ft at 15 kts rudder angle 15 degrees
|
||||
|
|
|
@ -521,7 +521,7 @@ void FGAIMultiplayer::update(double dt)
|
|||
if (dt < 1.0)
|
||||
Weighting = dt;
|
||||
// simple smoothing over 1 second
|
||||
vs = (1.0-Weighting)*vs + Weighting * (altitude_ft - recent_alt_ft) / dT * 60;
|
||||
vs_fps = (1.0-Weighting)*vs_fps + Weighting * (altitude_ft - recent_alt_ft) / dT * 60;
|
||||
}
|
||||
lastUpdateTime = curtime;
|
||||
|
||||
|
|
|
@ -136,7 +136,7 @@ void FGAIWingman::bind() {
|
|||
(*this, &FGAIBallistic::getElevHitchToUser));
|
||||
|
||||
tie("velocities/vertical-speed-fps",
|
||||
SGRawValuePointer<double>(&vs));
|
||||
SGRawValueMethods<FGAIBase,double>(*this, &FGAIBase::_getVS_fps, &FGAIBase::_setVS_fps));
|
||||
tie("velocities/true-airspeed-kt",
|
||||
SGRawValuePointer<double>(&speed));
|
||||
tie("velocities/speed-east-fps",
|
||||
|
@ -475,9 +475,9 @@ void FGAIWingman::Run(double dt) {
|
|||
|
||||
// calculate vertical and horizontal speed components
|
||||
if (speed == 0.0) {
|
||||
hs = vs = 0.0;
|
||||
hs = vs_fps = 0.0;
|
||||
} else {
|
||||
vs = sin( pitch * SG_DEGREES_TO_RADIANS ) * speed_fps;
|
||||
vs_fps = sin( pitch * SG_DEGREES_TO_RADIANS ) * speed_fps;
|
||||
hs = cos( pitch * SG_DEGREES_TO_RADIANS ) * speed_fps;
|
||||
}
|
||||
|
||||
|
@ -506,8 +506,8 @@ void FGAIWingman::Run(double dt) {
|
|||
if (hs <= 0.00001)
|
||||
hs = 0;
|
||||
|
||||
if (vs <= 0.00001 && vs >= -0.00001)
|
||||
vs = 0;
|
||||
if (vs_fps <= 0.00001 && vs_fps >= -0.00001)
|
||||
vs_fps = 0;
|
||||
|
||||
//cout << "lat " << pos.getLatitudeDeg()<< endl;
|
||||
// set new position
|
||||
|
@ -515,18 +515,18 @@ void FGAIWingman::Run(double dt) {
|
|||
+ (speed_north_deg_sec - wind_speed_from_north_deg_sec) * dt );
|
||||
pos.setLongitudeDeg( pos.getLongitudeDeg()
|
||||
+ (speed_east_deg_sec - wind_speed_from_east_deg_sec ) * dt );
|
||||
pos.setElevationFt(pos.getElevationFt() + vs * dt);
|
||||
pos.setElevationFt(pos.getElevationFt() + vs_fps * dt);
|
||||
|
||||
//cout << _name << " run hs " << hs << " vs " << vs << endl;
|
||||
|
||||
// recalculate total speed
|
||||
if ( vs == 0 && hs == 0)
|
||||
if ( vs_fps == 0 && hs == 0)
|
||||
speed = 0;
|
||||
else
|
||||
speed = sqrt( vs * vs + hs * hs) / SG_KT_TO_FPS;
|
||||
speed = sqrt( vs_fps * vs_fps + hs * hs) / SG_KT_TO_FPS;
|
||||
|
||||
// recalculate elevation and azimuth (velocity vectors)
|
||||
pitch = atan2( vs, hs ) * SG_RADIANS_TO_DEGREES;
|
||||
pitch = atan2( vs_fps, hs ) * SG_RADIANS_TO_DEGREES;
|
||||
hdg = atan2((speed_east_fps),(speed_north_fps))* SG_RADIANS_TO_DEGREES;
|
||||
|
||||
// rationalise heading
|
||||
|
|
|
@ -188,11 +188,11 @@ double PerformanceData::actualAltitude(FGAIAircraft* ac, double tgt_altitude, do
|
|||
//FIXME: a return sensible value here
|
||||
return 0.0; // 0 for now to avoid compiler errors
|
||||
} else
|
||||
return ac->getAltitude() + ac->getVerticalSpeed()*dt/60.0;
|
||||
return ac->getAltitude() + ac->getVerticalSpeedFPM()*dt/60.0;
|
||||
}
|
||||
|
||||
double PerformanceData::actualVerticalSpeed(FGAIAircraft* ac, double tgt_vs, double dt) {
|
||||
double vs = ac->getVerticalSpeed();
|
||||
double vs = ac->getVerticalSpeedFPM();
|
||||
double vs_diff = tgt_vs - vs;
|
||||
|
||||
if (fabs(vs_diff) > .001) {
|
||||
|
|
|
@ -64,7 +64,7 @@ void AIWakeGroup::AddAI(FGAIAircraft* ai)
|
|||
ai->getPitch(), 0.0);
|
||||
|
||||
double hVel = ai->getSpeed()*SG_KT_TO_FPS;
|
||||
double vVel = ai->getVerticalSpeed()/60;
|
||||
double vVel = ai->getVerticalSpeedFPM()/60;
|
||||
double gamma = atan2(vVel, hVel);
|
||||
double vel = sqrt(hVel*hVel + vVel*vVel);
|
||||
double weight = perfData->weight();
|
||||
|
|
|
@ -254,7 +254,6 @@ void SubmodelsTests::testInitialState()
|
|||
* speed
|
||||
+ speed_east,
|
||||
sm->_get_speed_east_fps(), 0.1);
|
||||
// In AIBase, attribute 'vs' is in fpm, but AIBallistic uses it as fps?!
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL(sin((pitch + pitch_offset) * SG_DEGREES_TO_RADIANS) * speed,
|
||||
sm->_getVS_fps() * 60, 0.1);
|
||||
sm->_getVS_fps(), 0.1);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue