doGroundAltitude();
//cerr << " Actual altitude " << altitude << endl;
// Transform();
- pos.setElevationFt(altitude);
+ pos.setElevationFt(altitude_ft);
}
return;
}
}
// adjust altitude (meters) based on current vertical speed (fpm)
- altitude += vs / 60.0 * dt;
- pos.setElevationFt(altitude);
- double altitude_ft = altitude;
+ altitude_ft += vs / 60.0 * dt;
+ pos.setElevationFt(altitude_ft);
// adjust target Altitude, based on ground elevation when on ground
if (no_roll) {
} else {
// find target vertical speed if altitude lock engaged
if (alt_lock && use_perf_vs) {
- if (altitude_ft < tgt_altitude) {
- tgt_vs = tgt_altitude - altitude_ft;
+ if (altitude_ft < tgt_altitude_ft) {
+ tgt_vs = tgt_altitude_ft - altitude_ft;
if (tgt_vs > performance->climb_rate)
tgt_vs = performance->climb_rate;
} else {
- tgt_vs = tgt_altitude - altitude_ft;
+ tgt_vs = tgt_altitude_ft - altitude_ft;
if (tgt_vs < (-performance->descent_rate))
tgt_vs = -performance->descent_rate;
}
}
if (alt_lock && !use_perf_vs) {
- double max_vs = 4*(tgt_altitude - altitude);
+ double max_vs = 4*(tgt_altitude_ft - altitude_ft);
double min_vs = 100;
- if (tgt_altitude < altitude)
+ if (tgt_altitude_ft < altitude_ft)
min_vs = -100.0;
- if ((fabs(tgt_altitude - altitude) < 1500.0)
+ if ((fabs(tgt_altitude_ft - altitude_ft) < 1500.0)
&& (fabs(max_vs) < fabs(tgt_vs)))
tgt_vs = max_vs;
}
-void FGAIAircraft::ClimbTo(double altitude) {
- tgt_altitude = altitude;
+void FGAIAircraft::ClimbTo(double alt_ft ) {
+ tgt_altitude_ft = alt_ft;
alt_lock = true;
}
tgt_vs = (curr->crossat - prev->altitude)
/ (fp->getDistanceToGo(pos.getLatitudeDeg(), pos.getLongitudeDeg(), curr)
/ 6076.0 / prev->speed*60.0);
- tgt_altitude = curr->crossat;
+ tgt_altitude_ft = curr->crossat;
} else {
use_perf_vs = true;
- tgt_altitude = prev->altitude;
+ tgt_altitude_ft = prev->altitude;
}
alt_lock = hdg_lock = true;
no_roll = prev->on_ground;
//cerr << "5.1" << endl;
if (!(prev->on_ground)) { // only update the tgt altitude from flightplan if not on the ground
- tgt_altitude = prev->altitude;
+ tgt_altitude_ft = prev->altitude;
if (curr->crossat > -1000.0) {
//cerr << "5.1a" << endl;
use_perf_vs = false;
- tgt_vs = (curr->crossat - altitude) / (fp->getDistanceToGo(pos.getLatitudeDeg(), pos.getLongitudeDeg(), curr)
+ tgt_vs = (curr->crossat - altitude_ft) / (fp->getDistanceToGo(pos.getLatitudeDeg(), pos.getLongitudeDeg(), curr)
/ 6076.0 / speed*60.0);
//cerr << "5.1b" << endl;
- tgt_altitude = curr->crossat;
+ tgt_altitude_ft = curr->crossat;
} else {
//cerr << "5.1c" << endl;
use_perf_vs = true;
//cerr << "5.1d" << endl;
- //cerr << "Setting target altitude : " <<tgt_altitude << endl;
+ //cerr << "Setting target altitude : " <<tgt_altitude_ft << endl;
}
}
//cerr << "6" << endl;
no_roll = prev->on_ground;
//cout << "Crossing waypoint: " << prev->name << endl;
//cout << " Target speed: " << tgt_speed << endl;
- //cout << " Target altitude: " << tgt_altitude << endl;
+ //cout << " Target altitude: " << tgt_altitude_ft << endl;
//cout << " Target heading: " << tgt_heading << endl << endl;
} else {
// //cerr << "25.1a" << endl;
// use_perf_vs = false;
//
- // tgt_vs = (curr->crossat - altitude)/
+ // tgt_vs = (curr->crossat - altitude_ft)/
// (fp->getDistanceToGo(pos.lat(), pos.lon(), curr)/6076.0/speed*60.0);
// //cerr << "25.1b" << endl;
- // tgt_altitude = curr->crossat;
+ // tgt_altitude_ft = curr->crossat;
//} else {
// //cerr << "25.1c" << endl;
// use_perf_vs = true;
// //cerr << "25.1d" << endl;
- // tgt_altitude = prev->altitude;
- // //cerr << "Setting target altitude : " <<tgt_altitude << endl;
+ // tgt_altitude_ft = prev->altitude;
+ // //cerr << "Setting target altitude : " <<tgt_altitude_ft << endl;
// }
//cerr << "26" << endl;
//tgt_speed = prev->speed;
// FIXME: make sure the pos.lat/pos.lon values are in degrees ...
double alt;
if (globals->get_scenery()->get_elevation_m(pos.getLatitudeDeg(), pos.getLongitudeDeg(), 20000.0, alt, 0))
- tgt_altitude = alt * SG_METER_TO_FEET;
+ tgt_altitude_ft = alt * SG_METER_TO_FEET;
- //cerr << "Target altitude : " << tgt_altitude << endl;
+ //cerr << "Target altitude : " << tgt_altitude_ft << endl;
// if (globals->get_scenery()->get_elevation_m(pos.lat(), pos.lon(),
// 20000.0, alt))
- // tgt_altitude = alt * SG_METER_TO_FEET;
- //cerr << "Target altitude : " << tgt_altitude << endl;
+ // tgt_altitude_ft = alt * SG_METER_TO_FEET;
+ //cerr << "Target altitude : " << tgt_altitude_ft << endl;
}
}
void FGAIAircraft::doGroundAltitude() {
- if (fabs(altitude - (tgt_altitude+groundOffset)) > 1000.0)
- altitude = (tgt_altitude + groundOffset);
+ if (fabs(altitude_ft - (tgt_altitude_ft+groundOffset)) > 1000.0)
+ altitude_ft = (tgt_altitude_ft + groundOffset);
else
- altitude += 0.1 * ((tgt_altitude+groundOffset) - altitude);
+ altitude_ft += 0.1 * ((tgt_altitude_ft+groundOffset) - altitude_ft);
}
vs -= (gravity - buoyancy) * dt;
// adjust altitude (feet)
- altitude += vs * dt;
- pos.setElevationFt(altitude);
+ altitude_ft += vs * dt;
+ pos.setElevationFt(altitude_ft);
// recalculate pitch (velocity vector) if aerostabilized
// cout << "aero_stabilised " << aero_stabilised << endl ;
speed = sqrt( vs * vs + hs * hs);
// set destruction flag if altitude less than sea level -1000
- if (altitude < -1000.0) setDie(true);
+ if (altitude_ft < -1000.0) setDie(true);
} // end Run
_refID( _newAIModelID() ),
_otype(ot)
{
- tgt_heading = hdg = tgt_altitude = tgt_speed = 0.0;
+ tgt_heading = hdg = tgt_altitude_ft = tgt_speed = 0.0;
tgt_roll = roll = tgt_pitch = tgt_yaw = tgt_vs = vs = pitch = 0.0;
bearing = elevation = range = rdot = 0.0;
x_shift = y_shift = rotation = 0.0;
props->setDoubleValue("controls/flight/target-roll", roll);
props->setStringValue("controls/flight/longitude-mode", "alt");
- props->setDoubleValue("controls/flight/target-alt", altitude);
+ props->setDoubleValue("controls/flight/target-alt", altitude_ft);
props->setDoubleValue("controls/flight/target-pitch", pitch);
props->setDoubleValue("controls/flight/target-spd", speed);
if (horiz_offset < -180.0) horiz_offset += 360.0;
// calculate elevation to target
- elevation = atan2( altitude - user_altitude, range_ft ) * SG_RADIANS_TO_DEGREES;
+ elevation = atan2( altitude_ft - user_altitude, range_ft ) * SG_RADIANS_TO_DEGREES;
// calculate look up/down to target
vert_offset = elevation - user_pitch;
x_shift = range * sin( horiz_offset * SG_DEGREES_TO_RADIANS);
rotation = hdg - user_heading;
if (rotation < 0.0) rotation += 360.0;
- ht_diff = altitude - user_altitude;
+ ht_diff = altitude_ft - user_altitude;
}
}
double FGAIBase::_getAltitude() const {
- return altitude;
+ return altitude_ft;
}
void FGAIBase::_setAltitude( double _alt ) {
setAltitude( _alt );
// Calculate rho at altitude, using standard atmosphere
// For the temperature T and the pressure p,
+ double altitude = altitude_ft;
+
if (altitude < 36152) { // curve fits for the troposphere
T = 59 - 0.00356 * altitude;
p = 2116 * pow( ((T + 459.7) / 518.6) , 5.256);
double roll; // degrees, left is negative
double pitch; // degrees, nose-down is negative
double speed; // knots true airspeed
- double altitude; // meters above sea level
+ double altitude_ft; // feet above sea level
double vs; // vertical speed, feet per minute
double turn_radius_ft; // turn radius ft at 15 kts rudder angle 15 degrees
double ft_per_deg_lat;
// these describe the model's desired state
- double tgt_heading; // target heading, degrees true
- double tgt_altitude; // target altitude, *feet* above sea level
- double tgt_speed; // target speed, KTAS
+ double tgt_heading; // target heading, degrees true
+ double tgt_altitude_ft; // target altitude, *feet* above sea level
+ double tgt_speed; // target speed, KTAS
double tgt_roll;
double tgt_pitch;
double tgt_yaw;
hdg = tgt_heading = heading;
}
-inline void FGAIBase::setAltitude( double altitude_ft ) {
- altitude = tgt_altitude = altitude_ft;
- pos.setElevationFt(altitude);
+inline void FGAIBase::setAltitude( double alt_ft ) {
+ altitude_ft = tgt_altitude_ft = alt_ft;
+ pos.setElevationFt(altitude_ft);
}
inline void FGAIBase::setBank( double bank ) {
SGVec3d ecPos;
SGQuatf ecOrient;
+ SGVec3f myVel;
+
if (tInterp <= curentPkgTime) {
// Ok, we need a time prevous to the last available packet,
// that is good ...
MotionInfo::iterator firstIt = mMotionInfo.begin();
ecPos = firstIt->second.position;
ecOrient = firstIt->second.orientation;
+ myVel = firstIt->second.linearVel;
std::vector<FGFloatPropertyData>::const_iterator firstPropIt;
std::vector<FGFloatPropertyData>::const_iterator firstPropItEnd;
ecPos = ((1-tau)*prevIt->second.position + tau*nextIt->second.position);
ecOrient = interpolate((float)tau, prevIt->second.orientation,
nextIt->second.orientation);
+ myVel = ((1-tau)*prevIt->second.linearVel + tau*nextIt->second.linearVel);
if (prevIt->second.properties.size()
== nextIt->second.properties.size()) {
ecOrient = motionInfo.orientation;
SGVec3f linearVel = motionInfo.linearVel;
SGVec3f angularVel = motionInfo.angularVel;
+ myVel = linearVel;
while (0 < t) {
double h = 1e-1;
if (t < h)
ecOrient += h*ecOrient.derivative(angularVel);
linearVel += h*(cross(linearVel, angularVel) + motionInfo.linearAccel);
+ myVel = linearVel;
angularVel += h*motionInfo.angularAccel;
t -= h;
// extract the position
pos = SGGeod::fromCart(ecPos);
-
+ altitude_ft = pos.getElevationFt();
+
+ // estimate speed (we care only about magnitude not direction/frame
+ // of reference here)
+ double vel_ms = sqrt( myVel[0]*myVel[0] + myVel[1]*myVel[1]
+ + myVel[2]*myVel[2] );
+ double vel_kts = vel_ms * SG_METER_TO_NM * 3600.0;
+ speed = vel_kts;
+
// The quaternion rotating from the earth centered frame to the
// horizontal local frame
SGQuatf qEc2Hl = SGQuatf::fromLonLatRad((float)pos.getLongitudeRad(),
range = range_ft / 6076.11549;
if (range < (diameter * 0.5) &&
- user_altitude > (altitude - 1000.0) &&
+ user_altitude > (altitude_ft - 1000.0) &&
user_altitude < height) {
turb_mag_node->setDoubleValue(strength_norm);
turb_rate_node->setDoubleValue(0.5);