1
0
Fork 0

Merge branch 'next' of git://gitorious.org/fg/flightgear into next

This commit is contained in:
Erik Hofman 2011-10-30 13:31:55 +01:00
commit 8f50e24f88
4 changed files with 76 additions and 46 deletions

View file

@ -28,6 +28,7 @@
#include <simgear/debug/logstream.hxx>
#include <simgear/scene/sky/sky.hxx>
#include <simgear/scene/model/particles.hxx>
#include <simgear/structure/event_mgr.hxx>
#include <Main/main.hxx>
#include <Main/fg_props.hxx>
@ -90,7 +91,6 @@ FGEnvironmentMgr::FGEnvironmentMgr () :
_altitude_n(fgGetNode("/position/altitude-ft", true)),
_longitude_n(fgGetNode( "/position/longitude-deg", true )),
_latitude_n( fgGetNode( "/position/latitude-deg", true )),
_positionTimeToLive(0.0),
_3dCloudsEnableListener(new FG3DCloudsListener(fgClouds) )
{
set_subsystem("controller", Environment::LayerInterpolateController::createInstance( fgGetNode("/environment/config", true ) ));
@ -145,6 +145,15 @@ FGEnvironmentMgr::init ()
_altitude_n->setDoubleValue(fgGetDouble("/sim/presets/altitude-ft"));
_longitude_n->setDoubleValue(fgGetDouble("/sim/presets/longitude-deg"));
_latitude_n->setDoubleValue(fgGetDouble("/sim/presets/latitude-deg"));
globals->get_event_mgr()->addTask("updateClosestAirport", this,
&FGEnvironmentMgr::updateClosestAirport, 30 );
}
void
FGEnvironmentMgr::shutdown()
{
globals->get_event_mgr()->removeTask("updateClosestAirport");
}
void
@ -258,33 +267,30 @@ FGEnvironmentMgr::update (double dt)
_latitude_n->getDoubleValue(),
_altitude_n->getDoubleValue()
)));
}
_positionTimeToLive -= dt;
if( _positionTimeToLive <= 0.0 )
void
FGEnvironmentMgr::updateClosestAirport()
{
SG_LOG(SG_ENVIRONMENT, SG_DEBUG, "FGEnvironmentMgr::update: updating closest airport");
SGGeod pos = globals->get_aircraft_position();
FGAirport * nearestAirport = FGAirport::findClosest(pos, 100.0);
if( nearestAirport == NULL )
{
// update closest airport information
_positionTimeToLive = 30.0;
SG_LOG(SG_ENVIRONMENT, SG_INFO, "FGEnvironmentMgr::update: updating closest airport");
SGGeod pos = SGGeod::fromDeg(_longitude_n->getDoubleValue(),
_latitude_n->getDoubleValue());
FGAirport * nearestAirport = FGAirport::findClosest(pos, 100.0);
if( nearestAirport == NULL )
{
SG_LOG(SG_ENVIRONMENT,SG_WARN,"FGEnvironmentMgr::update: No airport within 100NM range");
}
else
{
const string currentId = fgGetString("/sim/airport/closest-airport-id", "");
if (currentId != nearestAirport->ident())
{
fgSetString("/sim/airport/closest-airport-id",
nearestAirport->ident().c_str());
}
}
SG_LOG(SG_ENVIRONMENT,SG_WARN,"FGEnvironmentMgr::update: No airport within 100NM range");
}
else
{
const string currentId = fgGetString("/sim/airport/closest-airport-id", "");
if (currentId != nearestAirport->ident())
{
SG_LOG(SG_ENVIRONMENT, SG_INFO, "FGEnvironmentMgr::updateClosestAirport: selected:" << nearestAirport->ident());
fgSetString("/sim/airport/closest-airport-id",
nearestAirport->ident().c_str());
}
}
}
FGEnvironment

View file

