FlightGear next
ApproachController.cxx
Go to the documentation of this file.
1// Extracted from trafficrecord.cxx - Implementation of AIModels ATC code.
2//
3// Written by Durk Talsma, started September 2006.
4//
5// Copyright (C) 2006 Durk Talsma.
6//
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.
11//
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.
16//
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 Street, Fifth Floor, Boston, MA 02110-1301, USA.
20//
21// $Id$
22
23#include <config.h>
24
25#include <algorithm>
26#include <cstdio>
27#include <random>
28
29#include <osg/Geode>
30#include <osg/Geometry>
31#include <osg/MatrixTransform>
32#include <osg/Shape>
33
34#include <simgear/scene/material/EffectGeode.hxx>
35#include <simgear/scene/material/matlib.hxx>
36#include <simgear/scene/material/mat.hxx>
37#include <simgear/scene/util/OsgMath.hxx>
38#include <simgear/timing/sg_time.hxx>
39
40#include <Scenery/scenery.hxx>
41
42#include "trafficcontrol.hxx"
43#include "atc_mgr.hxx"
49#include <Airports/dynamics.hxx>
50#include <Airports/airport.hxx>
51#include <Radio/radio.hxx>
52#include <signal.h>
53
54#include <ATC/atc_mgr.hxx>
56#include <ATC/ATCController.hxx>
58
59using std::sort;
60using std::string;
61
62/***************************************************************************
63 * class FGApproachController
64 * subclass of FGATCController
65 **************************************************************************/
66
72
76
77
79 FGAIFlightPlan * intendedRoute,
80 int currentPosition,
81 double lat, double lon,
82 double heading, double speed,
83 double alt, double radius,
84 int leg, FGAIAircraft * ref)
85{
86 init();
87
88 // Search activeTraffic for a record matching our id
90
91 // Add a new TrafficRecord if no one exsists for this aircraft.
92 if (i == activeTraffic.end() || activeTraffic.empty()) {
94 rec->setId(id);
95
96 rec->setPositionAndHeading(lat, lon, heading, speed, alt, leg);
97 rec->setRunway(intendedRoute->getRunway());
98 rec->setLeg(leg);
99 rec->setCallsign(ref->getCallSign());
100 rec->setAircraft(ref);
101 rec->setPlannedArrivalTime(intendedRoute->getArrivalTime());
102 activeTraffic.push_back(rec);
103 } else {
104 (*i)->setRunway(intendedRoute->getRunway());
105 (*i)->setPositionAndHeading(lat, lon, heading, speed, alt, leg);
106 (*i)->setPlannedArrivalTime(intendedRoute->getArrivalTime());
107 }
108}
109
111 double heading, double speed, double alt,
112 double dt)
113{
114 time_t now = globals->get_time_params()->get_cur_time();
115 // Search activeTraffic for a record matching our id
117 TrafficVectorIterator current;
118
119 // update position of the current aircraft
120 if (i == activeTraffic.end() || activeTraffic.empty()) {
121 SG_LOG(SG_ATC, SG_ALERT,
122 "FGApproachController updating aircraft without traffic record at " << SG_ORIGIN);
123 } else {
124 (*i)->setPositionAndHeading(geod.getLatitudeDeg(), geod.getLongitudeDeg(), heading, speed, alt, AILeg::UNKNOWN);
125 current = i;
126 if((*current)->getAircraft()) {
127 //FIXME No call to aircraft! -> set instruction
128 time_t time_diff =
129 (*current)->getAircraft()->
130 checkForArrivalTime(string("final001"));
131 if (time_diff != 0) {
132 SG_LOG(SG_ATC, SG_BULK, (*current)->getCallsign() << "|ApproachController: checking for speed " << time_diff);
133 }
134 if (time_diff > 15) {
135 (*current)->setSpeedAdjustment((*current)->getAircraft()->
136 getPerformance()->vDescent() *
137 1.35);
138 } else if (time_diff > 5) {
139 (*current)->setSpeedAdjustment((*current)->getAircraft()->
140 getPerformance()->vDescent() *
141 1.2);
142 } else if (time_diff < -15) {
143 (*current)->setSpeedAdjustment((*current)->getAircraft()->
144 getPerformance()->vDescent() *
145 0.65);
146 } else if (time_diff < -5) {
147 (*current)->setSpeedAdjustment((*current)->getAircraft()->
148 getPerformance()->vDescent() *
149 0.8);
150 } else {
151 (*current)->clearSpeedAdjustment();
152 }
153 if ((now - lastTransmission) > 15) {
154 available = true;
155 }
157 SG_LOG(SG_ATC, SG_DEBUG, (*current)->getCallsign() << "(" << (*current)->getId() << ") " << " Hold " << (*current)->getRunwaySlot() << " " << (*current)->getPlannedArrivalTime() << " " << ((*current)->getRunwaySlot() > (*current)->getPlannedArrivalTime()));
158 if ((*current)->getRunwaySlot() > (*current)->getPlannedArrivalTime()) {
159 (*current)->setState(ATCMessageState::HOLD_PATTERN);
160 } else {
161 (*current)->setState(ATCMessageState::CLEARED_TO_LAND);
162 }
163 }
164 //Start of our status runimplicit "announce arrival"
166 parent->getRunwayQueue((*current)->getRunway())->requestTimeSlot((*current));
167 (*current)->setState(ATCMessageState::ACK_ARRIVAL);
168 }
170 (*current)->setState(ATCMessageState::ACK_HOLD);
171 }
173 (*current)->setState(ATCMessageState::ACK_CLEARED_TO_LAND);
174 }
176 (*current)->setState(ATCMessageState::SWITCH_GROUND_TOWER);
177 }
179 }
181 (*current)->setState(ATCMessageState::LANDING_TAXI);
182 }
183 }
184 //(*current)->setSpeedAdjustment((*current)->getAircraft()->getPerformance()->vDescent() + time_diff);
185 }
186 setDt(getDt() + dt);
187}
188
194
196 // Must be BULK in order to prevent it being called each frame
197 if (visible) {
198 SG_LOG(SG_ATC, SG_BULK, "FGApproachController::render function not yet implemented");
199 }
200}
201
203 return string(parent->parent()->getName() + "-approach");
204}
205
206int FGApproachController::getFrequency() {
207 int groundFreq = parent->getApproachFrequency(2);
208 int towerFreq = parent->getTowerFrequency(2);
209 return groundFreq>0?groundFreq:towerFreq;
210}
const double rec
#define i(x)
const std::string & getCallSign() const
Definition AIBase.hxx:367
const std::string & getRunway() const
time_t getArrivalTime() const
TrafficVectorIterator searchActiveTraffic(int id) const
Search activeTraffic vector to find matching id.
FGAirportDynamics * parent
TrafficVector activeTraffic
void setDt(double dt)
@ MSG_ACKNOWLEDGE_SWITCH_TOWER_FREQUENCY
bool checkTransmissionState(int minState, int MaxState, TrafficVectorIterator i, time_t now, AtcMsgId msgId, AtcMsgDir msgDir)
int getApproachFrequency(unsigned nr)
Definition dynamics.cxx:890
int getTowerFrequency(unsigned nr)
Definition dynamics.cxx:950
FGApproachController(FGAirportDynamics *parent)
virtual void render(bool)
virtual std::string getName() const
virtual void update(double dt)
Periodically check for and remove dead traffic records.
virtual void announcePosition(int id, FGAIFlightPlan *intendedRoute, int currentRoute, double lat, double lon, double hdg, double spd, double alt, double radius, int leg, FGAIAircraft *aircraft)
virtual void updateAircraftInformation(int id, SGGeod geod, double heading, double speed, double alt, double dt)
FGGlobals * globals
Definition globals.cxx:142
std::list< SGSharedPtr< FGTrafficRecord > >::const_iterator TrafficVectorIterator