Added DecayedException. Removed premature check.
parent
c63d209c35
commit
69744793e6
|
@ -0,0 +1,47 @@
|
|||
#ifndef DECAYEDEXCEPTION_H_
|
||||
#define DECAYEDEXCEPTION_H_
|
||||
|
||||
#include <exception>
|
||||
#include <iostream>
|
||||
#include "Julian.h"
|
||||
#include "Vector.h"
|
||||
|
||||
class DecayedException : public std::exception
|
||||
{
|
||||
public:
|
||||
DecayedException(const Julian& dt, const Vector& pos, const Vector& vel)
|
||||
: _dt(dt), _pos(pos), _vel(vel)
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~DecayedException(void) throw ()
|
||||
{
|
||||
}
|
||||
|
||||
virtual const char* what() const throw ()
|
||||
{
|
||||
return "Error: Satellite decayed";
|
||||
}
|
||||
|
||||
Julian GetDate() const
|
||||
{
|
||||
return _dt;
|
||||
}
|
||||
|
||||
Vector GetPosition() const
|
||||
{
|
||||
return _pos;
|
||||
}
|
||||
|
||||
Vector GetVelocity() const
|
||||
{
|
||||
return _vel;
|
||||
}
|
||||
|
||||
private:
|
||||
Julian _dt;
|
||||
Vector _pos;
|
||||
Vector _vel;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -3,6 +3,7 @@
|
|||
#include "Util.h"
|
||||
#include "Vector.h"
|
||||
#include "SatelliteException.h"
|
||||
#include "DecayedException.h"
|
||||
|
||||
#include <cmath>
|
||||
#include <iomanip>
|
||||
|
@ -267,11 +268,6 @@ Eci SGP4::FindPositionSDP4(const Julian& dt, double tsince) const
|
|||
xl = xmam + omgadf + xnode;
|
||||
omega = omgadf;
|
||||
|
||||
if (a < 1.0)
|
||||
{
|
||||
throw SatelliteException("Error: (a < 1.0)");
|
||||
}
|
||||
|
||||
/*
|
||||
* fix tolerance for error recognition
|
||||
*/
|
||||
|
@ -373,11 +369,6 @@ Eci SGP4::FindPositionSGP4(const Julian& dt, double tsince) const
|
|||
e = elements_.Eccentricity() - tempe;
|
||||
xl = xmp + omega + xnode + elements_.RecoveredMeanMotion() * templ;
|
||||
|
||||
if (a < 1.0)
|
||||
{
|
||||
throw SatelliteException("Error: (a < 1.0)");
|
||||
}
|
||||
|
||||
/*
|
||||
* fix tolerance for error recognition
|
||||
*/
|
||||
|
@ -538,11 +529,6 @@ Eci SGP4::CalculateFinalPositionVelocity(const Julian& dt, const double& e,
|
|||
const double rdotk = rdot - xn * temp42 * x1mth2 * sin2u;
|
||||
const double rfdotk = rfdot + xn * temp42 * (x1mth2 * cos2u + 1.5 * x3thm1);
|
||||
|
||||
if (rk < 1.0)
|
||||
{
|
||||
throw SatelliteException("Error: Satellite decayed (rk < 1.0)");
|
||||
}
|
||||
|
||||
/*
|
||||
* orientation vectors
|
||||
*/
|
||||
|
@ -572,6 +558,11 @@ Eci SGP4::CalculateFinalPositionVelocity(const Julian& dt, const double& e,
|
|||
const double zdot = (rdotk * uz + rfdotk * vz) * kXKMPER / 60.0;
|
||||
Vector velocity(xdot, ydot, zdot);
|
||||
|
||||
if (rk < 1.0)
|
||||
{
|
||||
throw DecayedException(dt, position, velocity);
|
||||
}
|
||||
|
||||
Eci eci(dt, position, velocity);
|
||||
|
||||
return eci;
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include "OrbitalElements.h"
|
||||
#include "Eci.h"
|
||||
#include "SatelliteException.h"
|
||||
#include "DecayedException.h"
|
||||
|
||||
class SGP4
|
||||
{
|
||||
|
|
|
@ -27,31 +27,59 @@ void RunTle(Tle tle, double start, double end, double inc)
|
|||
|
||||
while (running)
|
||||
{
|
||||
bool error = false;
|
||||
Vector position;
|
||||
Vector velocity;
|
||||
double tsince;
|
||||
|
||||
try
|
||||
{
|
||||
double val;
|
||||
if (first_run && current != 0.0)
|
||||
{
|
||||
/*
|
||||
* make sure first run is always as zero
|
||||
*/
|
||||
val = 0.0;
|
||||
tsince = 0.0;
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
* otherwise run as normal
|
||||
*/
|
||||
val = current;
|
||||
tsince = current;
|
||||
}
|
||||
Eci eci = model.FindPosition(val);
|
||||
|
||||
Vector position = eci.GetPosition();
|
||||
Vector velocity = eci.GetVelocity();
|
||||
Eci eci = model.FindPosition(tsince);
|
||||
position = eci.GetPosition();
|
||||
velocity = eci.GetVelocity();
|
||||
}
|
||||
catch (SatelliteException& e)
|
||||
{
|
||||
std::cerr << e.what() << std::endl;
|
||||
error = true;
|
||||
running = false;
|
||||
}
|
||||
catch (DecayedException& e)
|
||||
{
|
||||
std::cerr << e.what() << std::endl;
|
||||
|
||||
position = e.GetPosition();
|
||||
velocity = e.GetVelocity();
|
||||
|
||||
if (!first_run)
|
||||
{
|
||||
// print out position on first run
|
||||
error = true;
|
||||
}
|
||||
|
||||
running = false;
|
||||
}
|
||||
|
||||
if (!error)
|
||||
{
|
||||
std::cout << std::setprecision(8) << std::fixed;
|
||||
std::cout.width(17);
|
||||
std::cout << val << " ";
|
||||
std::cout << tsince << " ";
|
||||
std::cout.width(16);
|
||||
std::cout << position.x << " ";
|
||||
std::cout.width(16);
|
||||
|
@ -65,12 +93,8 @@ void RunTle(Tle tle, double start, double end, double inc)
|
|||
std::cout << velocity.y << " ";
|
||||
std::cout.width(14);
|
||||
std::cout << velocity.z << std::endl;
|
||||
}
|
||||
|
||||
}
|
||||
catch (SatelliteException& e)
|
||||
{
|
||||
running = false;
|
||||
}
|
||||
if ((first_run && current == 0.0) || !first_run)
|
||||
{
|
||||
if (current == end)
|
||||
|
@ -87,7 +111,6 @@ void RunTle(Tle tle, double start, double end, double inc)
|
|||
}
|
||||
}
|
||||
first_run = false;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue