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 **************************************************************************/
28 #include <simgear/math/sg_geodesy.hxx>
30 #include <Airports/airport.hxx>
31 #include <Airports/runways.hxx>
32 #include <Airports/dynamics.hxx>
34 #include <Environment/environment_mgr.hxx>
35 #include <Environment/environment.hxx>
37 #include "AIFlightPlan.hxx"
38 #include "AIAircraft.hxx"
39 #include "performancedata.hxx"
43 // TODO: Use James Turner's createOnGround functions.
44 bool FGAIFlightPlan::createPushBack(FGAIAircraft *ac,
45 bool firstFlight, FGAirport *dep,
47 const string& fltType,
48 const string& aircraftType,
49 const string& airline)
51 double vTaxi = ac->getPerformance()->vTaxi();
52 double vTaxiBackward = vTaxi * (-2.0/3.0);
53 double vTaxiReduced = vTaxi * (2.0/3.0);
55 // Active runway can be conditionally set by ATC, so at the start of a new flight, this
59 if (!(dep->getDynamics()->getGroundNetwork()->exists())) {
60 //cerr << "Push Back fallback" << endl;
61 createPushBackFallBack(ac, firstFlight, dep,
62 radius, fltType, aircraftType, airline);
66 // establish the parking position / gate if required
68 gate = dep->getDynamics()->getAvailableParking(radius, fltType,
69 aircraftType, airline);
70 if (!gate.isValid()) {
71 SG_LOG(SG_AI, SG_WARN, "Warning: Could not find parking for a " <<
73 " of flight type " << fltType <<
74 " of airline " << airline <<
75 " at airport " << dep->getId());
80 if (!gate.isValid()) {
81 createPushBackFallBack(ac, firstFlight, dep,
82 radius, fltType, aircraftType, airline);
87 FGGroundNetwork* groundNet = dep->getDynamics()->getGroundNetwork();
88 FGParking *parking = gate.parking();
89 if (parking && parking->getPushBackPoint() > 0) {
90 FGTaxiRoute route = groundNet->findShortestRoute(parking->guid(), parking->getPushBackPoint(), false);
92 int size = route.size();
94 SG_LOG(SG_AI, SG_ALERT, "Push back route from gate " << parking->ident() << " has only " << size << " nodes.");
95 SG_LOG(SG_AI, SG_ALERT, "Using " << parking->getPushBackPoint());
102 while (route.next(&node, &rte))
105 snprintf (buffer, 10, "%lld", (long long int) node);
106 FGTaxiNode *tn = groundNet->findNode(node);
107 FGAIWaypoint *wpt = createOnGround(ac, string(buffer), tn->geod(), dep->getElevation(), vTaxiBackward);
111 FGTaxiSegment* segment = groundNet->findSegment(previous, node);
112 wpt->setRouteIndex(segment->getIndex());
114 // not on the route yet, make up a unique segment ID
115 int x = (int) tn->guid();
116 wpt->setRouteIndex(x);
119 wpt->setRouteIndex(rte);
120 pushBackWaypoint(wpt);
123 // some special considerations for the last point:
124 waypoints.back()->setName(string("PushBackPoint"));
125 waypoints.back()->setSpeed(vTaxi);
126 ac->setTaxiClearanceRequest(true);
127 } else { // In case of a push forward departure...
128 ac->setTaxiClearanceRequest(false);
131 FGTaxiSegment* pushForwardSegment = dep->getDynamics()->getGroundNetwork()->findSegment(parking->guid(), 0);
132 // there aren't any routes for this parking.
133 if (!pushForwardSegment) {
134 SG_LOG(SG_AI, SG_ALERT, "Gate " << parking->ident() << "doesn't seem to have routes associated with it.");
138 lastNodeVisited = pushForwardSegment->getEnd()->getIndex();
139 double distance = pushForwardSegment->getLength();
141 double parkingHeading = parking->getHeading();
143 for (int i = 1; i < 10; i++) {
144 SGGeod pushForwardPt;
145 SGGeodesy::direct(parking->geod(), parkingHeading,
146 ((i / 10.0) * distance), pushForwardPt, az2);
148 snprintf(buffer, 16, "pushback-%02d", i);
149 FGAIWaypoint *wpt = createOnGround(ac, string(buffer), pushForwardPt, dep->getElevation(), vTaxiReduced);
151 wpt->setRouteIndex(pushForwardSegment->getIndex());
152 pushBackWaypoint(wpt);
155 waypoints.back()->setName(string("PushBackPoint"));
156 // cerr << "Done assinging new name" << endl;
161 /*******************************************************************
162 * createPushBackFallBack
163 * This is the backup function for airports that don't have a
165 ******************************************************************/
166 void FGAIFlightPlan::createPushBackFallBack(FGAIAircraft *ac, bool firstFlight, FGAirport *dep,
168 const string& fltType,
169 const string& aircraftType,
170 const string& airline)
174 double vTaxi = ac->getPerformance()->vTaxi();
175 double vTaxiBackward = vTaxi * (-2.0/3.0);
176 double vTaxiReduced = vTaxi * (2.0/3.0);
178 double heading = 180.0; // this is a completely arbitrary heading!
179 FGAIWaypoint *wpt = createOnGround(ac, string("park"), dep->geod(), dep->getElevation(), vTaxiBackward);
181 pushBackWaypoint(wpt);
184 SGGeodesy::direct(dep->geod(), heading, 10, coord, az2);
185 wpt = createOnGround(ac, string("park2"), coord, dep->getElevation(), vTaxiBackward);
187 pushBackWaypoint(wpt);
189 SGGeodesy::direct(dep->geod(), heading, 2.2 * radius, coord, az2);
190 wpt = createOnGround(ac, string("taxiStart"), coord, dep->getElevation(), vTaxiReduced);
191 pushBackWaypoint(wpt);