COSMOS core  1.0.2 (beta)
Comprehensive Open-architecture Solution for Mission Operations Systems
convertlib.cpp File Reference

Coordinate conversion library source file. More...

#include "support/convertlib.h"
#include "support/timelib.h"
#include "support/geomag.h"
#include "support/jsondef.h"
#include "support/ephemlib.h"
#include <iostream>
Include dependency graph for convertlib.cpp:

Macros

#define UNUSED_VARIABLE_LOCALDEF(x)   (void)(x)
 

Functions

int32_t loc_clear (locstruc *loc)
 Initialize locstruc. More...
 
int32_t loc_clear (locstruc &loc)
 
int32_t pos_clear (locstruc *loc)
 Initialize posstruc. More...
 
int32_t pos_clear (locstruc &loc)
 
int32_t att_clear (attstruc &att)
 Initialize attstruc. More...
 
int32_t pos_extra (locstruc *loc)
 Calculate Extra position information. More...
 
int32_t pos_extra (locstruc &loc)
 
int32_t pos_icrf (locstruc *loc)
 Set Barycentric position. More...
 
int32_t pos_icrf (locstruc &loc)
 
int32_t pos_eci (locstruc *loc)
 Set ECI position. More...
 
int32_t pos_eci (locstruc &loc)
 
int32_t pos_sci (locstruc *loc)
 Set SCI position. More...
 
int32_t pos_sci (locstruc &loc)
 
int32_t pos_geoc (locstruc *loc)
 Set Geocentric position. More...
 
int32_t pos_geoc (locstruc &loc)
 
int32_t pos_selc (locstruc *loc)
 Set Selenocentric position. More...
 
int32_t pos_selc (locstruc &loc)
 
int32_t pos_selg (locstruc *loc)
 Set Selenographic position. More...
 
int32_t pos_selg (locstruc &loc)
 
int32_t pos_geos (locstruc *loc)
 Set Geographic position. More...
 
int32_t pos_geos (locstruc &loc)
 
int32_t pos_geod (locstruc *loc)
 Set Geodetic position. More...
 
int32_t pos_geod (locstruc &loc)
 
int32_t pos_icrf2eci (locstruc *loc)
 Convert Barycentric to ECI. More...
 
int32_t pos_icrf2eci (locstruc &loc)
 
int32_t pos_eci2icrf (locstruc *loc)
 Convert ECI to Barycentric. More...
 
int32_t pos_eci2icrf (locstruc &loc)
 
int32_t pos_icrf2sci (locstruc *loc)
 Convert Barycentric to SCI. More...
 
int32_t pos_icrf2sci (locstruc &loc)
 
int32_t pos_sci2icrf (locstruc *loc)
 Convert SCI to Barycentric. More...
 
int32_t pos_sci2icrf (locstruc &loc)
 
int32_t pos_eci2geoc (locstruc *loc)
 Convert ECI to GEOC. More...
 
int32_t pos_eci2geoc (locstruc &loc)
 
int32_t pos_geoc2eci (locstruc *loc)
 Convert GEOC to ECI. More...
 
int32_t pos_geoc2eci (locstruc &loc)
 
int32_t pos_geoc2geos (locstruc *loc)
 Convert GEOC to GEOS. More...
 
int32_t pos_geoc2geos (locstruc &loc)
 
int32_t pos_geos2geoc (locstruc *loc)
 Convert GEOS to GEOC. More...
 
int32_t pos_geos2geoc (locstruc &loc)
 
int32_t geoc2geod (cartpos &geoc, geoidpos &geod)
 Convert GEOC to GEOD. More...
 
int32_t pos_geoc2geod (locstruc *loc)
 Update locstruc GEOC to GEOD. More...
 
int32_t pos_geoc2geod (locstruc &loc)
 
int32_t geod2geoc (geoidpos &geod, cartpos &geoc)
 Convert GEOD to GEOC. More...
 
int32_t pos_geod2geoc (locstruc *loc)
 Update GEOD to GEOC in locstruc. More...
 
int32_t pos_geod2geoc (locstruc &loc)
 
int32_t pos_sci2selc (locstruc *loc)
 Convert SCI to SELC. More...
 
int32_t pos_sci2selc (locstruc &loc)
 
int32_t pos_selc2sci (locstruc *loc)
 Convert SELC to SCI. More...
 
int32_t pos_selc2sci (locstruc &loc)
 
int32_t pos_selc2selg (locstruc *loc)
 Convert SELC to SELG. More...
 
int32_t pos_selc2selg (locstruc &loc)
 
int32_t pos_selg2selc (locstruc *loc)
 
int32_t pos_selg2selc (locstruc &loc)
 
double rearth (double lat)
 
int32_t att_extra (locstruc *loc)
 Calculate Extra attitude information. More...
 
int32_t att_extra (locstruc &loc)
 
int32_t att_icrf2geoc (locstruc *loc)
 
int32_t att_icrf2geoc (locstruc &loc)
 
int32_t att_geoc2icrf (locstruc *loc)
 
int32_t att_geoc2icrf (locstruc &loc)
 
int32_t att_geoc (locstruc *loc)
 
int32_t att_geoc (locstruc &loc)
 
int32_t att_icrf2selc (locstruc *loc)
 
int32_t att_icrf2selc (locstruc &loc)
 
int32_t att_selc2icrf (locstruc *loc)
 
int32_t att_selc2icrf (locstruc &loc)
 
int32_t att_selc (locstruc *loc)
 
int32_t att_selc (locstruc &loc)
 
int32_t att_icrf2lvlh (locstruc *loc)
 
int32_t att_icrf2lvlh (locstruc &loc)
 
int32_t att_icrf (locstruc *loc)
 
int32_t att_icrf (locstruc &loc)
 
int32_t att_planec2lvlh (locstruc *loc)
 Convert ITRS attitude to LVLH attitude. More...
 
int32_t att_planec2lvlh (locstruc &loc)
 
int32_t att_lvlh2planec (locstruc *loc)
 Convert LVLH attitude to ITRS attitude. More...
 
int32_t att_lvlh2planec (locstruc &loc)
 
int32_t att_lvlh2icrf (locstruc *loc)
 Convert LVLH attitude to ICRF attitude. More...
 
int32_t att_lvlh2icrf (locstruc &loc)
 
int32_t att_lvlh (locstruc *loc)
 
int32_t att_lvlh (locstruc &loc)
 
int32_t att_planec2topo (locstruc *loc)
 Planetocentric to Topo attitude. More...
 
int32_t att_planec2topo (locstruc &loc)
 
int32_t att_topo2planec (locstruc *loc)
 Topocentric to Planetocentric attitude. More...
 
int32_t att_topo2planec (locstruc &loc)
 
int32_t att_topo (locstruc *loc)
 
int32_t att_topo (locstruc &loc)
 
int32_t loc_update (locstruc *loc)
 Synchronize all frames in location structure. More...
 
int32_t loc_update (locstruc &loc)
 
int32_t teme2true (double ep0, rmatrix *rm)
 
int32_t true2teme (double ep0, rmatrix *rm)
 
int32_t true2pef (double utc, rmatrix *rm)
 
int32_t pef2true (double utc, rmatrix *rm)
 
int32_t pef2itrs (double utc, rmatrix *rm)
 
int32_t itrs2pef (double utc, rmatrix *rm)
 
int32_t mean2true (double ep0, rmatrix *pm)
 Rotate Mean of Epoch to True of Epoch. More...
 
int32_t true2mean (double ep0, rmatrix *pm)
 Rotate True of Epoch to Mean of Epoch. More...
 
int32_t mean2j2000 (double ep0, rmatrix *pm)
 Rotate Mean of Epoch to J2000. More...
 
int32_t itrs2gcrf (double utc, rmatrix *rnp, rmatrix *rm, rmatrix *drm, rmatrix *ddrm)
 ITRS to J2000 rotation matrix. More...
 
int32_t gcrf2itrs (double utc, rmatrix *rnp, rmatrix *rm, rmatrix *drm, rmatrix *ddrm)
 J2000 to ITRS rotation matrix. More...
 
int32_t j20002mean (double ep1, rmatrix *pm)
 
int32_t gcrf2j2000 (rmatrix *rm)
 
int32_t j20002gcrf (rmatrix *rm)
 
int32_t mean2mean (double ep0, double ep1, rmatrix *pm)
 
int32_t kep2eci (kepstruc &kep, cartpos &eci)
 
int32_t eci2kep (cartpos &eci, kepstruc &kep)
 
