1 /* 2 * Copyright 2013 Daniel Warner <contact@danrw.com> 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef SGP4_H_ 18 #define SGP4_H_ 19 20 #include <keplerian_toolbox/detail/visibility.hpp> 21 #include "DecayedException.h" 22 #include "Eci.h" 23 #include "OrbitalElements.h" 24 #include "SatelliteException.h" 25 #include "Tle.h" 26 27 /** 28 * @mainpage 29 * 30 * This documents the SGP4 tracking library. 31 */ 32 33 /** 34 * @brief The simplified perturbations model 4 propagater. 35 */ 36 class KEP_TOOLBOX_DLL_PUBLIC SGP4 37 { 38 public: SGP4(const Tle & tle)39 SGP4(const Tle &tle) : elements_(tle) 40 { 41 Initialise(); 42 } 43 ~SGP4()44 virtual ~SGP4() 45 { 46 } 47 48 void SetTle(const Tle &tle); 49 Eci FindPosition(double tsince) const; 50 Eci FindPosition(const DateTime &date) const; 51 52 private: 53 struct CommonConstants { 54 double cosio; 55 double sinio; 56 double eta; 57 double t2cof; 58 double a3ovk2; 59 double x1mth2; 60 double x3thm1; 61 double x7thm1; 62 double aycof; 63 double xlcof; 64 double xnodcf; 65 double c1; 66 double c4; 67 double omgdot; // secular rate of omega (radians/sec) 68 double xnodot; // secular rate of xnode (radians/sec) 69 double xmdot; // secular rate of xmo (radians/sec) 70 }; 71 72 struct NearSpaceConstants { 73 double c5; 74 double omgcof; 75 double xmcof; 76 double delmo; 77 double sinmo; 78 double d2; 79 double d3; 80 double d4; 81 double t3cof; 82 double t4cof; 83 double t5cof; 84 }; 85 86 struct DeepSpaceConstants { 87 double gsto; 88 double zmol; 89 double zmos; 90 /* 91 * whether the deep space orbit is 92 * geopotential resonance for 12 hour orbits 93 */ 94 bool resonance_flag; 95 /* 96 * whether the deep space orbit is 97 * 24h synchronous resonance 98 */ 99 bool synchronous_flag; 100 /* 101 * lunar / solar constants for epoch 102 * applied during DeepSpaceSecular() 103 */ 104 double sse; 105 double ssi; 106 double ssl; 107 double ssg; 108 double ssh; 109 /* 110 * lunar / solar constants 111 * used during DeepSpaceCalculateLunarSolarTerms() 112 */ 113 double se2; 114 double si2; 115 double sl2; 116 double sgh2; 117 double sh2; 118 double se3; 119 double si3; 120 double sl3; 121 double sgh3; 122 double sh3; 123 double sl4; 124 double sgh4; 125 double ee2; 126 double e3; 127 double xi2; 128 double xi3; 129 double xl2; 130 double xl3; 131 double xl4; 132 double xgh2; 133 double xgh3; 134 double xgh4; 135 double xh2; 136 double xh3; 137 /* 138 * used during DeepSpaceCalcDotTerms() 139 */ 140 double d2201; 141 double d2211; 142 double d3210; 143 double d3222; 144 double d4410; 145 double d4422; 146 double d5220; 147 double d5232; 148 double d5421; 149 double d5433; 150 double del1; 151 double del2; 152 double del3; 153 }; 154 155 struct IntegratorValues { 156 double xndot; 157 double xnddt; 158 double xldot; 159 }; 160 161 struct IntegratorConstants { 162 /* 163 * integrator constants 164 */ 165 double xfact; 166 double xlamo; 167 168 /* 169 * integrator values for epoch 170 */ 171 struct IntegratorValues values_0; 172 }; 173 174 struct IntegratorParams { 175 /* 176 * integrator values 177 */ 178 double xli; 179 double xni; 180 double atime; 181 /* 182 * itegrator values for current d_atime_ 183 */ 184 struct IntegratorValues values_t; 185 }; 186 187 void Initialise(); 188 Eci FindPositionSDP4(const double tsince) const; 189 Eci FindPositionSGP4(double tsince) const; 190 Eci CalculateFinalPositionVelocity(const double tsince, const double e, const double a, const double omega, 191 const double xl, const double xnode, const double xincl, const double xlcof, 192 const double aycof, const double x3thm1, const double x1mth2, 193 const double x7thm1, const double cosio, const double sinio) const; 194 void DeepSpaceInitialise(const double eosq, const double sinio, const double cosio, const double betao, 195 const double theta2, const double betao2, const double xmdot, const double omgdot, 196 const double xnodot); 197 void DeepSpaceCalculateLunarSolarTerms(const double tsince, double &pe, double &pinc, double &pl, double &pgh, 198 double &ph) const; 199 void DeepSpacePeriodics(const double tsince, double &em, double &xinc, double &omgasm, double &xnodes, 200 double &xll) const; 201 void DeepSpaceSecular(const double tsince, double &xll, double &omgasm, double &xnodes, double &em, double &xinc, 202 double &xn) const; 203 void DeepSpaceCalcDotTerms(struct IntegratorValues &values) const; 204 void DeepSpaceIntegrator(const double delt, const double step2, const struct IntegratorValues &values) const; 205 void Reset(); 206 207 /* 208 * flags 209 */ 210 bool use_simple_model_; 211 bool use_deep_space_; 212 213 /* 214 * the constants used 215 */ 216 struct CommonConstants common_consts_; 217 struct NearSpaceConstants nearspace_consts_; 218 struct DeepSpaceConstants deepspace_consts_; 219 struct IntegratorConstants integrator_consts_; 220 mutable struct IntegratorParams integrator_params_; 221 222 /* 223 * the orbit data 224 */ 225 OrbitalElements elements_; 226 227 static const struct SGP4::CommonConstants Empty_CommonConstants; 228 static const struct SGP4::NearSpaceConstants Empty_NearSpaceConstants; 229 static const struct SGP4::DeepSpaceConstants Empty_DeepSpaceConstants; 230 static const struct SGP4::IntegratorConstants Empty_IntegratorConstants; 231 static const struct SGP4::IntegratorParams Empty_IntegratorParams; 232 }; 233 234 #endif 235