Spacecraft Control Framework 1.0
Spacecraft Control Library
Classes | Typedefs | Functions
sc_orbit.h File Reference

Orbit mechanics functions and types, including Keplerian, spherical and cartesian elements. More...

Go to the source code of this file.

Classes

struct  orb_data_s
 Structure for storing orbit data. More...
 
struct  gps_data_s
 Data structure for the GPS model. More...
 
struct  gps_orb_out_s
 Structure for storing the orbit data output of the GPS Model. More...
 
struct  orbit_closest_point_out
 Structure for storing the data output of the closest orbit. More...
 

Typedefs

typedef struct orb_data_s orb_data_t
 Structure for storing orbit data.
 
typedef struct gps_data_s gps_data_t
 Data structure for the GPS model.
 
typedef struct gps_orb_out_s gps_orb_out_t
 Structure for storing the orbit data output of the GPS Model.
 
typedef struct orbit_closest_point_out orbit_closest_point_out
 Structure for storing the data output of the closest orbit.
 

Functions

void el_to_rv (const orb_data_t &data, ml_matrix &pos, ml_matrix &vel)
 Converts orbital elements to r and v for an elliptic orbit. More...
 
void rv_to_nearest (const ml_matrix &pos, const ml_matrix &vel, const ml_matrix &pos_target, double jD, ml_matrix &distance, ml_matrix &time)
 Compute nearest distance and time to a set of points on the earth.
 
orb_data_t rv_to_el (const ml_matrix &pos, const ml_matrix &vel, double mu=MU_EARTH)
 Converts position and velocity vectors to Keplerian orbital elements. More...
 
double r_to_true (double a, double e, double r)
 Converts distance, sma and e to true anomaly. More...
 
double rv_to_sma (double r_mag, double v_mag, double mu=MU_EARTH)
 Computes the semimajor axis given position and velocity. More...
 
double mean_to_true (double ecc, double mean)
 Computes the true anomaly from the mean anomaly. More...
 
double mean_to_ecc (double ecc, double mean)
 Generate the eccentric anomaly from the mean anomaly and the eccentricity. More...
 
double ecc_to_true (double ecc, double e)
 Computes the true anomaly from the eccentric or hyperbolic anomaly. More...
 
double ecc_to_mean (double ecc, double e)
 Converts eccentric anomaly to mean anomaly. More...
 
double true_to_mean (double ecc, double nu)
 Converts true anomaly to mean anomaly. More...
 
double mean_to_true_abs (double ecc, double mean_anom)
 Converts mean anomaly to true without wrapping. More...
 
double true_to_ecc (double ecc, double nu)
 Converts true anomaly to eccentric or hyperbolic anomaly. More...
 
double rarp_to_ecc (double ap, double per)
 Compute the eccentricity from apogee and perigee radii. More...
 
double rarp_to_sma (double ap, double per)
 Computes the semi major axis from apogee and perigee radii. More...
 
double slr (double ecc, double sma)
 Compute the semi-latus rectum. More...
 
ml_matrix cp_to_i (double inc, double raan, double w)
 Converts the transformation matrix from the perifocal frame to the inertial frame. More...
 
double orb_rate (double r, double a, double mu=MU_EARTH)
 Compute the orbital rate for non-circular orbits, or distance units other than [km]. More...
 
double orb_rate (double r)
 Compute the orbital rate for circular orbits and distance units in [km]. More...
 
double period (double a, double mu=MU_EARTH)
 Compute the orbital period. More...
 
void lin_orb (double n, ml_matrix &a, ml_matrix &b, double dt)
 Computes the linearized orbit equations. More...
 
void rv_orb_gen (const ml_matrix &el, const ml_matrix &t, ml_matrix &r, ml_matrix &v, double mu=MU_EARTH)
 Generate an orbit by propagating Keplerian elements. More...
 
void rv_orb_gen (const orb_data_t &el, const ml_matrix &t, ml_matrix &r, ml_matrix &v, double mu=MU_EARTH)
 Generate an orbit by propagating Keplerian elements. More...
 
ml_matrix cart_orb_rhs (const ml_matrix &x)
 Computes the right-hand-side of the unforced orbit equations about a mass point in cartesian coordinates. More...
 
