WSF
XWsfAirTraffic.hpp
Go to the documentation of this file.
1// ****************************************************************************
2// CUI
3//
4// The Advanced Framework for Simulation, Integration, and Modeling (AFSIM)
5//
6// Copyright 2003-2015 The Boeing Company. All rights reserved.
7//
8// The use, dissemination or disclosure of data in this file is subject to
9// limitation or restriction. See accompanying README and LICENSE for details.
10// ****************************************************************************
11
12#ifndef XWSFAIRTRAFFIC_HPP
13#define XWSFAIRTRAFFIC_HPP
14
15#include "wsf_export.h"
16
17#include <limits>
18#include <map>
19#include <string>
20#include <vector>
21
22class UtInput;
23#include "WsfCallback.hpp"
24#include "WsfEvent.hpp"
25#include "WsfMover.hpp"
26#include "WsfPlatform.hpp"
27class WsfRoute;
28#include "WsfSimulation.hpp"
29#include "WsfStringId.hpp"
30class WsfWaypoint;
32
34{
35public:
36 // The remaining classes describe data used by this class.
37
39 {
40 public:
42 : mAirbaseNameId(nullptr)
43 , mFraction(1.0)
44 {
45 }
46
47 WsfStringId mAirbaseNameId; // String Id of the airbase name
48
49 double mLatitude; // The latitude of the local destination
50 double mLongitude; // The longitude of the local destination
51 double mRadius;
52
53 double mFraction; // Fraction of departures going to this destination
54 };
55
56 typedef std::vector<Destination> Destinations;
57
59 {
60 public:
62 : mAircraftTypeId(nullptr)
63 , mFraction(1.0)
64 {
65 }
66 WsfStringId mAircraftTypeId; // String Id of the aircraft type
67 double mFraction; // Fraction of departures using this aircraft type
68 };
69
70 class Runway
71 {
72 public:
74 : mBegLat(0.0)
75 , mBegLon(0.0)
76 , mBegHeight(0.0F)
77 , mEndLat(0.0)
78 , mEndLon(0.0)
79 , mEndHeight(0.0F)
80 {
81 }
82
83 double mMidLat;
84 double mMidLon;
85 double mBegLat;
86 double mBegLon;
88 double mEndLat;
89 double mEndLon;
91 double mHeading;
92 double mLength;
93 double mLatFAF;
94 double mLonFAF;
95 float mAltFAF;
96 double mLatIAF;
97 double mLonIAF;
98 float mAltIAF;
103 };
104
106 {
107 public:
109 : mNameId(nullptr)
110 , mLat(0.0)
111 , mLon(0.0)
112 , mDepartureInterval(300.0)
113 , mDeactivationTime(std::numeric_limits<double>::max())
114 , mRunway()
115 , mDestinations()
116 , mAircrafts()
117 , mNextDepartureTime(0.0)
118 , mFlightNumber(0)
119 , mIsActive(true)
120 {
121 }
122
123 WsfStringId mNameId; // String Id of the airbase name
124 double mLat; // Latitude of the airbase
125 double mLon; // Longitude of the airbase
126 double mDepartureInterval; // Time (secs) between departures
127 double mDeactivationTime; // Simulation time when airbase is to be deactivated
131 std::vector<Aircraft> mAircrafts;
132 double mNextDepartureTime; // Sim time (secs) of next departure
133 unsigned int mFlightNumber; // Serial counter of flights from this airbase
135 };
136
138 {
139 public:
141 : mTypeId(nullptr)
142 , mLocal(false)
145 , mMeanCruiseSpeed(0.0F)
146 , mSigmaCruiseSpeed(0.0F)
149 , mLoiterTime(0.0)
150 , mSigmaLoiterTime(0.0)
151 , mDefaultLoiterTime(1800.0)
152 {
153 }
155 bool mLocal;
165 std::vector<WsfStringId> mRouteIds;
166 };
167
191
192 typedef std::map<WsfStringId, Airbase> Airbases;
193 typedef std::map<WsfStringId, AircraftType> AircraftTypes;
194
196 : mEveryoneLandTime(std::numeric_limits<double>::max())
197 {
198 }
199
200 bool ProcessInput(UtInput& aInput);
201 void ProcessAirbaseBlock(UtInput& aInput);
202 void ProcessAircraftTypeBlock(UtInput& aInput);
203
204 static double NormalizeHeading(double aHeading);
205 bool IsRequested() const;
206
210};
211
213{
214public:
215 XWsfAirTraffic(WsfSimulation& aSimulation, XWsfAirTrafficData& aData);
216 ~XWsfAirTraffic() override;
217
218 bool Initialize() override;
219
220 void UpdateFlightStatus(double aSimTime, WsfPlatform* aPlatformPtr, WsfStringId& aFlightStatus);
221
222 // void ProcessDepartureEvent(int aAirbaseId,
223 // double aSimTime);
224
225 double ProcessEvent(double aSimTime);
226
227 void ProcessDivertFlights(double aSimtime);
228
229private:
230 // Copy constructed declared but not defined to prevent use.
231 XWsfAirTraffic(const XWsfAirTraffic& aSrc);
232
233 // Assignment operator declared but not defined to prevent use.
234 XWsfAirTraffic& operator=(const XWsfAirTraffic& aRhs) = delete;
235
236public:
237 // An air traffic event is scheduled for the next time a takeoff
238 // or airbase deactivation is to occur.
239
241 {
242 public:
243 AirTrafficEvent(double aSimTime, XWsfAirTraffic* aAirTrafficPtr)
244 : WsfEvent(aSimTime)
245 , mAirTrafficPtr(aAirTrafficPtr)
246 {
247 }
248
250 {
251 double nextEventTime = mAirTrafficPtr->ProcessEvent(GetTime());
252 EventDisposition disposition = cDELETE;
253 if (nextEventTime >= 0.0)
254 {
255 SetTime(nextEventTime);
256 disposition = cRESCHEDULE;
257 }
258 return disposition;
259 }
260
261 private:
262 XWsfAirTraffic* mAirTrafficPtr;
263 };
264
266 {
267 public:
269 : WsfCallback()
270 , mAirTrafficPtr(aAirTrafficPtr)
271 , mFlightStatus(aFlightStatus)
272 {
273 }
274
275 WsfCallback* Clone() const override { return new UpdateFlightStatusCallback(*this); }
276
277 bool Execute(double aSimTime, WsfPlatform* aPlatformPtr) override
278 {
279 mAirTrafficPtr->UpdateFlightStatus(aSimTime, aPlatformPtr, mFlightStatus);
280 return true;
281 }
282
283 private:
284 XWsfAirTraffic* mAirTrafficPtr;
285 WsfStringId mFlightStatus;
286 };
287
292 {
293 public:
294 ExitLoiterEvent(WsfStringId aPlatformId, double aSimTime)
295 : WsfEvent(aSimTime)
296 , mPlatformId(aPlatformId)
297 {
298 }
299
301 {
302 WsfPlatform* platformPtr = GetSimulation()->GetPlatformByName(mPlatformId);
303 if (platformPtr != nullptr)
304 {
305 WsfMover* moverPtr = platformPtr->GetMover();
306 if (moverPtr != nullptr)
307 {
308 moverPtr->GoToLabel(GetTime(), "XWSF_AIR_TRAFFIC_GO_HOME");
309 }
310 }
311 return cDELETE;
312 }
313
314 private:
315 WsfStringId mPlatformId;
316 };
317
318private: // Revert back to 'private' (For Sun Workshop compiler)
319 void AddCallback(WsfPlatform* aPlatformPtr, WsfStringId& aCallbackName);
320
321 void AddToSimulation(const Aircraft& aAircraft,
322 bool aLocalAircraft,
323 Airbase& aAirbase,
324 const Destination& aDestination,
325 double aSimTime);
326
327 double ComputeHeadingChange(double aCurrentHeading, double aTargetHeading) const;
328
329 void ComputeRunwayParameters(Runway& aRunway);
330
332 void DivertFlight(double aSimTime, Flight& aFlight);
333
334 unsigned int FindAirbase(WsfStringId aAirbaseNameId) const;
335
336 void GenerateAscentPath(const Airbase& aOrigination,
337 const Airbase& aDestination,
338 float aCruiseAlt,
339 float aCruiseSpeed,
340 WsfRoute& aRoute);
341
342 void GenerateAscentPath(const Airbase& aAirbase, float aCruiseSpeed, WsfRoute& aRoute);
343
344 void GenerateLoiterPath(const std::vector<WsfStringId>& aRouteIds,
345 const Destination& aDestination,
346 float aCruiseAlt,
347 float aCruiseSpeed,
348 WsfRoute& aRoute);
349
350 void GenerateDescentPath(WsfRoute& aRoute,
351 double aCurrentLat,
352 double aCurrentLon,
353 double aCurrentAlt,
354 double aCurrentSpeed,
355 const Airbase& aDestination);
356
357 void GenerateDiversionPath(Flight& aFlight);
358
359 bool GetRandomDestination(const Airbase& aAirbase, const Destinations& aDestinations, Destination& aDestination);
360
361 bool GetRandomAircraft(const Airbase& aAirbase, const Airbase& aDestAirbase, Aircraft& aAircraft);
362
363 bool GetRandomLocalAircraft(const Airbase& aAirbase, Aircraft& aAircraft);
364
365 bool DrawLocalOrRemote(const Airbase& aAirbase);
366
367 void GetRandomWaypoint(const Destination& aDestination, WsfWaypoint& aWaypoint);
368
369 double GetRandomLoiterTime(const AircraftType& aAircraftType);
370
371 bool DoesAirbaseExist(WsfStringId aTypeId) const { return (mAirbases.find(aTypeId) != mAirbases.end()); }
372 bool DoesAircraftTypeExist(WsfStringId aTypeId) const
373 {
374 return (mAircraftTypes.find(aTypeId) != mAircraftTypes.end());
375 }
376
377 WsfStringId mTakeOff;
378 WsfStringId mAscending;
379 WsfStringId mCruising;
380 WsfStringId mDescending;
381 WsfStringId mTouchdown;
382 WsfStringId mComplete;
383 WsfStringId mEnterLoiter;
384 WsfStringId mGoHome;
385
386
387 std::vector<Flight> mFlights;
388
389 int mEveryoneLand;
390};
391
392#endif
WsfMover * moverPtr
Definition WsfScriptPlatformClass.cpp:2367
WsfPlatform * platformPtr
Definition WsfScriptTrackClass.cpp:507
UtStringId WsfStringId
WsfStringId – the same thing as UtStringId.
Definition WsfStringId.hpp:23
#define WSF_EXPORT
Definition WsfXIO_Export.hpp:35
WsfCallback()
Definition WsfCallback.cpp:21
double GetTime() const
Definition WsfEvent.hpp:71
WsfSimulation * GetSimulation() const
Definition WsfEvent.hpp:103
WsfEvent()=default
void SetTime(double aSimTime)
Definition WsfEvent.hpp:86
EventDisposition
Definition WsfEvent.hpp:37
@ cRESCHEDULE
Reschedule the event. WsfEvent::SetTime should have been called with the new time.
Definition WsfEvent.hpp:39
@ cDELETE
Delete the event from the event queue.
Definition WsfEvent.hpp:38
Definition WsfMover.hpp:37
Platforms represent a entity within the simulation.
Definition WsfPlatform.hpp:115
A collection of WsfWaypoint objects that represent a path to be followed.
Definition WsfRoute.hpp:40
WsfSimulationExtension()
Definition WsfSimulationExtension.cpp:23
friend class WsfSimulation
Definition WsfSimulationExtension.hpp:43
Definition WsfWaypoint.hpp:57
std::vector< Aircraft > mAircrafts
Definition XWsfAirTraffic.hpp:131
WsfStringId mNameId
Definition XWsfAirTraffic.hpp:123
Destinations mLocalDestinations
Definition XWsfAirTraffic.hpp:130
Airbase()
Definition XWsfAirTraffic.hpp:108
unsigned int mFlightNumber
Definition XWsfAirTraffic.hpp:133
double mLat
Definition XWsfAirTraffic.hpp:124
bool mIsActive
Definition XWsfAirTraffic.hpp:134
Destinations mDestinations
Definition XWsfAirTraffic.hpp:129
double mDepartureInterval
Definition XWsfAirTraffic.hpp:126
Runway mRunway
Definition XWsfAirTraffic.hpp:128
double mLon
Definition XWsfAirTraffic.hpp:125
double mDeactivationTime
Definition XWsfAirTraffic.hpp:127
double mNextDepartureTime
Definition XWsfAirTraffic.hpp:132
double mSigmaLoiterTime
Definition XWsfAirTraffic.hpp:163
double mDefaultLoiterTime
Definition XWsfAirTraffic.hpp:164
std::vector< WsfStringId > mRouteIds
Definition XWsfAirTraffic.hpp:165
float mMinimumRunwayLength
Definition XWsfAirTraffic.hpp:161
float mSigmaCruiseSpeed
Definition XWsfAirTraffic.hpp:159
float mMaximumOperatingRange
Definition XWsfAirTraffic.hpp:160
bool mLocal
Definition XWsfAirTraffic.hpp:155
AircraftType()
Definition XWsfAirTraffic.hpp:140
double mLoiterTime
Definition XWsfAirTraffic.hpp:162
WsfStringId mTypeId
Definition XWsfAirTraffic.hpp:154
float mMaximumCruiseAltitude
Definition XWsfAirTraffic.hpp:157
float mMeanCruiseSpeed
Definition XWsfAirTraffic.hpp:158
float mMinimumCruiseAltitude
Definition XWsfAirTraffic.hpp:156
Aircraft()
Definition XWsfAirTraffic.hpp:61
double mFraction
Definition XWsfAirTraffic.hpp:67
WsfStringId mAircraftTypeId
Definition XWsfAirTraffic.hpp:66
Destination()
Definition XWsfAirTraffic.hpp:41
double mLatitude
Definition XWsfAirTraffic.hpp:49
double mRadius
Definition XWsfAirTraffic.hpp:51
double mLongitude
Definition XWsfAirTraffic.hpp:50
double mFraction
Definition XWsfAirTraffic.hpp:53
WsfStringId mAirbaseNameId
Definition XWsfAirTraffic.hpp:47
WsfStringId mStatus
Definition XWsfAirTraffic.hpp:188
WsfStringId mDestinationId
Definition XWsfAirTraffic.hpp:184
bool mDiversionPending
Definition XWsfAirTraffic.hpp:189
size_t mPlatformIndex
Definition XWsfAirTraffic.hpp:182
WsfStringId mAircraftTypeId
Definition XWsfAirTraffic.hpp:185
WsfStringId mOriginationId
Definition XWsfAirTraffic.hpp:183
double mCruiseAltitude
Definition XWsfAirTraffic.hpp:186
double mCruiseSpeed
Definition XWsfAirTraffic.hpp:187
Flight()
Definition XWsfAirTraffic.hpp:171
Definition XWsfAirTraffic.hpp:71
double mLength
Definition XWsfAirTraffic.hpp:92
double mEndLon
Definition XWsfAirTraffic.hpp:89
double mLatLeftIAF
Definition XWsfAirTraffic.hpp:101
double mLonFAF
Definition XWsfAirTraffic.hpp:94
double mBegLon
Definition XWsfAirTraffic.hpp:86
double mLatIAF
Definition XWsfAirTraffic.hpp:96
double mLonIAF
Definition XWsfAirTraffic.hpp:97
double mBegLat
Definition XWsfAirTraffic.hpp:85
float mAltIAF
Definition XWsfAirTraffic.hpp:98
double mMidLat
Definition XWsfAirTraffic.hpp:83
float mAltFAF
Definition XWsfAirTraffic.hpp:95
double mLonLeftIAF
Definition XWsfAirTraffic.hpp:102
double mLonRightIAF
Definition XWsfAirTraffic.hpp:100
double mLatFAF
Definition XWsfAirTraffic.hpp:93
float mEndHeight
Definition XWsfAirTraffic.hpp:90
double mLatRightIAF
Definition XWsfAirTraffic.hpp:99
double mMidLon
Definition XWsfAirTraffic.hpp:84
double mEndLat
Definition XWsfAirTraffic.hpp:88
float mBegHeight
Definition XWsfAirTraffic.hpp:87
Runway()
Definition XWsfAirTraffic.hpp:73
double mHeading
Definition XWsfAirTraffic.hpp:91
std::map< WsfStringId, Airbase > Airbases
Definition XWsfAirTraffic.hpp:192
std::vector< Destination > Destinations
Definition XWsfAirTraffic.hpp:56
std::map< WsfStringId, AircraftType > AircraftTypes
Definition XWsfAirTraffic.hpp:193
double mEveryoneLandTime
Definition XWsfAirTraffic.hpp:207
XWsfAirTrafficData()
Definition XWsfAirTraffic.hpp:195
Airbases mAirbases
Definition XWsfAirTraffic.hpp:208
AircraftTypes mAircraftTypes
Definition XWsfAirTraffic.hpp:209
AirTrafficEvent(double aSimTime, XWsfAirTraffic *aAirTrafficPtr)
Definition XWsfAirTraffic.hpp:243
EventDisposition Execute() override
Definition XWsfAirTraffic.hpp:249
EventDisposition Execute() override
Definition XWsfAirTraffic.hpp:300
ExitLoiterEvent(WsfStringId aPlatformId, double aSimTime)
Definition XWsfAirTraffic.hpp:294
bool Execute(double aSimTime, WsfPlatform *aPlatformPtr) override
Definition XWsfAirTraffic.hpp:277
UpdateFlightStatusCallback(XWsfAirTraffic *aAirTrafficPtr, WsfStringId &aFlightStatus)
Definition XWsfAirTraffic.hpp:268
WsfCallback * Clone() const override
Definition XWsfAirTraffic.hpp:275
bool Initialize() override
Initialize the air traffic object.
Definition XWsfAirTraffic.cpp:97
void UpdateFlightStatus(double aSimTime, WsfPlatform *aPlatformPtr, WsfStringId &aFlightStatus)
Process a waypoint callback.
Definition XWsfAirTraffic.cpp:405
double ProcessEvent(double aSimTime)
Process airbase deactivations and takeoffs as required.
Definition XWsfAirTraffic.cpp:213
XWsfAirTraffic(WsfSimulation &aSimulation, XWsfAirTrafficData &aData)
Definition XWsfAirTraffic.cpp:71
void ProcessDivertFlights(double aSimtime)
Definition XWsfAirTraffic.cpp:308
Template specialization for wsf::comm::Address. Allows usage of Address in std::unordered_map/set.
Definition WsfCommAddress.hpp:185
Copyrights Multiple, All Rights Reserved