1 /******************************************************************************
2 * AIFlightPlanCreatePushBack.cxx
3 * Written by Durk Talsma, started August 1, 2007.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of the
8 * License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 **************************************************************************/
20 #include "AIFlightPlan.hxx"
21 #include <simgear/math/sg_geodesy.hxx>
22 #include <Airports/runways.hxx>
24 #include <Environment/environment_mgr.hxx>
25 #include <Environment/environment.hxx>
28 void FGAIFlightPlan::createPushBack(bool firstFlight, FGAirport *dep,
32 const string& fltType,
33 const string& aircraftType,
34 const string& airline)
36 double lat, lon, heading;
37 FGTaxiRoute *pushBackRoute;
38 if (!(dep->getDynamics()->getGroundNetwork()->exists())) {
39 //cerr << "Push Back fallback" << endl;
40 createPushBackFallBack(firstFlight, dep, latitude, longitude,
41 radius, fltType, aircraftType, airline);
45 if (!(dep->getDynamics()->getAvailableParking(&lat, &lon,
48 aircraftType, airline))) {
49 SG_LOG(SG_INPUT, SG_WARN, "Warning: Could not find parking for a " <<
51 " of flight type " << fltType <<
52 " of airline " << airline <<
53 " at airport " << dep->getId());
55 snprintf (buffer, 10, "%d", gateId);
56 //FGTaxiNode *tn = dep->getDynamics()->getGroundNetwork()->findNode(node);
59 wpt->name = string(buffer); // fixme: should be the name of the taxiway
62 // Elevation is currently disregarded when on_ground is true
63 // because the AIModel obtains a periodic ground elevation estimate.
64 wpt->altitude = dep->getElevation();
66 wpt->crossat = -10000;
67 wpt->gear_down = true;
68 wpt->flaps_down= true;
69 wpt->finished = false;
70 wpt->on_ground = true;
72 waypoints.push_back(wpt);
74 //cerr << "Success : GateId = " << gateId << endl;
75 SG_LOG(SG_INPUT, SG_WARN, "Warning: Succesfully found a parking for a " <<
77 " of flight type " << fltType <<
78 " of airline " << airline <<
79 " at airport " << dep->getId());
81 //cerr << "Push Back follow-up Flight" << endl;
82 dep->getDynamics()->getParking(gateId, &lat, &lon, &heading);
85 createPushBackFallBack(firstFlight, dep, latitude, longitude,
86 radius, fltType, aircraftType, airline);
90 //cerr << "getting parking " << gateId;
91 //cerr << " for a " <<
93 // " of flight type " << fltType <<
94 // " of airline " << airline <<
95 // " at airport " << dep->getId() << endl;
96 FGParking *parking = dep->getDynamics()->getParking(gateId);
97 int pushBackNode = parking->getPushBackPoint();
100 pushBackRoute = parking->getPushBackRoute();
101 if ((pushBackNode > 0) && (pushBackRoute == 0)) {
104 //cerr << "Creating push-back for " << gateId << " (" << parking->getName() << ") using push-back point " << pushBackNode << endl;
105 route = dep->getDynamics()->getGroundNetwork()->findShortestRoute(gateId, pushBackNode, false);
106 parking->setPushBackRoute(new FGTaxiRoute(route));
109 pushBackRoute = parking->getPushBackRoute();
110 int size = pushBackRoute->size();
112 SG_LOG(SG_GENERAL, SG_WARN, "Push back route from gate " << gateId << " has only " << size << " nodes.");
113 SG_LOG(SG_GENERAL, SG_WARN, "Using " << pushBackNode);
115 pushBackRoute->first();
117 while(pushBackRoute->next(&node, &rte))
119 //FGTaxiNode *tn = apt->getDynamics()->getGroundNetwork()->findSegment(node)->getEnd();
121 snprintf (buffer, 10, "%d", node);
122 FGTaxiNode *tn = dep->getDynamics()->getGroundNetwork()->findNode(node);
125 wpt->name = string(buffer); // fixme: should be the name of the taxiway
126 wpt->latitude = tn->getLatitude();
127 wpt->longitude = tn->getLongitude();
128 // Elevation is currently disregarded when on_ground is true
129 // because the AIModel obtains a periodic ground elevation estimate.
130 wpt->altitude = dep->getElevation();
132 wpt->crossat = -10000;
133 wpt->gear_down = true;
134 wpt->flaps_down= true;
135 wpt->finished = false;
136 wpt->on_ground = true;
137 wpt->routeIndex = rte;
138 waypoints.push_back(wpt);
140 // some special considerations for the last point:
141 wpt->name = string("PushBackPoint");
144 //cerr << "Creating direct forward departure route fragment" << endl;
145 double lat2, lon2, az2;
147 geo_direct_wgs_84 ( 0, lat, lon, heading,
148 2, &lat2, &lon2, &az2 );
151 wpt->latitude = lat2;
152 wpt->longitude = lon2;
153 wpt->altitude = dep->getElevation();
155 wpt->crossat = -10000;
156 wpt->gear_down = true;
157 wpt->flaps_down= true;
158 wpt->finished = false;
159 wpt->on_ground = true;
161 waypoints.push_back(wpt);
163 geo_direct_wgs_84 ( 0, lat, lon, heading,
164 4, &lat2, &lon2, &az2 );
167 wpt->latitude = lat2;
168 wpt->longitude = lon2;
169 wpt->altitude = dep->getElevation();
171 wpt->crossat = -10000;
172 wpt->gear_down = true;
173 wpt->flaps_down= true;
174 wpt->finished = false;
175 wpt->on_ground = true;
177 waypoints.push_back(wpt);
179 //cerr << "Creating final push forward point for gate " << gateId << endl;
180 FGTaxiNode *tn = dep->getDynamics()->getGroundNetwork()->findNode(gateId);
181 FGTaxiSegmentVectorIterator ts = tn->getBeginRoute();
182 FGTaxiSegmentVectorIterator te = tn->getEndRoute();
184 SG_LOG(SG_GENERAL, SG_ALERT, "Gate " << gateId << "doesn't seem to have routes associated with it.");
187 tn = (*ts)->getEnd();
188 lastNodeVisited = tn->getIndex();
190 SG_LOG(SG_GENERAL, SG_ALERT, "No valid taxinode found");
194 wpt->name = "PushBackPoint";
195 wpt->latitude = tn->getLatitude();
196 wpt->longitude = tn->getLongitude();
197 wpt->altitude = dep->getElevation();
199 wpt->crossat = -10000;
200 wpt->gear_down = true;
201 wpt->flaps_down= true;
202 wpt->finished = false;
203 wpt->on_ground = true;
204 wpt->routeIndex = (*ts)->getIndex();
205 waypoints.push_back(wpt);
212 /*******************************************************************
213 * createPushBackFallBack
214 * This is the backup function for airports that don't have a
216 ******************************************************************/
217 void FGAIFlightPlan::createPushBackFallBack(bool firstFlight, FGAirport *dep,
221 const string& fltType,
222 const string& aircraftType,
223 const string& airline)
234 dep->getDynamics()->getParking(-1, &lat, &lon, &heading);
239 waypoint *wpt = new waypoint;
242 wpt->longitude = lon;
243 wpt->altitude = dep->getElevation();
245 wpt->crossat = -10000;
246 wpt->gear_down = true;
247 wpt->flaps_down= true;
248 wpt->finished = false;
249 wpt->on_ground = true;
251 waypoints.push_back(wpt);
253 geo_direct_wgs_84 ( 0, lat, lon, heading,
255 &lat2, &lon2, &az2 );
258 wpt->latitude = lat2;
259 wpt->longitude = lon2;
260 wpt->altitude = dep->getElevation();
262 wpt->crossat = -10000;
263 wpt->gear_down = true;
264 wpt->flaps_down= true;
265 wpt->finished = false;
266 wpt->on_ground = true;
268 waypoints.push_back(wpt);
269 geo_direct_wgs_84 ( 0, lat, lon, heading,
271 &lat2, &lon2, &az2 );
273 wpt->name = "taxiStart";
274 wpt->latitude = lat2;
275 wpt->longitude = lon2;
276 wpt->altitude = dep->getElevation();
278 wpt->crossat = -10000;
279 wpt->gear_down = true;
280 wpt->flaps_down= true;
281 wpt->finished = false;
282 wpt->on_ground = true;
284 waypoints.push_back(wpt);