All Classes Functions
DirectAscent.h
1 // ==============================================================
2 // ORBITER MODULE: LaunchMFD
3 // Part of the ORBITER SDK
4 //
5 // Copyright (C) 2004 rjcroy - robust time based pitch autopilot (borrowed code)
6 // Copyright (C) 2004 Dave "Daver" Rowbotham - conversion of rjcroy's autopolot to C++ (borrowed code)
7 // Copyright (C) 2004 Erik H. "Sputnik" Anderson - conversion of the autopilot to energy based (borrowed code)
8 // Copyright (C) 2007 "Vanguard" - dressing up azimuth calcualtions into an MFD (author)
9 // Copyright (C) 2007 Pawel "She'da'Lier" Stiasny - yaw error visual representation (contributor)
10 // Copyright (C) 2008 Mohd "Computerex" Ali - borrowed his code (multiple vessels support) (borrowed code)
11 // Copyright (C) 2008 Chris "Kwan" Jeppesen - borrowed his code (peg guidance) (borrowed code)
12 // Copyright (C) 2008 Steve "agentgonzo" Arch - peg integration, offplane correction, compass, hud display (co-developer)
13 // Copyright (C) 2007-2012 Szymon "Enjo" Ender - everything else ;> (author and maintainer)
14 // All rights reserved
15 //
16 // DirectAscent.h - algorithms for direct ascent
17 // Authors - Szymon "Enjo" Ender
18 //
19 // This module calculates the appropriate launch azimuth given
20 // desired orbital inclination and desired orbit altitude. This
21 // MFD takes the planets rotation into account, which provides a
22 // much more accurate azimuth. The calculations are performed
23 // 'on the fly' (technically and methaphorically), meaning that
24 // you get info about necessary course corrections.
25 //
26 // This file is part of LaunchMFD.
27 //
28 // LaunchMFD is free software: you can redistribute it and/or modify
29 // it under the terms of the GNU General Public License as published by
30 // the Free Software Foundation, either version 3 of the License, or
31 // (at your option) any later version.
32 //
33 // LaunchMFD is distributed in the hope that it will be useful,
34 // but WITHOUT ANY WARRANTY; without even the implied warranty of
35 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36 // GNU General Public License for more details.
37 //
38 // You should have received a copy of the GNU General Public License
39 // along with LaunchMFD. If not, see <http://www.gnu.org/licenses/>.
40 // ==============================================================
41 
42 #pragma once
43 
44 #include <vector>
45 #include <string>
46 #include <sstream>
47 #include <utility>
48 
49 #include "../../BODYPHYS.h"
50 #include "../../TGTPARAM.h"
51 #include "SHIP_PARAMS.h"
52 #include "../../../lib/Systems/Systems.hpp"
53 #include "Satellite.h"
54 #include "Ship.h"
55 #include "Times.h"
56 
58 {
59 
60 public:
61  DirectAscent();
62  virtual ~DirectAscent();
63  void SetAllVars( const BODYPHYS &, const TGTPARAM &, const SHIP_PARAMS &);
64  // call before each new calculation
65  void reset_values();
66 
67 private:
68 
69 protected:
70  EnjoLib::Spherical CalculateSatellitePosition();
71  bool IsNodeInFrontOfShip();
72  EnjoLib::Vect3 CalcNode( );
73  double CalcAngDistToNode( const EnjoLib::Spherical & sph );
74  double CalcAngDistStartPosToNode();
76  double CalcAngDistInPlane( const EnjoLib::Spherical & shPos, const EnjoLib::Spherical & satPos );
77  double CalcTimeToNodeOnGround();
78 
79 protected:
80 
81  virtual bool InitInternalVars() = 0;
82  virtual double GetShipsInitialAcceleration() = 0;
83 
84  void UpdateGreatCircleShip();
85  void UpdateGreatCircleSatellite();
86  void UpdatePlaneMomentumShip();
87  void UpdatePlaneMomentumSatellite();
88 
89  double CalcSatFullRevolutionTime();
90  double CalcPlaneRotationLongitude( double waitingTime );
91 
92 
93  EnjoLib::Spherical CalcPointOnWholeGreatCircle(double angRatio, double r, double latStart, double lonStart, bool bSatellite = false );
94 
95  double CalcAngDistOfPlanes( const EnjoLib::Spherical & sph, EnjoLib::Vect3 v3SatPlaneN );
96  double CalculateAsymptore(const EnjoLib::Spherical & sphPos);
97  EnjoLib::Vect3 CalcShipVel3D(const EnjoLib::Vect3 & shPos);
98  EnjoLib::Point ConvertShipVel3Dto2D(const EnjoLib::Spherical & sphPos, const EnjoLib::Vect3 & shVel3D);
99  EnjoLib::Vect3 ConvertShipVel2Dto3D(const EnjoLib::Spherical & sphPos, const EnjoLib::Point & shVel2D);
100  EnjoLib::Vect3 Get2dPlaneY();
101  EnjoLib::Vect3 Get2dPlaneX(const EnjoLib::Spherical & sphPos);
102 
103  BODYPHYS bodyPhys; // source body's physical parameters
104  TGTPARAM tgtParam; // target's parameters
105  SHIP_PARAMS shipParams;
106 
107  // loop defining a curved path ( stores it in s_x and s_y vectors )
108  // accepts a true azimuth parameter - azimuth needed to reach a certain final velocity depending on current velocity
109  //void inner_loop( double true_azimuth = 0);
110  void inner_loop( );
111  // loop which increments the time of flying and calls inner_loop at each increment
112  void medium_loop();
113  // preparation of medium_loop for time efficient solution. Call before medium loop
114  void main_loop_prepare(bool timeEfficient);
115  // preparation of medium_loop for fuel efficient solution. Call before medium loop
116  // void main_loop_fuel_efficient_prepare();
117  // finalisation of medium_loop. Call after looping the medium_loop
118  void main_loop_finalise();
119 
120  int main_iter;
121  int iter; // number of medium loop's iterations
122  int inner_iter; // number of inner loop's iterations
123  static const int max_i; // maximal number of medium loop's iterations. Helps quiting calculations from a dead loop
124 
125  Times m_t;
126 
127  bool solNotPossible; // time efficient solution not possible (from left to right)
128  bool fuelEfSolNotPossible; // fuel efficient solution not possible (from right to left)
129 
130  double initial_rotation_vel;
131  double initial_rotation_vel_wlat; // velocity resulting from body's rotation, taking latitude into account
132 
133  double initialAccel; // ship's initial acceleration. Acceleration will be changing as ship looses fuel
134 
135  double Ldistance; // Longitudinal difference at y > 0 (final point) between distance covered by accelerating and orbit's plane.
136  double angDistance;
137  double distanceShipSatFinal; // 2D final distance between positions of the ship and the sattelite itself
138 
139  double xDistance; // x distance between positions of the ship and the satellite
140  double xPrvDistance;
141 
142  double mi; // gravitational parameter mi = GGRAV * mass_of_body
143 
144  Satellite m_satellite;
145  double target_radius; // target sattelite's radius. NOT altitude.
146  EnjoLib::Point tgt_orbit_v2_ref; // this is station's velocity which we use as reference
147  double tgt_orbit_v2_ref_module;
148 
149  Ship m_ship;
150  double sshx_excession;
151  double dvUsed;
152  double sshx_waiting; // the amount of distance you will cover by just waiting, resulting from body's rotation
153  double max_xvel; // maximal eastern velocity, after achieving which, we fly with a constant vel.
154  double latStart, lonStart, lonCurrent;
155 
156  double debug, debug2, debug3, debug4, debug5;
157  bool debugbool;
158 };
159