ml_matrix cart_orb_rhs (const ml_matrix &x, const ml_matrix &a)
 Right hand side of the cartesion equations of motion. More...
 
ml_matrix satellite_visibility (const ml_matrix &from_pos, const ml_matrix &targets, double horizon_angle, double radius)
 Compute satellite visibility. More...
 
ml_matrix planetary_accelerations (const ml_matrix &pos, double jd, int center)
 Compute perturbations due to other planets aside from the center. More...
 
ml_matrix acc_planet (const ml_matrix &pos, double mu, const ml_matrix &rho)
 Acceleration due to a planet on a spacecraft within the sphere of influence of another body. More...
 
ml_matrix orbit_acquisition_dv (ml_matrix &t, const orb_data_t &elI, const orb_data_t &elF, double smaTol=0.5, double incTol=1e-3, double raTol=1e-3)
 Compute delta-v sequence to acquire orbit. More...
 
double phase_change_dv (double a0, double deltaA, double kTarget, double mu)
 Compute delta-v for a phase change. More...
 
ml_matrix circular_maneuver (double p, double r, double m)
 Compute radial force and tangential impulse for a circular maneuver. More...
 
ml_matrix gps_satellite (double jD)
 GPS satellite locations. More...
 
orbit_closest_point_out orbit_closest_point (const ml_matrix &r_ef_target, const ml_int_array &t_target, const orb_data_s &el, int n_points=1000, int n_orbits=1)
 Closest points in an orbit. More...
 
ml_matrix r_ef_from_el (const orb_data_t &el, int n_points=1000, int n_orbits=1)
 Closest r from elements.
 
ml_matrix gps_eci_state_from_data (double longitude, double latitude, double heading, double velocity, double altitude, double jd)
 ECI state from GPS data.
 
void print_orbit_data (orb_data_s orbData)
 Display the contents of the passed-in orb_data_s struct.
 

Detailed Description

Orbit mechanics functions and types, including Keplerian, spherical and cartesian elements.

Function Documentation

◆ el_to_rv()

void el_to_rv ( const orb_data_t data,
ml_matrix &  pos,
ml_matrix &  vel 
)

Converts orbital elements to r and v for an elliptic orbit.

Converts orbital elements to r and v for an elliptic orbit.

Parameters
dataOrbital elements for the satellite.
posposition "r" matrix to be returned (km).
velvelocity "v" matrix to be returned (km/s).

References cp_to_i(), orb_data_s::ecc, orb_data_s::inc, orb_data_s::mean_anom, mean_to_true(), MU_EARTH, orb_data_s::perigee, orb_data_s::raan, and orb_data_s::sma.

Referenced by FFEccDeltaElem2Hills(), FFEccHills2DeltaElem(), ImpulsiveManeuver(), orbit_acquisition_dv(), r_ef_from_el(), and galilean_moons::update().

◆ rv_to_el()

orb_data_t rv_to_el ( const ml_matrix &  pos,
const ml_matrix &  vel,
double  mu 
)

Converts position and velocity vectors to Keplerian orbital elements.

Parameters
posposition "r" matrix for the satellite (km).
velvelocity "v" matrix for the satellite (km/s).
mugravitational constant for the central body of the orbit pair (km^3/sec^2)
Returns
The Keplerian orbital elements for the satellite.

References orb_data_s::ecc, orb_data_s::inc, orb_data_s::mean_anom, orb_data_s::orb_rate, orb_rate(), orb_data_s::perigee, PI, orb_data_s::raan, orb_data_s::sma, orb_data_s::true_anom, true_to_mean(), and TWO_PI.

Referenced by ECI2MeanElements(), FFEccHills2DeltaElem(), and GetHillsMats().

◆ r_to_true()

double r_to_true ( double  a,
double  e,
double  r 
)

Converts distance, sma and e to true anomaly.

Converts distance, sma and e to true anomaly.

Parameters
asemimajor axis
eeccentricity
rdistance
Returns
true anomaly (rad)

◆ rv_to_sma()

double rv_to_sma ( double  r_mag,
double  v_mag,
double  mu 
)

Computes the semimajor axis given position and velocity.