int32_t geoc2topo (gvector source, rvector targetgeoc, rvector &topo)
 Geocentric to Topocentric. More...
 
int32_t body2topo (Vector source, Vector target, Vector &topo)
 Body Centric to Topocentric. More...
 
int32_t topo2azel (rvector tpos, float &az, float &el)
 
int32_t topo2azel (Vector tpos, float &az, float &el)
 
int lines2eci (double utc, vector< tlestruc >lines, cartpos &eci)
 Return position from TLE set. More...
 
int sgp4 (double utc, tlestruc tle, cartpos &pos_teme)
 
int32_t eci2tle (double utc, cartpos eci, tlestruc &tle)
 TLE from ECI. More...
 
int tle2eci (double utc, tlestruc tle, cartpos &eci)
 
tlestruc get_line (uint16_t index, vector< tlestruc > lines)
 Get TLE from array of TLE's. More...
 
int32_t loadTLE (char *fname, tlestruc &tle)
 Load TLE from file. TODO!!! create new class for dealing with TLEs. More...
 
int32_t load_lines (string fname, vector< tlestruc > &lines)
 Load TLE from file. TODO!!! Rename Function to loadTle and create new class for dealing with TLEs. More...
 
int32_t load_lines_multi (string fname, vector< tlestruc > &lines)
 
int32_t load_stk (string filename, stkstruc &stkdata)
 Load STK elements. More...
 
int stk2eci (double utc, stkstruc &stk, cartpos &eci)
 ECI from STK data. More...
 
std::ostream & operator<< (std::ostream &out, const cartpos &a)
 
std::istream & operator>> (std::istream &in, cartpos &a)
 
std::ostream & operator<< (std::ostream &out, const cposstruc &a)
 
std::istream & operator>> (std::istream &in, cposstruc &a)
 
std::ostream & operator<< (std::ostream &out, const geoidpos &a)
 
std::istream & operator>> (std::istream &in, geoidpos &a)
 
std::ostream & operator<< (std::ostream &out, const spherpos &a)
 
std::istream & operator>> (std::istream &in, spherpos &a)
 
std::ostream & operator<< (std::ostream &out, const aattstruc &a)
 
std::istream & operator>> (std::istream &in, aattstruc &a)
 
std::ostream & operator<< (std::ostream &out, const quatatt &a)
 
std::istream & operator>> (std::istream &in, quatatt &a)
 
std::ostream & operator<< (std::ostream &out, const dcmatt &a)
 
std::istream & operator>> (std::istream &in, dcmatt &a)
 
std::ostream & operator<< (std::ostream &out, const qatt &a)
 
std::istream & operator>> (std::istream &in, qatt &a)
 
std::ostream & operator<< (std::ostream &out, const kepstruc &a)
 
std::istream & operator>> (std::istream &in, kepstruc &a)
 
std::ostream & operator<< (std::ostream &out, const bodypos &a)
 
std::istream & operator<< (std::istream &in, bodypos &a)
 
std::ostream & operator<< (std::ostream &out, const extrapos &a)
 
std::istream & operator>> (std::istream &in, extrapos &a)
 
std::ostream & operator<< (std::ostream &out, const extraatt &a)
 
std::istream & operator>> (std::istream &in, extraatt &a)
 
std::ostream & operator<< (std::ostream &out, const posstruc &a)
 
std::istream & operator>> (std::istream &in, posstruc &a)
 
std::ostream & operator<< (std::ostream &out, const attstruc &a)
 
std::istream & operator>> (std::istream &in, attstruc &a)
 
std::ostream & operator<< (std::ostream &out, const locstruc &a)
 
std::istream & operator>> (std::istream &in, locstruc &a)
 
int32_t tle2sgp4 (tlestruc tle, sgp4struc &sgp4)
 
int32_t sgp42tle (sgp4struc sgp4, tlestruc &tle)
 
int tle_checksum (char *line)
 
int32_t eci2tlestring (cartpos eci, string &tle, string ref_tle, double bstar)
 

Variables

static uint16_t tlecount
 

Detailed Description

Coordinate conversion library source file.

Macro Definition Documentation

#define UNUSED_VARIABLE_LOCALDEF (   x)    (void)(x)

Function Documentation

