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

Command line simulator. More...

#include "physics/physicslib.h"
#include "math/mathlib.h"
#include "support/jsonlib.h"
#include "support/ephemlib.h"
#include <cmath>
#include <stdio.h>
#include <stdlib.h>
Include dependency graph for testengine.cpp:

Macros

#define MMCORRECT   0.0
 

Functions

int main (int argc, char *argv[])
 

Variables

cosmosstruccosmos_data
 
stkstruc stk
 

Detailed Description

Command line simulator.

Macro Definition Documentation

#define MMCORRECT   0.0

Function Documentation

int main ( int  argc,
char *  argv[] 
)
49 {
50  int iretn;
51  kepstruc kep;
52  cartpos ipos;
53  locstruc tloc, iloc;
54  double localtime;
55  double dt, dp, maxr, minr, mjdnow, mjdbase, mjdlast, tp, cp;
56  double radius;
57  double deltas, deltav;
58  double rwomg;
59  double ralp=0., mtrx=0., mtry=0., mtrz=0.;
60  uint32_t order = 8;
61  rvector torque, mtorque, rtorque1, rtorque2, bearth, mmoment, ftorque;
62  int mode;
63  char stkname[50], tstring[100];
64  const char *tpointer;
65 
66  if (argc != 6)
67  {
68  printf("Usage: testengine node mode deltat deltap totalp\n");
69  exit (1);
70  }
71 
72  // seconds
73  dt = atof(argv[3]);
74 
75  // printing
76  dp = atof(argv[4]);
77 
78  // total time
79  tp = atof(argv[5]);
80 
81  node_init(argv[1],cosmos_data);
82 
83  // mode is just for attitude
84  // mode = 0, free propagation for attitude
85  // mode = 1, force LVLH
86  mode = atol(argv[2]);
87 
91 
92  // STK: CDR
93  // STK: a(6578km),e(0deg),i(45deg),raan(0deg),ea(0deg),mm()
94  strcpy(stkname,"stk_cdr_j2000.txt");
95  if (load_stk(stkname, stk)<2)
96  exit(1);
97 
98  // STK
99  mjdbase = mjdnow = stk.pos[1].utc;
100  if ((iretn=stk2eci(mjdnow, stk, ipos)) < 0)
101  {
102  printf("Error: stk2eci()\n");
103  exit(iretn);
104  }
105  radius = length_rv(ipos.s);
106  sqrt(GM/(radius*radius*radius));
107 
108  // JERS
109  /*
110 mjdbase = mjdnow = 49809.15208333333;
111 ipos.s.col[0] = 4762230.08;
112 ipos.s.col[1] = -165142.097;
113 ipos.s.col[2] = 5052273.733;
114 ipos.v.col[0] = 5356.758;
115 ipos.v.col[1] = -1669.669;
116 ipos.v.col[2] = -5090.863;
117 */
118 
119  //STK Me
120  /*
121 mjdbase = mjdnow = 55593.416666669997;
122 ipos.s.col[0] = -1354250.647;
123 ipos.s.col[1] = 6794489.492;
124 ipos.s.col[2] = 153.839;
125 ipos.v.col[0] = 983.319318;
126 ipos.v.col[1] = 195.821067;
127 ipos.v.col[2] = 7518.530795;
128 */
129 
130  // STK (Miguel)
131  /*
132 mjdbase = mjdnow = 55927.79166667;
133 ipos.s.col[0] = 3905510.;
134 ipos.s.col[1] = 5722420.;
135 ipos.s.col[2] = -1.03369e-10;
136 ipos.v.col[0] = 828.335;
137 ipos.v.col[1] = -565.334;
138 ipos.v.col[2] = 7518.5;
139 */
140 
141  // Midstar
142  /*
143 load_lines("midstar.tle",&tle);
144 mjdbase = mjdnow = tle.mjd;
145 ipos.s.col[0] = 327679.002;
146 ipos.s.col[1] = 6866364.173;
147 ipos.s.col[2] = -528.566;
148 ipos.v.col[0] = -5277.99;
149 ipos.v.col[1] = 248.735;
150 ipos.v.col[2] = 5488.55;
151 gauss_jackson_init_tle(order,dt,tle.mjd,tle,cosmos_data);
152 line2eci(cosmos_data->node.mjd,&tle,&ipos);
153 printf("%.15g\t%f\t%f\t%f\t",tle.mjd,ipos.s.col[0],ipos.s.col[1],ipos.s.col[2]);
154 printf("%f\t%f\t%f\n",ipos.v.col[0],ipos.v.col[1],ipos.v.col[2]);
155 */
156 
157 
158  iloc.pos.eci = ipos;
159  pos_eci(&iloc);
160  //iloc.att.lvlh.s = q_roty(DPI2);
161  //iloc.att.lvlh.v = rv_smult(D2PI,rv_unitx());
162  iloc.att.lvlh.s = q_eye();
163  iloc.att.lvlh.v = rv_zero();
164  iloc.att.lvlh.a = rv_zero();
165  att_lvlh2planec(&iloc);
166  pos_clear(iloc);
167  iloc.pos.geoc.utc = mjdnow;
168  pos_geoc(&iloc);
169 
170  // propagator
171  gj_handle gjh;
173  order,
174  mode,
175  dt, //s
176  mjdnow, // modified julian date
177  ipos, // initial ECI position
178  iloc.att.icrf, // initial ICRF attitude
180  cosmos_data->node.loc);
181 
182  mjdnow = cosmos_data->node.loc.utc;
183 
185  if (!dp)
186  {
187  dp = dt;
188  tp = kep.period;
189  }
190 
191  maxr = 0.;
192  minr = 10. * cosmos_data->node.loc.pos.geos.s.r;
193 // cosmos_data->node.loc.pos.geod.s.lat;
194  mjdbase = mjdnow;
195  mjdlast = mjdnow + tp/86400.;
196  cp = 0;
197  cosmos_data->device[cosmos_data->devspec.rw[0]].rw.omg = rwomg = 0;
198  cosmos_data->node.phys.moi[0] = 2.3;
199  cosmos_data->node.phys.moi[1] = 2.6;
200  cosmos_data->node.phys.moi[2] = 2.7;
201  tpointer = tstring;
202  strcpy(tstring,"(\"info_powuse\">10.)");
203  //strcpy(tstring,"(1+1)");
204  radius = json_equation(tpointer, cosmos_data);
205  do
206  {
207 
209  localtime = atan2(cosmos_data->node.loc.pos.icrf.s.col[1], cosmos_data->node.loc.pos.icrf.s.col[0]);
210  if (localtime < 0.)
211  localtime += D2PI;
212  localtime = kep.raan + DPI - localtime;
213  if (localtime < 0.)
214  localtime += D2PI;
215 
216  mjdnow += dt/86400.;
217  cp += dt;
218 
220 
221  tloc = cosmos_data->node.loc;
222  tloc.att.lvlh.s = q_eye();
223  tloc.att.lvlh.v = rv_zero();
224  att_lvlh2icrf(&tloc);
225  att_icrf2lvlh(&tloc);
226  att_lvlh2icrf(&tloc);
227 
228 // torque = calc_control_torque(dt,tloc,cosmos_data);
229 // calc_hardware_torque(cosmos_data->node.loc,torque,&rtorque1,&rtorque2,&mtorque,&ralp,&mtrx,&mtry,&mtrz,cosmos_data);
230  ftorque = rv_add(rtorque1,rv_add(rtorque2,mtorque));
231  ftorque = drotate(q_conjugate(cosmos_data->node.loc.att.icrf.s),ftorque);
232 
233  rwomg += ralp * dt;
234  // cosmos_data->dnode[0].rw[0].omg += cosmos_data->dnode[0].rw[0].ralp * dt;
235  // cosmos_data->dnode[0].rw[0].ralp = length_rv(rtorque2) / cosmos_data->node.rw[0].mom.col[2];
236 
238  mmoment = rv_smult(length_rv(mtorque)/length_rv(bearth),rv_normal(rv_cross(bearth,mtorque)));
239  // cosmos_data->dnode[0].mtr[0].rfld = mmoment.col[0];
240  // cosmos_data->dnode[0].mtr[1].rfld = mmoment.col[1];
241  // cosmos_data->dnode[0].mtr[2].rfld = mmoment.col[2];
242 
243  rtorque1 = drotate(q_conjugate(cosmos_data->node.loc.att.icrf.s),rtorque1);
244  rtorque2 = drotate(q_conjugate(cosmos_data->node.loc.att.icrf.s),rtorque2);
245  mtorque = drotate(q_conjugate(cosmos_data->node.loc.att.icrf.s),mtorque);
246 
247  // cosmos_data->node.phys.ftorque = rv_zero();
248  cosmos_data->node.phys.ftorque = torque;
249  // cosmos_data->node.phys.ftorque = ftorque;
250 
251  if (cp >= dp)
252  {
253  cp = 0;
255  if (deltas > DPI)
257  deltav = length_rv(rv_sub(tloc.att.icrf.v,cosmos_data->node.loc.att.icrf.v));
258  printf("%.15g\t%12.6f\t",cosmos_data->node.utc,1440.*(cosmos_data->node.utc-mjdbase));
259  printf("%.10g\t%.10g\t%.5g\t",DEGOF(cosmos_data->node.loc.pos.geod.s.lat),DEGOF(cosmos_data->node.loc.pos.geod.s.lon),cosmos_data->node.loc.pos.geod.s.h/1000.);
260  printf("%.10g\t%.10g\t%.10g\t%.10g\t",cosmos_data->node.loc.att.lvlh.s.d.x,cosmos_data->node.loc.att.lvlh.s.d.y,cosmos_data->node.loc.att.lvlh.s.d.z,cosmos_data->node.loc.att.lvlh.s.w);
261  printf("%.10g\t%.10g\t%.10g\t",cosmos_data->node.loc.att.lvlh.v.col[0],cosmos_data->node.loc.att.lvlh.v.col[1],cosmos_data->node.loc.att.lvlh.v.col[2]);
262  printf("%.10g\t%.10g\t%.10g\t",cosmos_data->node.loc.att.lvlh.a.col[0],cosmos_data->node.loc.att.lvlh.a.col[1],cosmos_data->node.loc.att.lvlh.a.col[2]);
263  printf("%.10g\t%.10g\t%.10g\t",torque.col[0],torque.col[1],torque.col[2]);
264  printf("%.10g\t%.10g\t%.10g\t",cosmos_data->node.phys.ftorque[0],cosmos_data->node.phys.ftorque[1],cosmos_data->node.phys.ftorque[2]);
265  printf("%.10g\t%.10g\t%.10g\t",mtorque.col[0],mtorque.col[1],mtorque.col[2]);
266  printf("%.10g\t%.10g\t",rwomg,ralp);
267  printf("%.10g\t%.10g\t%.10g\t",mtrx,mtry,mtrz);
268  printf("%.10g\t%.10g\t",deltas,deltav);
269  printf("\n");
270  fflush(stdout);
271  }
272 // mjdnext = currentmjd(cosmos_data->node.utcoffset);
273  if (cosmos_data->node.loc.pos.geos.s.r < minr)
274  minr = cosmos_data->node.loc.pos.geos.s.r;
275  if (cosmos_data->node.loc.pos.geos.s.r > maxr)
276  maxr= cosmos_data->node.loc.pos.geos.s.r;
277  } while (mjdnow < mjdlast && cosmos_data->node.loc.pos.geod.s.h > 8600.);
278  printf("\n");
279 }
rvector bearth
Earth magnetic vector in ITRS for this time and location.
Definition: convertdef.h:754
double y
Y value.
Definition: vector.h:114
Vector moi
Definition: jsondef.h:3448
svector s
Position vector.
Definition: convertdef.h:318
Gauss-Jackson integration handle.
Definition: physicsdef.h:98
int32_t eci2kep(cartpos &eci, kepstruc &kep)
Definition: convertlib.cpp:2934
rvector rv_add(rvector a, rvector b)
Add two row vectors.
Definition: vector.cpp:299
cposstruc * pos
Array of positions.
Definition: convertdef.h:1006
ElapsedTime dt
Definition: agent_file3.cpp:183
3 element generic row vector
Definition: vector.h:53
spherpos geos
Definition: convertdef.h:743
double utc
UTC of Position.
Definition: convertdef.h:161
rvector a
2nd derivative: Alpha - acceleration
Definition: convertdef.h:483
cvector d
Orientation.
Definition: vector.h:405
Cartesian full position structure.
Definition: convertdef.h:158
double length_rv(rvector v)
Length of row vector.
Definition: vector.cpp:748
quaternion q_conjugate(quaternion q)
Definition: vector.cpp:1010
int iretn
Definition: rw_test.cpp:37
void gauss_jackson_init_eci(gj_handle &gjh, uint32_t order, int32_t mode, double dt, double utc, cartpos ipos, qatt iatt, physicsstruc &physics, locstruc &loc)
Initialize Gauss-Jackson orbit using ECI state vector.
Definition: physicslib.cpp:2479
cartpos geoc
Definition: convertdef.h:739
Vector ftorque
Definition: jsondef.h:3437
double utc
Master time for location, in Modified Julian Day.
Definition: convertdef.h:879
double utc
Overall Node time.
Definition: jsondef.h:3592
double x
X value.
Definition: vector.h:112
int32_t att_lvlh2icrf(locstruc *loc)
Convert LVLH attitude to ICRF attitude.
Definition: convertlib.cpp:2035
vector< uint16_t > rw
Definition: jsondef.h:3913
qatt lvlh
Definition: convertdef.h:827
#define GM
SI Mass * Gravitational Constant for Earth.
Definition: convertdef.h:79
rvector v
1st derivative: Omega - angular velocity
Definition: convertdef.h:481
rvector rv_smult(double a, rvector b)
Multiply row vector by scalar.
Definition: vector.cpp:266
#define JPL_MOON
Definition: convertdef.h:119
quaternion q_fmult(rvector r1, quaternion q2)
rvector quaternion multiply
Definition: vector.cpp:1079
double json_equation(const char *&ptr, cosmosstruc *cinfo)
Return the results of a JSON equation.
Definition: jsonlib.cpp:4294
vector< devicestruc > device
Vector of all general (common) information for devices (components) in node.
Definition: jsondef.h:4238
nodestruc node
Structure for summary information in node.
Definition: jsondef.h:4220
int32_t node_init(string node, cosmosstruc *cinfo)
Initialize Node configuration.
Definition: jsonlib.cpp:10832
int32_t pos_clear(locstruc *loc)
Initialize posstruc.
Definition: convertlib.cpp:77
quaternion q_smult(double a, quaternion b)
Multiply quaternion by scalar.
Definition: vector.cpp:1151
rvector s
Location.
Definition: convertdef.h:163
double period
Orbital Period in seconds.
Definition: convertdef.h:536
attstruc att
attstruc for this time.
Definition: convertdef.h:883
cosmosstruc * cosmos_data
Definition: testengine.cpp:45
rvector rv_normal(rvector v)
Normalize row order vector.
Definition: vector.cpp:212
double utc
UTC as Modified Julian Day.
Definition: convertdef.h:218
qatt icrf
Definition: convertdef.h:830
rvector rv_quaternion2axis(quaternion q)
Quaternion to row vector axis and angle.
Definition: mathlib.cpp:194
locstruc loc
Location structure.
Definition: jsondef.h:3596
int32_t pos_geoc(locstruc *loc)
Set Geocentric position.
Definition: convertlib.cpp:366
#define DEGOF(rad)
Degrees of a Radian value.
Definition: math/constants.h:33
int32_t pos_eci(locstruc *loc)
Set ECI position.
Definition: convertlib.cpp:258
double h
Height in meters.
Definition: vector.h:229
stkstruc stk
Definition: testengine.cpp:46
vector< locstruc > gauss_jackson_propagate(gj_handle &gjh, physicsstruc &physics, locstruc &loc, double tomjd)
Definition: physicslib.cpp:2871
double raan
Right Ascension of the Ascending Node in radians.
Definition: convertdef.h:549
rvector rv_unitz(double scale)
Scaled z row vector.
Definition: vector.cpp:140
gj_handle gjh
Definition: agent_node.cpp:80
double lon
Longitude in radians.
Definition: vector.h:227
double w
Rotation.
Definition: vector.h:407
rvector rv_zero()
Zero row order vector.
Definition: vector.cpp:107
Classical elements structure.
Definition: convertdef.h:529
#define JPL_EARTH
Definition: convertdef.h:112
posstruc pos
posstruc for this time.
Definition: convertdef.h:881
double z
Z value.
Definition: vector.h:116
gvector s
Position vector.
Definition: convertdef.h:263
double lat
Latitude in radians.
Definition: vector.h:225
const double D2PI
Double precision 2*PI.
Definition: math/constants.h:16
quaternion s
0th derivative: Quaternion
Definition: convertdef.h:479
int32_t att_icrf2lvlh(locstruc *loc)
Definition: convertlib.cpp:1822
double col[3]
Definition: vector.h:55
cartpos eci
Definition: convertdef.h:737
quaternion q_eye()
Identity quaternion.
Definition: vector.cpp:1310
geoidpos geod
Definition: convertdef.h:741
double r
Radius in meters.
Definition: vector.h:174
int32_t jplpos(long from, long to, double utc, cartpos *pos)
Position from JPL Ephemeris.
Definition: ephemlib.cpp:128
devspecstruc devspec
Structure for devices (components) special data in node, by type.
Definition: jsondef.h:4241
int32_t att_lvlh2planec(locstruc *loc)
Convert LVLH attitude to ITRS attitude.
Definition: convertlib.cpp:1943
static string node
Definition: agent_monitor.cpp:126
const double DPI
Double precision PI.
Definition: math/constants.h:14
cartpos icrf
Definition: convertdef.h:736
rvector rv_sub(rvector a, rvector b)
Subtract two vectors.
Definition: vector.cpp:315
rvector rv_cross(rvector a, rvector b)
Take cross product of two row vectors.
Definition: vector.cpp:363
Definition: convertdef.h:876
int32_t load_stk(string filename, stkstruc &stkdata)
Load STK elements.
Definition: convertlib.cpp:3792
physicsstruc phys
Definition: jsondef.h:3597
rvector drotate(quaternion q, rvector v)
Rotate a row vector using a quaternion.
Definition: mathlib.cpp:2261
double utc2tt(double mjd)
Convert UTC to TT.
Definition: timelib.cpp:884
int stk2eci(double utc, stkstruc &stk, cartpos &eci)
ECI from STK data.
Definition: convertlib.cpp:3842

Variable Documentation

cosmosstruc* cosmos_data
stkstruc stk