@ -56,6 +56,7 @@ public:
virtual void init ();
virtual void reinit ();
virtual void shutdown ();
virtual void bind ();
virtual void unbind ();
virtual void update (double dt);
@ -74,7 +75,8 @@ public:
virtual FGEnvironment getEnvironment(const SGGeod& aPos) const;
private:
void updateClosestAirport();
double get_cloud_layer_span_m (int index) const;
void set_cloud_layer_span_m (int index, double span_m);
double get_cloud_layer_elevation_ft (int index) const;
@ -98,7 +100,6 @@ private:
SGPropertyNode_ptr _altitude_n;
SGPropertyNode_ptr _longitude_n;
SGPropertyNode_ptr _latitude_n;
double _positionTimeToLive;
simgear::TiedPropertyList _tiedProperties;
SGPropertyChangeListener * _3dCloudsEnableListener;
};

View file

@ -501,7 +501,7 @@ TCAS::AdvisoryCoordinator::update(int mode)
}
/* [TCASII]: "Aural annunciations are inhibited below 500+/-100 feet AGL." */
if ((tcas->threatDetector.getAlt() > 500)&&
if ((tcas->threatDetector.getRadarAlt() > 500)&&
(mode >= SwitchTaOnly))
tcas->annunciator.trigger(current, revertedRA);
else
@ -525,8 +525,10 @@ TCAS::AdvisoryCoordinator::update(int mode)
TCAS::ThreatDetector::ThreatDetector(TCAS* _tcas) :
tcas(_tcas),
checkCount(0),
pAlarmThresholds(&sensitivityLevels[0])
{
self.radarAltFt = 0.0;
unitTest();
}
@ -535,7 +537,8 @@ TCAS::ThreatDetector::init(void)
{
nodeLat = fgGetNode("/position/latitude-deg", true);
nodeLon = fgGetNode("/position/longitude-deg", true);
nodeAlt = fgGetNode("/position/altitude-ft", true);
nodePressureAlt = fgGetNode("/position/altitude-ft", true);
nodeRadarAlt = fgGetNode("/position/altitude-agl-ft", true);
nodeHeading = fgGetNode("/orientation/heading-deg", true);
nodeVelocity = fgGetNode("/velocities/airspeed-kt", true);
nodeVerticalFps = fgGetNode("/velocities/vertical-speed-fps", true);
@ -548,18 +551,30 @@ void
TCAS::ThreatDetector::update(void)
{
// update local position
self.lat = nodeLat->getDoubleValue();
self.lon = nodeLon->getDoubleValue();
self.altFt = nodeAlt->getDoubleValue();
self.heading = nodeHeading->getDoubleValue();
self.velocityKt = nodeVelocity->getDoubleValue();
self.verticalFps = nodeVerticalFps->getDoubleValue();
self.lat = nodeLat->getDoubleValue();
self.lon = nodeLon->getDoubleValue();
self.pressureAltFt = nodePressureAlt->getDoubleValue();
self.heading = nodeHeading->getDoubleValue();
self.velocityKt = nodeVelocity->getDoubleValue();
self.verticalFps = nodeVerticalFps->getDoubleValue();
/* radar altimeter provides a lot of spikes due to uneven terrain
* MK-VIII GPWS-spec requires smoothing the radar altitude with a
* 10second moving average. Likely the TCAS spec requires the same.
* => We use a cheap 10 second exponential average method.
*/
const double SmoothingFactor = 0.3;
self.radarAltFt = nodeRadarAlt->getDoubleValue()*SmoothingFactor +
(1-SmoothingFactor)*self.radarAltFt;
#ifdef FEATURE_TCAS_DEBUG_THREAT_DETECTOR
printf("TCAS::ThreatDetector::update: radarAlt = %f\n",self.radarAltFt);
checkCount = 0;
#endif
// determine current altitude's "Sensitivity Level Definition and Alarm Thresholds"
int sl=0;
for (sl=0;((self.altFt > sensitivityLevels[sl].maxAltitude)&&
for (sl=0;((self.radarAltFt > sensitivityLevels[sl].maxAltitude)&&
(sensitivityLevels[sl].maxAltitude));sl++);
pAlarmThresholds = &sensitivityLevels[sl];
tcas->advisoryGenerator.setAlarmThresholds(pAlarmThresholds);
@ -597,7 +612,9 @@ TCAS::ThreatDetector::checkTransponder(const SGPropertyNode* pModel, float veloc
int
TCAS::ThreatDetector::checkThreat(int mode, const SGPropertyNode* pModel)
{
#ifdef FEATURE_TCAS_DEBUG_THREAT_DETECTOR
checkCount++;
#endif
float velocityKt = pModel->getDoubleValue("velocities/true-airspeed-kt");
@ -606,7 +623,7 @@ TCAS::ThreatDetector::checkThreat(int mode, const SGPropertyNode* pModel)
int threatLevel = ThreatNone;
float altFt = pModel->getDoubleValue("position/altitude-ft");
currentThreat.relativeAltitudeFt = altFt - self.altFt;
currentThreat.relativeAltitudeFt = altFt - self.pressureAltFt;
// save computation time: don't care when relative altitude is excessive
if (fabs(currentThreat.relativeAltitudeFt) > 10000)
@ -638,7 +655,7 @@ TCAS::ThreatDetector::checkThreat(int mode, const SGPropertyNode* pModel)
/* do not detect any threats when in standby or on ground and taxiing */
if ((mode <= SwitchStandby)||
((self.altFt < 360)&&(self.velocityKt < 40)))
((self.radarAltFt < 360)&&(self.velocityKt < 40)))
{
return threatLevel;
}
@ -1032,7 +1049,7 @@ TCAS::AdvisoryGenerator::resolution(int mode, int threatLevel, float rangeNm, fl
/* [EUROACAS]: "Certain RAs are inhibited at altitudes based on inputs from the radio altimeter:
* [..] (c)1000ft (+/- 100ft) and below, all RAs are inhibited;" */
if (pSelf->altFt < 1000)
if (pSelf->radarAltFt < 1000)
threatLevel = ThreatTA;
// RAs only issued in mode "Auto" (= "TA/RA" mode)
@ -1100,7 +1117,7 @@ TCAS::AdvisoryGenerator::resolution(int mode, int threatLevel, float rangeNm, fl
/* [TCASII]: "TCAS is designed to inhibit Increase Descent RAs below 1450 feet AGL; */
/* [TCASII]: "Descend RAs below 1100 feet AGL;" (inhibited) */
if (pSelf->altFt < 1100)
if (pSelf->radarAltFt < 1100)
{
RA &= ~AdvisoryDescend;
//TODO Support "Do not descend" RA
@ -1291,8 +1308,8 @@ TCAS::selfTest(void)
newAdvisory.threatLevel = ThreatRA;
newAdvisory.RA = AdvisoryClear;
newAdvisory.RAOption = OptionNone;
// TCAS audio is disabled below 500ft
threatDetector.setAlt(501);
// TCAS audio is disabled below 500ft AGL
threatDetector.setRadarAlt(501);
// trigger various advisories
switch(selfTestStep)

View file

@ -140,7 +140,8 @@ class TCAS : public SGSubsystem
{
double lat;
double lon;
float altFt;
float pressureAltFt;
float radarAltFt;
float heading;
float velocityKt;
float verticalFps;
@ -324,8 +325,12 @@ class TCAS : public SGSubsystem
void horizontalThreat (float bearing, float distanceNm, float heading,
float velocityKt);
void setAlt (float altFt) { self.altFt = altFt;}
float getAlt (void) { return self.altFt;}
void setPressureAlt (float altFt) { self.pressureAltFt = altFt;}
float getPressureAlt (void) { return self.pressureAltFt;}
void setRadarAlt (float altFt) { self.radarAltFt = altFt;}
float getRadarAlt (void) { return self.radarAltFt;}
float getVelocityKt (void) { return self.velocityKt;}
int getRASense (void) { return currentThreat.RASense;}
@ -340,7 +345,8 @@ class TCAS : public SGSubsystem
SGPropertyNode_ptr nodeLat;
SGPropertyNode_ptr nodeLon;
SGPropertyNode_ptr nodeAlt;
SGPropertyNode_ptr nodePressureAlt;
SGPropertyNode_ptr nodeRadarAlt;
SGPropertyNode_ptr nodeHeading;
SGPropertyNode_ptr nodeVelocity;
SGPropertyNode_ptr nodeVerticalFps;