int32_t eci2tlestring ( cartpos  eci,
string &  tle,
string  ref_tle,
double  bstar 
)
4250 {
4251  // char tle_buffer[ref_tle.size()];
4252  char field_buffer[30];
4253  // strcpy(tle_buffer, ref_tle.c_str());
4254 
4255  // Convert to keplarian elements, compute our epoch field.
4256  string epoch;
4257  tlestruc tles; // <-- in SI units.
4258  mjd2tlef(eci.utc, epoch);
4259  eci2tle(eci.utc, eci, tles);
4260 
4261  // std::cout << "Inclination: " << DEGOF(tles.i) << std::endl;
4262  // std::cout << "Right acension of rising node: " << DEGOF(tles.raan) << std::endl;
4263  // std::cout << "Eccentricity: " << tles.e << std::endl;
4264  // std::cout << "Argument of perigee: " << DEGOF(tles.ap) << std::endl;
4265  // std::cout << "Mean anomaly: " << ((DEGOF(tles.ma) < 0) ? 360 + DEGOF(tles.ma) : DEGOF(tles.ma)) << std::endl;
4266  // std::cout << "Mean motion: " << tles.mm * 1440. / D2PI << std::endl;
4267 
4268  // Ignore the name line. Populate our epoch field.
4269  // char *line_1 = strstr(tle_buffer, "\n");
4270  char *line_1 = strstr(static_cast<char *>(&ref_tle[0]), "\n");
4271  sprintf(field_buffer, "%14s", epoch.c_str());
4272  strncpy(line_1+19, field_buffer, 14);
4273  sprintf(field_buffer, "");
4274 
4275  // Populate our fields for line 2.
4276  char *line_2 = strstr(line_1 + 1, "\n");
4277  sprintf(field_buffer, "%#08.4f", DEGOF(tles.i));
4278  strncpy(line_2+9, field_buffer, 8);
4279  sprintf(field_buffer, "%08.4f", DEGOF(tles.raan));
4280  strncpy(line_2+18, field_buffer, 8);
4281  sprintf(field_buffer, "%07d", static_cast<int>(tles.e*pow(10,7)));
4282  strncpy(line_2+27, field_buffer, 7);
4283  sprintf(field_buffer, "%#08.4f", DEGOF(tles.ap));
4284  strncpy(line_2+35, field_buffer, 8);
4285  sprintf(field_buffer, "%#08.4f", (DEGOF(tles.ma) < 0) ? 360 + DEGOF(tles.ma) : DEGOF(tles.ma));
4286  strncpy(line_2+44, field_buffer, 8);
4287  sprintf(field_buffer, "%#011.8f", tles.mm * 1440. / D2PI); // rad/min ---> rev/day
4288  strncpy(line_2+53, field_buffer, 11);
4289 
4290  // Compute our checksum (copy null character here).
4291  sprintf(field_buffer, "%1d", tle_checksum(line_2));
4292  strncpy(line_2+69, field_buffer, 2);
4293 
4294  // tle = string(tle_buffer);
4295  tle = ref_tle;
4296 
4297  return 0;
4298 }
In units for the SGP4 propogator (not NORAD TLE itself).
Definition: convertdef.h:921
static std::vector< tlestruc > tle
Definition: agent_antenna.cpp:177
double utc
UTC of Position.
Definition: convertdef.h:161
int tle_checksum(char *line)
Definition: convertlib.cpp:4234
double mm
Mean motion (radians / minute)
Definition: convertdef.h:942
double raan
Right ascension of ascending node (radians)
Definition: convertdef.h:934
int32_t eci2tle(double utc, cartpos eci, tlestruc &tle)
TLE from ECI.
Definition: convertlib.cpp:3418
#define DEGOF(rad)
Degrees of a Radian value.
Definition: math/constants.h:33
double ap
Argument of perigee (radians)
Definition: convertdef.h:938
int32_t mjd2tlef(double mjd, string &tle)
Convert mjd to the TLE epoch format.
Definition: timelib.cpp:1613
double e
Eccentricity (unitless)
Definition: convertdef.h:936
const double D2PI
Double precision 2*PI.
Definition: math/constants.h:16
double ma
Mean anomaly (radians)
Definition: convertdef.h:940
double i
Inclination (radians)
Definition: convertdef.h:932

Variable Documentation

uint16_t tlecount
static