Computes the semimajor axis given position and velocity.

Parameters
r_magPosition magnitude (length).
v_magVelocity magnitude (length/s).
muGravitational parameter (length^3/s^2).
Returns
Semimajor axis (length).

◆ mean_to_true()

double mean_to_true ( double  ecc,
double  mean_anom 
)

◆ mean_to_ecc()

double mean_to_ecc ( double  ecc,
double  mean_anom 
)

Generate the eccentric anomaly from the mean anomaly and the eccentricity.

Parameters
eccEccentricity.
mean_anomMean anomaly (rad).
Returns
Eccentric anomaly (rad).

◆ ecc_to_true()

double ecc_to_true ( double  ecc,
double  e 
)

Computes the true anomaly from the eccentric or hyperbolic anomaly.

Parameters
eccEccentricity.
eHyperbolic or Eccentric anomaly (rad).
Returns
True anomaly (rad).

◆ ecc_to_mean()

double ecc_to_mean ( double  ecc,
double  e 
)

Converts eccentric anomaly to mean anomaly.

Parameters
eccEccentricity.
hypHyperbolic anomaly (rad).
Returns
Mean anomaly (rad).

Referenced by true_to_mean().

◆ true_to_mean()

double true_to_mean ( double  ecc,
double  nu 
)

Converts true anomaly to mean anomaly.

Parameters
eccEccentricity.
nuTrue anomaly (rad).
Returns
Mean anomaly (rad).

References ecc_to_mean(), and true_to_ecc().

Referenced by Alfriend2El(), FFEccDiscreteHills(), GenerateTimeVector(), LPEccentric(), LPEccentricGVE(), rv_to_el(), TargetTrueAnom(), and TimeUntilTheta().

◆ mean_to_true_abs()

double mean_to_true_abs ( double  ecc,
double  mean_anom 
)

Converts mean anomaly to true without wrapping.

Converts mean anomaly to true without wrapping.

Parameters
eccEccentricity in radians.
mean_anomMean anomaly in radians.
Returns
The true anomaly in radians.

References mean_to_true(), PI, and TWO_PI.

◆ true_to_ecc()

double true_to_ecc ( double  ecc,
double  nu 
)

Converts true anomaly to eccentric or hyperbolic anomaly.

Parameters
eccEccentricity in radians.
nuTrue anomaly in radians.
Returns
The eccentric or hyperbolic anomaly in radians.

Referenced by true_to_mean().

◆ rarp_to_ecc()

double rarp_to_ecc ( double  ap,
double  per 
)

Compute the eccentricity from apogee and perigee radii.

Parameters
apApogee radius.
perPerigee radius.
Returns
Eccentricity.

◆ rarp_to_sma()

double rarp_to_sma ( double  ap,
double  per 
)

Computes the semi major axis from apogee and perigee radii.

Computes the semi major axis from apogee and perigee radii.

Parameters
apApogee radius.
perPerigee radius.
Returns
The semi-major axis.

◆ slr()

double slr ( double  ecc,
double  sma 
)

Compute the semi-latus rectum.

Parameters
eccEccentricity.
smaSemi major axis (or perigee radius for parabola).
Returns
Semi-latus rectum.

Referenced by ImpulsiveManeuver(), and rv_orb_gen().

◆ cp_to_i()

ml_matrix cp_to_i ( double  inc,
double  raan,
double  w 
)

Converts the transformation matrix from the perifocal frame to the inertial frame.

Parameters
incInclination (rad).
raanRight ascension of the ascending node (rad).
wArgument of perigee (rad).
Returns
The inertial frame (3,3) transformation matrix.

Referenced by el_to_rv(), gps_satellite(), and rv_orb_gen().

◆ orb_rate() [1/2]

double orb_rate ( double  r,
double  sma,
double  mu 
)

Compute the orbital rate for non-circular orbits, or distance units other than [km].

Parameters
rRadius
smaSemi major axis (inf for parabola)
muGravitational parameter
Returns
w Angular velocity

