COSMOS core  1.0.2 (beta)
Comprehensive Open-architecture Solution for Mission Operations Systems
agent_physics.cpp File Reference
#include "physics/physicslib.h"
#include "math/mathlib.h"
#include "support/jsonlib.h"
#include "agent/agentclass.h"
#include "support/datalib.h"
#include "support/socketlib.h"
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
Include dependency graph for agent_physics.cpp:

Functions

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

Variables

char * output
 
gj_handle gjh
 
Agentagent
 
std::string reqjstring
 
std::string mainjstring
 
double logperiod =30
 
double newlogperiod =30
 
char logstring [AGENTMAXBUFFER-20]
 
int logcount
 
char node [200] =""
 

Function Documentation

int main ( int  argc,
char *  argv[] 
)
54 {
55  uint32_t order;
56  double dt, mjdnow, mjdaccel, lmjd, cmjd;
57  int rflag, iretn, mode;
58  FILE *fdes;
59  char fname[200];
60  char *ibuf;
61  struct stat fstat;
62  tlestruc tline;
63 
64  dt = .1;
65  mjdaccel = 1.;
66  mode = 0;
67  switch (argc)
68  {
69  case 5:
70  mjdaccel = atof(argv[4]);
71  case 4:
72  dt = atof(argv[3]);
73  case 3:
74  mode = atol(argv[2]);
75  case 2:
76  strcpy(node,argv[1]);
77  break;
78  default:
79  printf("Usage: agent_physics node [attitude_mode [dt [mjdaccel]]]\n");
80  exit(-1);
81  }
82 
83  rflag = 1;
84 
85  // Initialization stuff
86 
87  if (!(agent = new Agent(node, "physics", 2.)))
88  {
89  printf("Failed to setup server: %d\n",AGENT_ERROR_JSON_CREATE);
91  }
92 
93  order = 8;
94 
95  sprintf(fname,"%s/state.ini",get_nodedir(node).c_str());
96 
97  if ((iretn=stat(fname,&fstat)) == 0 && (fdes=fopen(fname,"r")) != NULL)
98  {
99  ibuf = (char *)calloc(1,fstat.st_size+1);
100  fgets(ibuf,fstat.st_size,fdes);
101  json_parse(ibuf, agent->cinfo);
102  free(ibuf);
103  mjdnow = agent->cinfo->node.loc.pos.eci.utc;
104  }
105  else
106  {
107  sprintf(fname,"%s/tle.ini",get_nodedir(node).c_str());
108  if ((iretn=stat(fname,&fstat)) == 0 && (iretn=load_lines(fname, agent->cinfo->tle)) > 0)
109  {
110  tline = get_line(0, agent->cinfo->tle);
111  mjdnow = currentmjd(0.);
112  lines2eci(mjdnow, agent->cinfo->tle, agent->cinfo->node.loc.pos.eci);
113  }
114  else
115  {
116  mjdnow = 55593.416667827405;
118  agent->cinfo->node.loc.pos.eci.s.col[0] = -1354152.3069408732;
119  agent->cinfo->node.loc.pos.eci.s.col[1] = 6794509.033329579;
120  agent->cinfo->node.loc.pos.eci.s.col[2] = 905.69207709436682;
121  agent->cinfo->node.loc.pos.eci.v.col[0] = 983.48186257069437;
122  agent->cinfo->node.loc.pos.eci.v.col[1] = 195.00552418716413;
123  agent->cinfo->node.loc.pos.eci.v.col[2] = 7518.5307318052819;
124  agent->cinfo->node.loc.pos.eci.a.col[0] = 1.625564;
125  agent->cinfo->node.loc.pos.eci.a.col[1] = -8.155423;
126  agent->cinfo->node.loc.pos.eci.a.col[2] = -0.000244;
127  }
128  }
129 
130  agent->cinfo->node.loc.utc = mjdnow;
131  ++agent->cinfo->node.loc.pos.eci.pass;
132 // agent->cinfo->node.phys.moi[0] = 1.;
133 // agent->cinfo->node.phys.moi[1] = 3.;
134 // agent->cinfo->node.phys.moi[2] = 5.;
135  agent->cinfo->node.phys.moi[0] = 1.;
136  agent->cinfo->node.phys.moi[1] = 3.;
137  agent->cinfo->node.phys.moi[2] = 5.;
138  agent->cinfo->node.loc.att.icrf.v = rv_smult(.017453293,rv_unity());
139  agent->cinfo->node.loc.att.icrf.s = q_eye();
141  pos_eci(&agent->cinfo->node.loc);
142 
143 /*
144  agent->cinfo->node.loc.att.lvlh.v = rv_zero();
145  agent->cinfo->node.loc.att.lvlh.s = q_eye();
146  agent->cinfo->node.loc.att.lvlh.a = rv_zero();
147  ++agent->cinfo->node.loc.att.lvlh.pass;
148  att_lvlh(&agent->cinfo->node.loc);
149  loc_update(&agent->cinfo->node.loc);
150 */
151 
155  mjdnow = agent->cinfo->node.loc.utc;
156 
157  agent->cinfo->node.utcoffset = mjdnow - currentmjd(0);
158  lmjd = currentmjd(0);
159  mjdaccel -= 1.;
160 
161  do
162  {
163  mjdnow = currentmjd(0.);
166 
167  /*
168  if (agent->cinfo->node.state == 1)
169  {
170  ipos.s.col[0] = -6605464.484;
171  ipos.s.col[1] = -2233537.982;
172  ipos.s.col[2] = 270957.434;
173  ipos.v.col[0] = -603.693;
174  ipos.v.col[1] = 877.7741;
175  ipos.v.col[2] = -7482.349;
176  orbit_init_eci(mode,mjdnow,1./dt,ipos,cinfo);
177  }
178  */
179  if (agent->cinfo->node.state == 2)
180  rflag = 0;
181 
182  COSMOS_USLEEP(1);
183  cmjd = currentmjd(0);
184  agent->cinfo->node.utcoffset += mjdaccel * (cmjd-lmjd);
185  lmjd = cmjd;
186  } while (agent->running() && rflag);
187 }
static double cmjd
Definition: agent_monitor.cpp:121
Vector moi
Definition: jsondef.h:3448
vector< tlestruc > tle
Array of Two Line Elements.
Definition: jsondef.h:4259
In units for the SGP4 propogator (not NORAD TLE itself).
Definition: convertdef.h:921
ElapsedTime dt
Definition: agent_file3.cpp:183
rvector a
Acceleration.
Definition: convertdef.h:167
double utc
UTC of Position.
Definition: convertdef.h:161
int32_t json_parse(string jstring, cosmosstruc *cinfo)
Parse JSON using Name Space.
Definition: jsonlib.cpp:4799
char ibuf[1000]
Definition: razor_imu.cpp:43
rvector a
2nd derivative: Alpha - acceleration
Definition: convertdef.h:483
void simulate_hardware(cosmosstruc *cinfo, vector< locstruc > &locvec)
Simulate Hardware data - multiple.
Definition: physicslib.cpp:937
uint32_t pass
pass indicator: allows synchronization with other attitude and position values.
Definition: convertdef.h:170
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
double utc
Master time for location, in Modified Julian Day.
Definition: convertdef.h:879
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
nodestruc node
Structure for summary information in node.
Definition: jsondef.h:4220
uint16_t running()
Check if we&#39;re supposed to be running.
Definition: agentclass.cpp:391
gj_handle gjh
Definition: agent_physics.cpp:43
rvector rv_unity(double scale)
Scaled y row vector.
Definition: vector.cpp:129
rvector s
Location.
Definition: convertdef.h:163
attstruc att
attstruc for this time.
Definition: convertdef.h:883
double utcoffset
MJD Offset between system UT and simulated UT.
Definition: jsondef.h:3590
static char fname[100]
Definition: geomag.cpp:89
uint16_t state
Operational state.
Definition: jsondef.h:3564
Definition: agentclass.h:139
qatt icrf
Definition: convertdef.h:830
tlestruc get_line(uint16_t index, vector< tlestruc > lines)
Get TLE from array of TLE&#39;s.
Definition: convertlib.cpp:3512
locstruc loc
Location structure.
Definition: jsondef.h:3596
int32_t pos_eci(locstruc *loc)
Set ECI position.
Definition: convertlib.cpp:258
vector< locstruc > gauss_jackson_propagate(gj_handle &gjh, physicsstruc &physics, locstruc &loc, double tomjd)
Definition: physicslib.cpp:2871
rvector rv_zero()
Zero row order vector.
Definition: vector.cpp:107
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...
Definition: convertlib.cpp:3612
double currentmjd(double offset)
Current UTC in Modified Julian Days.
Definition: timelib.cpp:65
string get_nodedir(string node, bool create_flag)
Get Current Node Directory.
Definition: datalib.cpp:1572
posstruc pos
posstruc for this time.
Definition: convertdef.h:881
void hardware_init_eci(cosmosstruc *cinfo, locstruc &loc)
Initialize Hardware.
Definition: physicslib.cpp:877
quaternion s
0th derivative: Quaternion
Definition: convertdef.h:479
double col[3]
Definition: vector.h:55
char node[200]
Definition: agent_physics.cpp:51
cosmosstruc * cinfo
Definition: agentclass.h:346
cartpos eci
Definition: convertdef.h:737
quaternion q_eye()
Identity quaternion.
Definition: vector.cpp:1310
#define AGENT_ERROR_JSON_CREATE
Definition: cosmos-errno.h:105
int lines2eci(double utc, vector< tlestruc >lines, cartpos &eci)
Return position from TLE set.
Definition: convertlib.cpp:3155
physicsstruc phys
Definition: jsondef.h:3597
Agent * agent
Definition: agent_physics.cpp:44
rvector v
Velocity.
Definition: convertdef.h:165

Variable Documentation

char* output
gj_handle gjh
Agent* agent
std::string reqjstring
std::string mainjstring
double logperiod =30
double newlogperiod =30
char logstring[AGENTMAXBUFFER-20]
int logcount
char node[200] =""