From 3df6db72d2356ab0827821ffa3c20e461efa4e97 Mon Sep 17 00:00:00 2001 From: Daniel Warner Date: Sat, 23 Apr 2011 12:18:51 +0100 Subject: [PATCH] Moved Coord into seperate files. --- CoordGeodetic.cpp | 41 +++++++++ CoordGeodetic.h | 67 +++++++++++++++ Coord.cpp => CoordTopographic.cpp | 42 +--------- Coord.h => CoordTopographic.h | 66 +-------------- Eci.h | 2 +- Observer.h | 3 +- Rewrite.vcxproj | 8 +- Rewrite.vcxproj.filters | 24 ++++-- testmain.cpp => RunTest.cpp | 13 +-- SatelliteOrbit.cpp | 47 +++++------ SatelliteOrbit.h | 4 +- Timespan.cpp | 3 + main.cpp | 133 ------------------------------ 13 files changed, 168 insertions(+), 285 deletions(-) create mode 100644 CoordGeodetic.cpp create mode 100644 CoordGeodetic.h rename Coord.cpp => CoordTopographic.cpp (54%) rename Coord.h => CoordTopographic.h (51%) rename testmain.cpp => RunTest.cpp (91%) delete mode 100644 main.cpp diff --git a/CoordGeodetic.cpp b/CoordGeodetic.cpp new file mode 100644 index 0000000..436f625 --- /dev/null +++ b/CoordGeodetic.cpp @@ -0,0 +1,41 @@ +#include "CoordGeodetic.h" + +CoordGeodetic::CoordGeodetic(const CoordGeodetic& b) { + + lat_ = b.lat_; + lon_ = b.lon_; + alt_ = b.alt_; +} + +CoordGeodetic& CoordGeodetic::operator =(const CoordGeodetic& b) { + + if (this != &b) { + lat_ = b.lat_; + lon_ = b.lon_; + alt_ = b.alt_; + } + + return (*this); +} + +bool CoordGeodetic::operator ==(const CoordGeodetic& b) const { + + if (lat_ == b.lat_ && + lon_ == b.lon_ && + alt_ == b.alt_) { + return true; + } else { + return false; + } +} + +bool CoordGeodetic::operator !=(const CoordGeodetic& b) const { + + if (lat_ == b.lat_ && + lon_ == b.lon_ && + alt_ == b.alt_) { + return false; + } else { + return true; + } +} diff --git a/CoordGeodetic.h b/CoordGeodetic.h new file mode 100644 index 0000000..98714cc --- /dev/null +++ b/CoordGeodetic.h @@ -0,0 +1,67 @@ +#ifndef COORDGEODETIC_H_ +#define COORDGEODETIC_H_ + +class CoordGeodetic { +public: + + CoordGeodetic() + : lat_(0.0), lon_(0.0), alt_(0.0) { + } + + /* + * radians + */ + CoordGeodetic(double latitude, double longitude, double altitude) + : lat_(latitude), lon_(longitude), alt_(altitude) { + } + + CoordGeodetic(const CoordGeodetic& g); + + virtual ~CoordGeodetic() { + }; + + CoordGeodetic & operator =(const CoordGeodetic& b); + bool operator ==(const CoordGeodetic& b) const; + bool operator !=(const CoordGeodetic& b) const; + + void SetLatitude(const double latitude) { + lat_ = latitude; + } + + void SetLongitude(const double longitude) { + lon_ = longitude; + } + + void SetAltitude(const double altitude) { + alt_ = altitude; + } + + double GetLatitude() const { + return lat_; + } + + double GetLongitude() const { + return lon_; + } + + double GetAltitude() const { + return alt_; + } + +private: + /* + * radians (north positive, south negative) + */ + double lat_; + /* + * radians (east positive, west negative) + */ + double lon_; + /* + * kilometers + */ + double alt_; +}; + +#endif + diff --git a/Coord.cpp b/CoordTopographic.cpp similarity index 54% rename from Coord.cpp rename to CoordTopographic.cpp index e25f1af..ee4f4d7 100644 --- a/Coord.cpp +++ b/CoordTopographic.cpp @@ -1,44 +1,4 @@ -#include "Coord.h" - -CoordGeodetic::CoordGeodetic(const CoordGeodetic& b) { - - lat_ = b.lat_; - lon_ = b.lon_; - alt_ = b.alt_; -} - -CoordGeodetic& CoordGeodetic::operator =(const CoordGeodetic& b) { - - if (this != &b) { - lat_ = b.lat_; - lon_ = b.lon_; - alt_ = b.alt_; - } - - return (*this); -} - -bool CoordGeodetic::operator ==(const CoordGeodetic& b) const { - - if (lat_ == b.lat_ && - lon_ == b.lon_ && - alt_ == b.alt_) { - return true; - } else { - return false; - } -} - -bool CoordGeodetic::operator !=(const CoordGeodetic& b) const { - - if (lat_ == b.lat_ && - lon_ == b.lon_ && - alt_ == b.alt_) { - return false; - } else { - return true; - } -} +#include "CoordTopographic.h" CoordTopographic::CoordTopographic(const CoordTopographic& b) { diff --git a/Coord.h b/CoordTopographic.h similarity index 51% rename from Coord.h rename to CoordTopographic.h index 276085c..d8fea8e 100644 --- a/Coord.h +++ b/CoordTopographic.h @@ -1,67 +1,5 @@ -#ifndef COORD_H_ -#define COORD_H_ - -class CoordGeodetic { -public: - - CoordGeodetic() - : lat_(0.0), lon_(0.0), alt_(0.0) { - } - - /* - * radians - */ - CoordGeodetic(double latitude, double longitude, double altitude) - : lat_(latitude), lon_(longitude), alt_(altitude) { - } - - CoordGeodetic(const CoordGeodetic& g); - - virtual ~CoordGeodetic() { - }; - - CoordGeodetic & operator =(const CoordGeodetic& b); - bool operator ==(const CoordGeodetic& b) const; - bool operator !=(const CoordGeodetic& b) const; - - void SetLatitude(const double latitude) { - lat_ = latitude; - } - - void SetLongitude(const double longitude) { - lon_ = longitude; - } - - void SetAltitude(const double altitude) { - alt_ = altitude; - } - - double GetLatitude() const { - return lat_; - } - - double GetLongitude() const { - return lon_; - } - - double GetAltitude() const { - return alt_; - } - -private: - /* - * radians (north positive, south negative) - */ - double lat_; - /* - * radians (east positive, west negative) - */ - double lon_; - /* - * kilometers - */ - double alt_; -}; +#ifndef COORDTOPOGRAPHIC_H_ +#define COORDTOPOGRAPHIC_H_ class CoordTopographic { public: diff --git a/Eci.h b/Eci.h index 3af2ea4..340fd28 100644 --- a/Eci.h +++ b/Eci.h @@ -1,7 +1,7 @@ #ifndef ECI_H_ #define ECI_H_ -#include "Coord.h" +#include "CoordGeodetic.h" #include "Vector.h" #include "Julian.h" diff --git a/Observer.h b/Observer.h index ad1ffbd..2e7553f 100644 --- a/Observer.h +++ b/Observer.h @@ -1,7 +1,8 @@ #ifndef OBSERVER_H_ #define OBSERVER_H_ -#include "Coord.h" +#include "CoordGeodetic.h" +#include "CoordTopographic.h" #include "Julian.h" #include "Eci.h" diff --git a/Rewrite.vcxproj b/Rewrite.vcxproj index 2babb6f..cba0858 100644 --- a/Rewrite.vcxproj +++ b/Rewrite.vcxproj @@ -74,12 +74,13 @@ - + + - + @@ -87,7 +88,8 @@ - + + diff --git a/Rewrite.vcxproj.filters b/Rewrite.vcxproj.filters index 423268e..3799d23 100644 --- a/Rewrite.vcxproj.filters +++ b/Rewrite.vcxproj.filters @@ -15,9 +15,6 @@ - - Source Files - Source Files @@ -27,9 +24,6 @@ Source Files - - Source Files - Source Files @@ -48,11 +42,17 @@ Source Files + + Source Files + + + Source Files + + + Source Files + - - Header Files - Header Files @@ -83,5 +83,11 @@ Header Files + + Header Files + + + Header Files + \ No newline at end of file diff --git a/testmain.cpp b/RunTest.cpp similarity index 91% rename from testmain.cpp rename to RunTest.cpp index 6fbda6e..3f74fc0 100644 --- a/testmain.cpp +++ b/RunTest.cpp @@ -1,9 +1,10 @@ #include "Julian.h" #include "Tle.h" -#include "SGDP4.h" +#include "SGP4.h" #include "Globals.h" #include "Observer.h" -#include "Coord.h" +#include "CoordGeodetic.h" +#include "CoordTopographic.h" #include #include @@ -14,11 +15,11 @@ void RunTle(Tle tle, double start, double end, double inc) { double current = start; - SGDP4 model; + SGP4 model; model.SetTle(tle); bool running = true; bool first_run = true; - std::cout << " " << std::setprecision(0) << tle.GetNoradNumber() << " xx" << std::endl; + std::cout << " " << std::setprecision(0) << tle.NoradNumber() << " xx" << std::endl; while (running) { try { double val; @@ -142,7 +143,7 @@ void RunTest(const char* infile) { */ if (!got_first_line) { - if (Tle::IsValidLine(line, Tle::LINE_ONE)) { + if (Tle::IsValidLine(line, 1)) { /* * store line and now read in second line */ @@ -180,7 +181,7 @@ void RunTest(const char* infile) { /* * following line must be the second line */ - if (Tle::IsValidLine(line2, Tle::LINE_TWO)) { + if (Tle::IsValidLine(line2, 2)) { Tle tle("Test", line1, line2); RunTle(tle, 0.0, 1440.0, 120.0); } else { diff --git a/SatelliteOrbit.cpp b/SatelliteOrbit.cpp index edd64b0..698af08 100644 --- a/SatelliteOrbit.cpp +++ b/SatelliteOrbit.cpp @@ -8,48 +8,43 @@ SatelliteOrbit::~SatelliteOrbit(void) { void SatelliteOrbit::SetTle(const Tle& tle) { - sgdp4_.SetTle(tle); + sgp4_.SetTle(tle); } bool SatelliteOrbit::IsGeostationary() { -#if 0 - if (sgdp4_.MeanMotion() == 0.0) + + if (sgp4_.MeanMotion() == 0.0) return true; /* - radius of apogee + radius of apogee the distance from the centre of the planet to the point in the orbit furthest away from the planet - */ - const double apogee_altitude = sgdp4_.RecoveredSemiMajorAxis() * (1.0 + sgdp4_.Eccentricity()) - Globals::XKMPER(); + */ + const double apogee_altitude = sgp4_.RecoveredSemiMajorAxis() * (1.0 + sgp4_.Eccentricity()) - Globals::XKMPER(); /* * check if almost same speed as earth * or altitude is over 35000 km */ - if (fabs(sgdp4_.MeanMotion() - Globals::OMEGA_E()) < 0.0005 || apogee_altitude > 35000) + if (fabs(sgp4_.MeanMotion() - Globals::OMEGA_E()) < 0.0005 || apogee_altitude > 35000) return true; else -#endif return false; } -unsigned int SatelliteOrbit::GetOrbitNumber(const Julian& jul) const{ -#if 0 - double diff = jul.SpanMin(sgdp4_.Epoch()); - - return (unsigned int)floor((sgdp4_.MeanMotion() * 1440.0 / Globals::TWOPI() + - diff * sgdp4_.BStar() * Globals::AE()) * diff + - sgdp4_.MeanAnomoly() / Globals::TWOPI()) + sgdp4_.OrbitNumber() - 1.0; -#endif - return 0; +unsigned int SatelliteOrbit::GetOrbitNumber(const Julian& jul) const { + + double diff = jul.SpanMin(sgp4_.Epoch()); + + return static_cast (floor((sgp4_.MeanMotion() * 1440.0 / Globals::TWOPI() + + diff * sgp4_.BStar() * Globals::AE()) * diff + + sgp4_.MeanAnomoly() / Globals::TWOPI())) + sgp4_.OrbitNumber() - 1; } -#if 0 -/* same formulas, but the one from predict is nicer */ -//sat->footprint = 2.0 * xkmper * acos (xkmper/sat->pos.w); -sat->footprint = 12756.33 * acos(xkmper / (xkmper + sat->alt)); -age = sat->jul_utc - sat->jul_epoch; -sat->orbit = (long) floor((sat->tle.xno * xmnpda / twopi + - age * sat->tle.bstar * ae) * age + - sat->tle.xmo / twopi) + sat->tle.revnum - 1; -#endif \ No newline at end of file +double SatelliteOrbit::Footprint(const double& altitude) { + + if (altitude > 0) + return 2.0 * Globals::XKMPER() * acos(Globals::XKMPER() / (Globals::XKMPER() + altitude)); + else + return 0.0; +} \ No newline at end of file diff --git a/SatelliteOrbit.h b/SatelliteOrbit.h index d56d9f2..8054490 100644 --- a/SatelliteOrbit.h +++ b/SatelliteOrbit.h @@ -15,8 +15,10 @@ public: unsigned int GetOrbitNumber(const Julian& jul) const; + static double Footprint(const double& altitude); + private: - SGP4 sgdp4_; + SGP4 sgp4_; }; #endif diff --git a/Timespan.cpp b/Timespan.cpp index 8a2e3a7..210fdf3 100644 --- a/Timespan.cpp +++ b/Timespan.cpp @@ -5,6 +5,9 @@ Timespan::Timespan(void) { } +/* + * time_span is days and fraction of a day + */ Timespan::Timespan(const double time_span) { time_span_ = time_span; } diff --git a/main.cpp b/main.cpp deleted file mode 100644 index eb5d825..0000000 --- a/main.cpp +++ /dev/null @@ -1,133 +0,0 @@ -#include "Julian.h" -#include "Tle.h" -#include "SGP4.h" -#include "Globals.h" -#include "Observer.h" -#include "Coord.h" - -#include -#include -#include - -void FindSatellite(const Julian& time_start, const Julian& time_end) { - - /* - * half a second - */ - static const double delta = 1.0 / (60.0 * 60.0 * 24.0 * 2.0); - - //while (fabs(time_end - time_start) > delta) { - - //} - -} - -void GeneratePassList(const CoordGeodetic& geo, const SGP4& model, const Julian& date) { - Observer obs(geo); - Eci eci; - model.FindPosition(eci, date); - - CoordTopographic topo = obs.GetLookAngle(eci); - - /* - * set start and end date - */ - Julian time0 = date; - Julian time1 = date; - time1.AddDay(10.0); - - /* - * step throw period with 1 minute increments - */ - for (Julian jd = date; jd <= time1; jd.AddMin(1.0)) { - - } -} - -int main() { - - Tle tle = Tle("UK-DMC 2 ", - "1 35683U 09041C 11089.11558659 .00000272 00000-0 54146-4 0 8712", - "2 35683 98.0762 348.1067 0001434 99.8921 260.2456 14.69414094 89293"); - - CoordGeodetic geo(Globals::Deg2Rad(51.360242), Globals::Deg2Rad(0.101473), 0.07); - - SGP4 sgp4_model; - sgp4_model.SetTle(tle); - Julian date; - - GeneratePassList(geo, sgp4_model, date); - - - return 0; -} - -#if 0 - -http://olifantasia.com/projects/gnuradio/mdvh/weather_sat/weather_sat_scripts_without_capture_files_2010061701/decoding/poes-weather-hrpt-decoder/hrpt-decoder-1.0.0.2/satellite/predict/ - -xmnpda = 1440.0 - - /* same formulas, but the one from predict is nicer */ - //sat->footprint = 2.0 * xkmper * acos (xkmper/sat->pos.w); - sat->footprint = 12756.33 * acos (xkmper / (xkmper+sat->alt)); - age = sat->jul_utc - sat->jul_epoch; - sat->orbit = (long) floor((sat->tle.xno * xmnpda/twopi + - age * sat->tle.bstar * ae) * age + - sat->tle.xmo/twopi) + sat->tle.revnum - 1; - -bool TSat::IsGeostationary(void) -{ - /* This function returns a 1 if the satellite - appears to be in a geostationary orbit - - Circular orbit at an altitude of 35 800 km over the equator. - A satellite moving with the Earth's rotation in a geostationary - orbit has a period of 23 hours, 56 minutes and 4 seconds. - */ - double sma, aalt; - - if(meanmo == 0.0) - return true; - - sma = 331.25*exp(log(1440.0/meanmo)*(2.0/3.0)); - aalt = sma*(1.0+eccn)-xkmper; - - if(fabs(meanmo-omega_E) < 0.0005 || // allmost same speed as earth - aalt > 35000) // altitude is over 35000 km - return true; - else - return false; -} - -// latitude in radians -bool TSat::DoesRise(double lat) -{ - /* This function returns a true if the satellite can ever rise - above the horizon of the ground station. -*/ - double lin, sma, apogee; - bool rc = false; - - if(meanmo == 0.0) - return rc; - else { - lin = incl; - - if(lin >= 90.0) - lin=180.0-lin; - - sma = 331.25*exp(log(1440.0/meanmo)*(2.0/3.0)); - apogee = sma*(1.0+eccn)-xkmper; - - if((acos2(xkmper/(apogee+xkmper))+lin*deg2rad) > fabs(lat)) - rc = true; - else - rc = false; - } - - return rc; -} - -#endif -