Referenced by FFEccDeltaElem2Goals(), FFEccEstimateCost(), FFEccGenerateTeamGoals(), GenerateTimeVector(), Goals2Hills(), ImpulsiveLPManeuver(), ImpulsiveManeuver(), IterativeImpulsiveManeuver(), LPCircularTimeWeight(), LPEccentricGVE(), LPEccentricTimeWeight(), MonitoringAlg(), rv_to_el(), and TimeUntilTheta().

◆ orb_rate() [2/2]

double orb_rate ( double  r)

Compute the orbital rate for circular orbits and distance units in [km].

Parameters
rRadius
Returns
w Angular velocity (rad/s)

References MU_EARTH.

◆ period()

double period ( double  a,
double  mu 
)

Compute the orbital period.

Compute the orbital period.

The units for a and mu must be consistent, for example [km] and [km3/s2]. FLT_MAX is substituted for infinity.

Parameters
aSemi-major axis
muGravitation parameter, default is Earth
Returns
p Orbital period (s)

References TWO_PI.

Referenced by GenerateTeamGoals(), orbit_closest_point(), and r_ef_from_el().

◆ lin_orb()

void lin_orb ( double  n,
ml_matrix &  a,
ml_matrix &  b,
double  dt 
)

Computes the linearized orbit equations.

If value of dT is not equal to -1 it will generate the discrete time equations.

Parameters
n(1) orbit rate (rad/s).
a(6,6) State transition matrix.
b(6,3) Input matrix.
dt(1) Time step (s).

Referenced by DiscreteHills(), and LPCircular().

◆ rv_orb_gen() [1/2]

void rv_orb_gen ( const ml_matrix &  el,
const ml_matrix &  t,
ml_matrix &  pos,
ml_matrix &  vel,
double  mu 
)

Generate an orbit by propagating Keplerian elements.

Parameters
el(6,1) Elements vector [a,i,W,w,e,M]
t(1,n) Times from 0 to infinity (sec)
pos(3,n) Position vectors for times t
vel(3,n) Velocity vectors for times t
mu(1,1) Gravitational potential

References orb_data_s::ecc, orb_data_s::inc, orb_data_s::mean_anom, orb_data_s::perigee, orb_data_s::raan, rv_orb_gen(), and orb_data_s::sma.

Referenced by orbit_acquisition_dv(), orbit_closest_point(), rv_orb_gen(), and Target().

◆ rv_orb_gen() [2/2]

void rv_orb_gen ( const orb_data_t el,
const ml_matrix &  t,
ml_matrix &  pos,
ml_matrix &  vel,
double  mu 
)

Generate an orbit by propagating Keplerian elements.

Overloaded for calling with elements of type "orb_data_s"

Parameters
el(1,1) Elements data structure
t(1,n) Times from 0 to infinity (sec)
pos(3,n) Position vectors for times t
vel(3,n) Velocity vectors for times t
mu(1,1) Gravitational potential

References cp_to_i(), orb_data_s::ecc, orb_data_s::inc, orb_data_s::mean_anom, mean_to_true(), orb_data_s::perigee, orb_data_s::raan, slr(), and orb_data_s::sma.

◆ cart_orb_rhs() [1/2]

ml_matrix cart_orb_rhs ( const ml_matrix &  x)

Computes the right-hand-side of the unforced orbit equations about a mass point in cartesian coordinates.

Parameters
x(6,1) State [x;y;z;dx/dt;dy/dt;dz/dt], pos: (km), vel: (km/s)
Returns
xDot (6,1) State derivative

References MU_EARTH.

◆ cart_orb_rhs() [2/2]

ml_matrix cart_orb_rhs ( const ml_matrix &  x,
const ml_matrix &  a 
)

Right hand side of the cartesion equations of motion.

Parameters
x(6,1) Current state vector, pos: (km), vel: (km/s).
a(3,1) Acceleration vector (km/s/s).
Returns
xDot (6,1) State derivative.

References MU_EARTH.

◆ satellite_visibility()

ml_matrix satellite_visibility ( const ml_matrix &  from_pos,
const ml_matrix &  targets,
double  horizon_angle,
double  radius 
)

Compute satellite visibility.

Parameters
from_posPosition of the viewing satellite.
targetsPositions of possibly visible satellites.
horizon_angleAngle above horizon for visibility
radiusPlanet radius.
Returns
A ml_int_array with "1" for each visible satellite and "0" for each that is not visible.

