1 // tcas.hxx -- Traffic Alert and Collision Avoidance System (TCAS)
3 // Written by Thorsten Brehm, started December 2010.
5 // Copyright (C) 2010 Thorsten Brehm - brehmt (at) gmail com
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
21 #ifndef __INSTRUMENTS_TCAS_HXX
22 #define __INSTRUMENTS_TCAS_HXX
30 #include <simgear/props/props.hxx>
31 #include <simgear/structure/subsystem_mgr.hxx>
32 #include <Sound/voiceplayer.hxx>
40 #include <Main/globals.hxx>
43 # pragma warning( push )
44 # pragma warning( disable: 4355 )
47 ///////////////////////////////////////////////////////////////////////////////
48 // TCAS //////////////////////////////////////////////////////////////////////
49 ///////////////////////////////////////////////////////////////////////////////
51 class TCAS : public SGSubsystem
56 AdvisoryClear = 0, /*< Clear of traffic */
57 AdvisoryIntrusion = 1, /*< Intrusion flag */
58 AdvisoryClimb = AdvisoryIntrusion|(1 << 1), /*< RA climb */
59 AdvisoryDescend = AdvisoryIntrusion|(1 << 2), /*< RA descend */
60 AdvisoryAdjustVSpeed = AdvisoryIntrusion|(1 << 3), /*< RA adjust vertical speed (TCAS II 7.0 only) */
61 AdvisoryMaintVSpeed = AdvisoryIntrusion|(1 << 4), /*< RA maintain vertical speed */
62 AdvisoryMonitorVSpeed = AdvisoryIntrusion|(1 << 5), /*< RA monitor vertical speed */
63 AdvisoryLevelOff = AdvisoryIntrusion|(1 << 6) /*< RA level off (TCAS II 7.1 only) */
68 OptionNone = 0, /*< no option modifier */
69 OptionIncreaseClimb = (1 << 0), /*< increase climb */
70 OptionIncreaseDescend = (1 << 1), /*< increase descend */
71 OptionCrossingClimb = (1 << 2), /*< crossing climb */
72 OptionCrossingDescent = (1 << 3) /*< crossing descent */
77 SwitchOff = 0, /*< TCAS switched off */
78 SwitchStandby = 1, /*< TCAS standby (no TA/RA) */
79 SwitchTaOnly = 2, /*< TCAS in TA-only mode (no RA) */
80 SwitchAuto = 3 /*< TCAS in TA/RA mode */
85 ThreatInvisible = -1,/*< Traffic is invisible to TCAS (i.e. no transponder) */
86 ThreatNone = 0, /*< Traffic is visible but no threat. */
87 ThreatProximity = 1, /*< Proximity intruder traffic (no threat). */
88 ThreatTA = 2, /*< TA-level threat traffic. */
89 ThreatRA = 3 /*< RA-level threat traffic. */
94 int threatLevel; /*< intruder threat level: 0=clear, 1=proximity,
95 2=intruder, 3=proximity intruder */
96 int RA; /*< resolution advisory */
97 int RAOption; /*< option flags for advisory */
102 float Tau; /*< vertical/horizontal protection range in seconds */
103 float DMOD; /*< horizontal protection range in nm */
104 float ALIM; /*< vertical protection range in ft */
109 double maxAltitude; /*< max altitude for this sensitivity level */
110 int sl; /*< sensitivity level */
111 Thresholds TA; /*< thresholds for TA-level threats */
112 Thresholds RA; /*< thresholds for RA-level threats */
125 float relativeAltitudeFt;
137 typedef map<string,TrackerTarget*> TrackerTargets;
148 } LocalInfo; /*< info structure for local aircraft */
150 /////////////////////////////////////////////////////////////////////////////
151 // TCAS::PropertiesHandler ///////////////////////////////////////////////
152 /////////////////////////////////////////////////////////////////////////////
154 class PropertiesHandler : public FGVoicePlayer::PropertiesHandler
159 PropertiesHandler (TCAS *device) :
160 FGVoicePlayer::PropertiesHandler(), tcas(device) {}
162 PropertiesHandler (void) : FGVoicePlayer::PropertiesHandler() {}
165 /////////////////////////////////////////////////////////////////////////////
166 // TCAS::VoicePlayer ////////////////////////////////////////////////////////
167 /////////////////////////////////////////////////////////////////////////////
173 VoicePlayer (TCAS* tcas) :
174 FGVoicePlayer(&tcas->properties_handler, "tcas") {}
176 ~VoicePlayer (void) {}
182 Voice* pTrafficTraffic;
185 Voice* pClimbCrossing;
186 Voice* pClimbIncrease;
189 Voice* pDescendCrossing;
190 Voice* pDescendIncrease;
192 Voice* pAdjustVSpeed;
194 Voice* pMonitorVSpeed;
200 SGPropertyNode_ptr nodeSoundFilePrefix;
203 /////////////////////////////////////////////////////////////////////////////
204 // TCAS::Annunciator ////////////////////////////////////////////////////////
205 /////////////////////////////////////////////////////////////////////////////
210 Annunciator (TCAS* tcas);
211 ~Annunciator (void) {}
212 void bind (SGPropertyNode* node);
216 void trigger (const ResolutionAdvisory& newAdvisory, bool revertedRA);
217 void test (bool testOk);
219 bool isPlaying (void) { return voicePlayer.is_playing();}
223 ResolutionAdvisory previous;
224 FGVoicePlayer::Voice* pLastVoice;
225 VoicePlayer voicePlayer;
226 SGPropertyNode_ptr nodeGpwsAlertOn;
229 /////////////////////////////////////////////////////////////////////////////
230 // TCAS::AdvisoryCoordinator ////////////////////////////////////////////////
231 /////////////////////////////////////////////////////////////////////////////
233 class AdvisoryCoordinator
236 AdvisoryCoordinator (TCAS* _tcas);
237 ~AdvisoryCoordinator (void) {}
239 void bind (SGPropertyNode* node);
241 void update (int mode);
244 void add (const ResolutionAdvisory& newAdvisory);
249 ResolutionAdvisory current;
250 ResolutionAdvisory previous;
251 SGPropertyNode_ptr nodeTAWarning;
254 /////////////////////////////////////////////////////////////////////////////
255 // TCAS::Tracker ////////////////////////////////////////////////////////////
256 /////////////////////////////////////////////////////////////////////////////
261 Tracker (TCAS* _tcas);
266 void add (const string callsign, int detectedLevel);
267 bool active (void) { return haveTargets;}
268 bool newTraffic (void) { return newTargets;}
269 bool isTracked (string callsign) { if (!haveTargets) return false;else return _isTracked(callsign);}
270 bool _isTracked (string callsign);
271 int getThreatLevel (string callsign);
278 TrackerTargets targets;
281 /////////////////////////////////////////////////////////////////////////////
282 // TCAS::AdvisoryGenerator //////////////////////////////////////////////////
283 /////////////////////////////////////////////////////////////////////////////
285 class AdvisoryGenerator
288 AdvisoryGenerator (TCAS* _tcas);
289 ~AdvisoryGenerator (void) {}
291 void init (const LocalInfo* _pSelf, ThreatInfo* _pCurrentThreat);
293 void setAlarmThresholds (const SensitivityLevel* _pAlarmThresholds);
295 int resolution (int mode, int threatLevel, float distanceNm,
296 float altFt, float heading, float velocityKt);
299 float verticalSeparation (float newVerticalFps);
300 void determineRAsense (int& RASense, bool& isCrossing);
304 const LocalInfo* pSelf; /*< info structure for local aircraft */
305 ThreatInfo* pCurrentThreat; /*< info structure on current intruder/threat */
306 const SensitivityLevel* pAlarmThresholds;
309 /////////////////////////////////////////////////////////////////////////////
310 // TCAS::ThreatDetector /////////////////////////////////////////////////////
311 /////////////////////////////////////////////////////////////////////////////
316 ThreatDetector (TCAS* _tcas);
317 ~ThreatDetector (void) {}
322 bool checkTransponder (const SGPropertyNode* pModel, float velocityKt);
323 int checkThreat (int mode, const SGPropertyNode* pModel);
324 void checkVerticalThreat (void);
325 void horizontalThreat (float bearing, float distanceNm, float heading,
328 void setPressureAlt (float altFt) { self.pressureAltFt = altFt;}
329 float getPressureAlt (void) { return self.pressureAltFt;}
331 void setRadarAlt (float altFt) { self.radarAltFt = altFt;}
332 float getRadarAlt (void) { return self.radarAltFt;}
334 float getVelocityKt (void) { return self.velocityKt;}
335 int getRASense (void) { return currentThreat.RASense;}
338 void unitTest (void);
341 static const SensitivityLevel sensitivityLevels[];
346 SGPropertyNode_ptr nodeLat;
347 SGPropertyNode_ptr nodeLon;
348 SGPropertyNode_ptr nodePressureAlt;
349 SGPropertyNode_ptr nodeRadarAlt;
350 SGPropertyNode_ptr nodeHeading;
351 SGPropertyNode_ptr nodeVelocity;
352 SGPropertyNode_ptr nodeVerticalFps;
354 LocalInfo self; /*< info structure for local aircraft */
355 ThreatInfo currentThreat; /*< info structure on current intruder/threat */
356 const SensitivityLevel* pAlarmThresholds;
362 double nextUpdateTime;
365 SGPropertyNode_ptr nodeModeSwitch;
366 SGPropertyNode_ptr nodeServiceable;
367 SGPropertyNode_ptr nodeSelfTest;
368 SGPropertyNode_ptr nodeDebugTrigger;
369 SGPropertyNode_ptr nodeDebugRA;
370 SGPropertyNode_ptr nodeDebugThreat;
372 PropertiesHandler properties_handler;
373 ThreatDetector threatDetector;
375 AdvisoryCoordinator advisoryCoordinator;
376 AdvisoryGenerator advisoryGenerator;
377 Annunciator annunciator;
380 void selfTest (void);
383 TCAS (SGPropertyNode* node);
385 virtual void bind (void);
386 virtual void unbind (void);
387 virtual void init (void);
388 virtual void update (double dt);
392 # pragma warning( pop )
395 #endif // __INSTRUMENTS_TCAS_HXX