1 /***************************************************************************
2  * Name: gSatStelWrapper.hpp
3  *
4  * Description: Wrapper over gSatTEME class.
5  *              This class allow use Satellite orbit calculation module (gSAt) in
6  *              Stellarium 'native' mode using Stellarium objects.
7  *
8  ***************************************************************************/
9 /***************************************************************************
10  *   Copyright (C) 2006 by J.L. Canales                                    *
11  *   jlcanales.gasco@gmail.com                                  *
12  *                                                                         *
13  *   This program is free software; you can redistribute it and/or modify  *
14  *   it under the terms of the GNU General Public License as published by  *
15  *   the Free Software Foundation; either version 2 of the License, or     *
16  *   (at your option) any later version.                                   *
17  *                                                                         *
18  *   This program is distributed in the hope that it will be useful,       *
19  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
20  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
21  *   GNU General Public License for more details.                          *
22  *                                                                         *
23  *   You should have received a copy of the GNU General Public License     *
24  *   along with this program; if not, write to the                         *
25  *   Free Software Foundation, Inc.,                                       *
26  *   51 Franklin Street, Suite 500, Boston, MA  02110-1335, USA.             *
27  ***************************************************************************/
28 
29 #ifndef GSATWRAPPER_HPP
30 #define GSATWRAPPER_HPP
31 
32 #include <QString>
33 
34 #include "VecMath.hpp"
35 
36 #include "gsatellite/gSatTEME.hpp"
37 #include "gsatellite/gTime.hpp"
38 
39 //! Wrapper allowing compatibility between gsat and Stellarium/Qt.
40 //! @ingroup satellites
41 class gSatWrapper
42 {
43 public:
44 	enum Visibility
45 	{
46 		//constants for visibility prediction
47 		UNKNOWN=0,
48 		RADAR_SUN=1,
49 		VISIBLE=2,
50 		RADAR_NIGHT=3,
51 		NOT_VISIBLE=4
52 	};
53         gSatWrapper(QString designation, QString tle1,QString tle2);
54         ~gSatWrapper();
55 
56 	// Operation setEpoch
57 	//! @brief This operation update Epoch timestamp for gSatTEME object
58 	//! from Stellarium Julian Date.
59 	void setEpoch(double ai_julianDaysEpoch);
60 
61 	// Operation getTEMEPos
62 	//! @brief This operation isolate gSatTEME getPos operation.
63 	//! @return Vec3d with TEME position. Units measured in Km.
64 	Vec3d getTEMEPos() const;
65 
66 	// Operation getSunECIPos
67 	//! @brief Get Sun positions in ECI system.
68 	//! @return Vec3d with ECI position.
69 	static Vec3d getSunECIPos();
70 
71 	// Operation getTEMEVel
72 	//! @brief This operation isolate gSatTEME getVel operation.
73 	//! @return Vec3d with TEME speed. Units measured in Km/s.
74 	Vec3d getTEMEVel() const;
75 
76 	// Operation:  getSubPoint
77 	//! @brief This operation isolate getSubPoint method of gSatTEME object.
78 	//! @return Vec3d Geographical coordinates\n
79 	//!    Latitude:  Coord[0]  measured in degrees\n
80 	//!    Longitude: Coord[1]  measured in degrees\n
81         //!    Altitude:  Coord[2]  measured in Km.\n
82 	Vec3d getSubPoint() const;
83 
84 	// Operation getAltAz
85 	//! @brief This operation compute the coordinates in StelCore::FrameAltAz
86 	//! @return Vect3d Vector with coordinates (meassured in km)
87 	//! @par References
88 	//!  Orbital Coordinate Systems, Part II
89 	//!   Dr. T.S. Kelso
90 	//!   http://www.celestrak.com/columns/v02n02/
91 	Vec3d getAltAz() const;
92 
93         // Operation getSlantRange
94         //! @brief This operation compute the slant range (distance between the
95         //! satellite and the observer) and its variation/seg
96         //! @param &ao_slantRange Reference to a output variable where the method store the slant range measured in Km
97         //! @param &ao_slantRangeRate Reference to a output variable where the method store the slant range variation in Km/s
98         //! @return void
99 	void  getSlantRange(double &ao_slantRange, double &ao_slantRangeRate) const; //measured in km and km/s
100 
101         // Operation getVisibilityPredict
102         //! @brief This operation predicts the satellite visibility contidions.
103         //! This prediction can return 4 different states
104 	//!   RADAR_SUN when satellite and observer are in the sunlight
105 	//!   VISIBLE   when satellite is in sunlight and observer is in the dark. Satellite could be visible in the sky.
106         //!   RADAR_NIGHT when satellite is eclipsed by the earth shadow.
107         //!   NOT_VISIBLE The satellite is under the observer horizon
108         //! @return
109         //!     1 if RADAR_SUN
110         //!     2 if VISIBLE
111 	//!     3 if RADAR_NIGHT
112         //!     3 if NOT_VISIBLE
113         //! @par References
114         //!   Fundamentals of Astrodynamis and Applications (Third Edition) pg 898
115         //!   David A. Vallado
116 	Visibility getVisibilityPredict() const;
117 
118 	double getPhaseAngle() const;
119 	//! Get orbital period in minutes
120 	double getOrbitalPeriod() const;
121 	//! Get orbital inclination in degrees
122 	double getOrbitalInclination() const;
123 	//! Get perigee/apogee altitudes in kilometers for equatorial radius of Earth
124 	Vec2d getPerigeeApogeeAltitudes() const;
getEpoch()125 	static gTime getEpoch() { return epoch; }
126 
127 	// Operation calcObserverECIPosition
128 	//! @brief This operation computes the observer ECI coordinates in Geocentric
129 	//! Equatorial Coordinate System (IJK) for the ai_epoch time.
130         //! This position can be asumed as observer position in TEME framework without an appreciable error.
131         //! ECI axis (IJK) are parallel to StelCore::EquinoxEQ Framework but centered in the earth centre
132         //! instead the observer position.
133 	//! @par References
134 	//!  Orbital Coordinate Systems, Part II
135 	//!   Dr. T.S. Kelso
136 	//!   http://www.celestrak.com/columns/v02n02/
137         //! @param[out] ao_position Observer ECI position vector measured in Km
138         //! @param[out] ao_vel Observer ECI velocity vector measured in Km/s
139 	static void calcObserverECIPosition(Vec3d& ao_position, Vec3d& ao_vel) ;
140 
141 private:
142 	//! do the actual work to compute a cached value.
143 	static void updateSunECIPos();
144 
145 	gSatTEME *pSatellite;
146 	static gTime	 epoch;
147 
148 	// GZ We can avoid many computations (solar and observer positions for every satellite) by computing them only once for all objects.
149 	static gTime lastSunECIepoch; // store last time of computation to avoid all-1 computations.
150 	static Vec3d sunECIPos;       // enough to have these once.
151 	static Vec3d observerECIPos;
152 	static Vec3d observerECIVel;
153 	static gTime lastCalcObserverECIPosition;
154 };
155 
156 #endif
157