◆ planetary_accelerations()

ml_matrix planetary_accelerations ( const ml_matrix &  pos,
double  jd,
int  center 
)

Compute perturbations due to other planets aside from the center.

Currently only handles the earth, moon and sun.

Parameters
pos(3,1) Position vector wrt center
jd(1,1) Julian Date
center1 for Earth and 2 for Moon
Returns
(3,1) Acceleration

References acc_planet(), moon_vector(), MU_EARTH, MU_MOON, MU_SUN, and sun_vector().

◆ acc_planet()

ml_matrix acc_planet ( const ml_matrix &  pos,
double  mu,
const ml_matrix &  rho 
)

Acceleration due to a planet on a spacecraft within the sphere of influence of another body.

Parameters
pos(3,1) Vector of the spacecraft from the central body
mu(1) Planet's gravitational parameter
rho(3,:) Vector of the planet from the central body
Returns
(3,1) Acceleration

Referenced by planetary_accelerations().

◆ orbit_acquisition_dv()

ml_matrix orbit_acquisition_dv ( ml_matrix &  t,
const orb_data_t elI,
const orb_data_t elF,
double  smaTol,
double  incTol,
double  raTol 
)

Compute delta-v sequence to acquire orbit.

Compute delta-v sequence to acquire orbit.

Inclination and right ascension correction are a single burn. Semi-major axis correction is a two-burn Hohmann transfer set. The conditions for performing a SMA correction are:

  1. The SMA error exceeds the tolerance, AND 2. a) The final SMA is smaller than the initial, OR b) Both the inc. and r.a. error are within tolerance. The times will include the wait time for the necessary Hohmann phasing.
    Parameters
    tdelta-V time (output)
    elIInitial orbital elements
    elFFinal orbital elements
    smaTolTolerance on semi-major axis
    incTolTolerance on inclination
    raTolTolerance on right ascension
    Returns
    Matrix of delta-V's (3xn)

References au_to_q(), el_to_rv(), orb_data_s::inc, orb_data_s::mean_anom, orb_data_s::perigee, PI, orb_data_s::raan, rv_orb_gen(), orb_data_s::sma, and WrapPhase().

◆ phase_change_dv()

double phase_change_dv ( double  a0,
double  deltaA,
double  kTarget,
double  mu 
)

Compute delta-v for a phase change.

Compute delta-v for a phase change.

Parameters
a0(1,1) Initial semi-major axis
deltaA(1,1) Phase change
kTarget(1,1) Number of revolutions
mu(1,1) Planet's gravitational parameter
Returns
(1,1) Delta-v

References PI.

◆ circular_maneuver()

ml_matrix circular_maneuver ( double  p,
double  r,
double  m 
)

Compute radial force and tangential impulse for a circular maneuver.

Compute radial force and tangential impulse for a circular maneuver.

Parameters
pPeriod (min)
rRadius of orbit (m)
mMass (kg)
Returns
[Radial force (N); Tangential impulse (Ns)]

References PI.

◆ gps_satellite()

ml_matrix gps_satellite ( double  jD)

GPS satellite locations.

Models the GPS constellation very approximately using a static set of elements. Each column is the stacked [r;v] of one GPS satellite.

Parameters
jDJulian date
Returns
Position and velocity of 24 GPS satellites, (6x24)

References cp_to_i().

◆ orbit_closest_point()

orbit_closest_point_out orbit_closest_point ( const ml_matrix &  r_ef_target,
const ml_int_array &  t_target,
const orb_data_t el,
int  n_points,
int  n_orbits 
)

Closest points in an orbit.

Parameters
r_ef_targetTarget positions in the earth fixed frame
elOrbit of observing spacecraft
n_pointsNumber of points in the orbit to check
n_orbitsNumber of orbits to check
Returns
Data structure with closest points, minimum distance and time of minimun

References orb_data_s::epoch, orbit_closest_point_out::id, jd_to_jcent(), orbit_closest_point_out::julian_date, period(), orbit_closest_point_out::r, rv_orb_gen(), orb_data_s::sma, and true_earth().