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>
33 #include <Airports/groundnetwork.hxx>
35 #include <Environment/environment_mgr.hxx>
36 #include <Environment/environment.hxx>
38 #include "AIFlightPlan.hxx"
39 #include "AIAircraft.hxx"
40 #include "performancedata.hxx"
44 // TODO: Use James Turner's createOnGround functions.
45 bool FGAIFlightPlan::createPushBack(FGAIAircraft *ac,
46 bool firstFlight, FGAirport *dep,
48 const string& fltType,
49 const string& aircraftType,
50 const string& airline)
52 double vTaxi = ac->getPerformance()->vTaxi();
53 double vTaxiBackward = vTaxi * (-2.0/3.0);
54 double vTaxiReduced = vTaxi * (2.0/3.0);
56 // Active runway can be conditionally set by ATC, so at the start of a new flight, this
60 if (!(dep->getDynamics()->getGroundController()->exists())) {
61 //cerr << "Push Back fallback" << endl;
62 createPushBackFallBack(ac, firstFlight, dep,
63 radius, fltType, aircraftType, airline);
67 // establish the parking position / gate if required
69 // if the airprot has no parking positions defined, don't log
71 if (!dep->getDynamics()->hasParkings()) {
75 gate = dep->getDynamics()->getAvailableParking(radius, fltType,
76 aircraftType, airline);
77 if (!gate.isValid()) {
78 SG_LOG(SG_AI, SG_WARN, "Could not find parking for a " <<
80 " of flight type " << fltType <<
81 " of airline " << airline <<
82 " at airport " << dep->getId());
87 if (!gate.isValid()) {
88 createPushBackFallBack(ac, firstFlight, dep,
89 radius, fltType, aircraftType, airline);
94 FGGroundNetwork* groundNet = dep->getDynamics()->getGroundNetwork();
95 FGParking *parking = gate.parking();
96 if (parking && parking->getPushBackPoint() > 0) {
97 FGTaxiRoute route = groundNet->findShortestRoute(parking, parking->getPushBackPoint(), false);
99 int size = route.size();
101 SG_LOG(SG_AI, SG_ALERT, "Push back route from gate " << parking->ident() << " has only " << size << " nodes.");
102 SG_LOG(SG_AI, SG_ALERT, "Using " << parking->getPushBackPoint());
109 while (route.next(node, &rte))
112 snprintf (buffer, 10, "%d", node->getIndex());
113 FGAIWaypoint *wpt = createOnGround(ac, string(buffer), node->geod(), dep->getElevation(), vTaxiBackward);
117 FGTaxiSegment* segment = groundNet->findSegment(previous, node);
118 wpt->setRouteIndex(segment->getIndex());
120 // not on the route yet, make up a unique segment ID
121 int x = (int) tn->guid();
122 wpt->setRouteIndex(x);
125 wpt->setRouteIndex(rte);
126 pushBackWaypoint(wpt);
129 // some special considerations for the last point:
130 waypoints.back()->setName(string("PushBackPoint"));
131 waypoints.back()->setSpeed(vTaxi);
132 ac->setTaxiClearanceRequest(true);
133 } else { // In case of a push forward departure...
134 ac->setTaxiClearanceRequest(false);
137 FGTaxiSegment* pushForwardSegment = dep->getDynamics()->getGroundNetwork()->findSegment(parking, 0);
138 // there aren't any routes for this parking.
139 if (!pushForwardSegment) {
140 SG_LOG(SG_AI, SG_ALERT, "Gate " << parking->ident() << "doesn't seem to have routes associated with it.");
144 lastNodeVisited = pushForwardSegment->getEnd();
145 double distance = pushForwardSegment->getLength();
147 double parkingHeading = parking->getHeading();
149 for (int i = 1; i < 10; i++) {
150 SGGeod pushForwardPt;
151 SGGeodesy::direct(parking->geod(), parkingHeading,
152 ((i / 10.0) * distance), pushForwardPt, az2);
154 snprintf(buffer, 16, "pushback-%02d", i);
155 FGAIWaypoint *wpt = createOnGround(ac, string(buffer), pushForwardPt, dep->getElevation(), vTaxiReduced);
157 wpt->setRouteIndex(pushForwardSegment->getIndex());
158 pushBackWaypoint(wpt);
161 waypoints.back()->setName(string("PushBackPoint"));
162 // cerr << "Done assinging new name" << endl;
167 /*******************************************************************
168 * createPushBackFallBack
169 * This is the backup function for airports that don't have a
171 ******************************************************************/
172 void FGAIFlightPlan::createPushBackFallBack(FGAIAircraft *ac, bool firstFlight, FGAirport *dep,
174 const string& fltType,
175 const string& aircraftType,
176 const string& airline)
180 double vTaxi = ac->getPerformance()->vTaxi();
181 double vTaxiBackward = vTaxi * (-2.0/3.0);
182 double vTaxiReduced = vTaxi * (2.0/3.0);
184 double heading = 180.0; // this is a completely arbitrary heading!
185 FGAIWaypoint *wpt = createOnGround(ac, string("park"), dep->geod(), dep->getElevation(), vTaxiBackward);
187 pushBackWaypoint(wpt);
190 SGGeodesy::direct(dep->geod(), heading, 10, coord, az2);
191 wpt = createOnGround(ac, string("park2"), coord, dep->getElevation(), vTaxiBackward);
193 pushBackWaypoint(wpt);
195 SGGeodesy::direct(dep->geod(), heading, 2.2 * radius, coord, az2);
196 wpt = createOnGround(ac, string("taxiStart"), coord, dep->getElevation(), vTaxiReduced);
197 pushBackWaypoint(wpt);