Moved Coord into seperate files.

feature/19
Daniel Warner 2011-04-23 12:18:51 +01:00
parent dcb4469507
commit 3df6db72d2
13 changed files with 168 additions and 285 deletions

41
CoordGeodetic.cpp Normal file
View File

@ -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;
}
}

67
CoordGeodetic.h Normal file
View File

@ -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

View File

@ -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) {

View File

@ -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:

2
Eci.h
View File

@ -1,7 +1,7 @@
#ifndef ECI_H_
#define ECI_H_
#include "Coord.h"
#include "CoordGeodetic.h"
#include "Vector.h"
#include "Julian.h"

View File

@ -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"

View File

@ -74,12 +74,13 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="Coord.cpp" />
<ClCompile Include="CoordGeodetic.cpp" />
<ClCompile Include="CoordTopographic.cpp" />
<ClCompile Include="Eci.cpp" />
<ClCompile Include="Globals.cpp" />
<ClCompile Include="Julian.cpp" />
<ClCompile Include="main.cpp" />
<ClCompile Include="Observer.cpp" />
<ClCompile Include="RunTest.cpp" />
<ClCompile Include="SatelliteOrbit.cpp" />
<ClCompile Include="SGP4.cpp" />
<ClCompile Include="Timespan.cpp" />
@ -87,7 +88,8 @@
<ClCompile Include="Vector.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="Coord.h" />
<ClInclude Include="CoordGeodetic.h" />
<ClInclude Include="CoordTopographic.h" />
<ClInclude Include="Eci.h" />
<ClInclude Include="Globals.h" />
<ClInclude Include="Julian.h" />

View File

@ -15,9 +15,6 @@
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="Coord.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Julian.cpp">
<Filter>Source Files</Filter>
</ClCompile>
@ -27,9 +24,6 @@
<ClCompile Include="Globals.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="main.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Tle.cpp">
<Filter>Source Files</Filter>
</ClCompile>
@ -48,11 +42,17 @@
<ClCompile Include="SGP4.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="CoordGeodetic.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="CoordTopographic.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="RunTest.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="Coord.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Julian.h">
<Filter>Header Files</Filter>
</ClInclude>
@ -83,5 +83,11 @@
<ClInclude Include="SGP4.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="CoordGeodetic.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="CoordTopographic.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>

View File

@ -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 <list>
#include <string>
@ -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 {

View File

@ -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<unsigned int> (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
double SatelliteOrbit::Footprint(const double& altitude) {
if (altitude > 0)
return 2.0 * Globals::XKMPER() * acos(Globals::XKMPER() / (Globals::XKMPER() + altitude));
else
return 0.0;
}

View File

@ -15,8 +15,10 @@ public:
unsigned int GetOrbitNumber(const Julian& jul) const;
static double Footprint(const double& altitude);
private:
SGP4 sgdp4_;
SGP4 sgp4_;
};
#endif

View File

@ -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;
}

133
main.cpp
View File

@ -1,133 +0,0 @@
#include "Julian.h"
#include "Tle.h"
#include "SGP4.h"
#include "Globals.h"
#include "Observer.h"
#include "Coord.h"
#include <list>
#include <string>
#include <iomanip>
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