COSMOS core  1.0.2 (beta)
Comprehensive Open-architecture Solution for Mission Operations Systems
measure_trods.cpp File Reference
#include <iostream>
#include <fstream>
#include <time.h>
#include "microstrain_lib.h"
#include "timelib.h"
#include <sys/time.h>
#include "mathlib.h"
Include dependency graph for measure_trods.cpp:

Functions

int main ()
 

Function Documentation

int main ( )
41 {
42  int iretn, handle, iretn_mag;
43  avector euler;
44  //rvector ;
45  rvector magfield, magref, magdiff, stablemagfield;
46  float magX,magY,magZ;
47  float magdiffX,magdiffY,magdiffZ;
48  float stablemagfieldX,stablemagfieldY,stablemagfieldZ;
49  float roll, pitch, yaw;
50  rvector accel,rate;
51 
52  //struct timeval first, last, delta;
53  //struct timezone x;
54  //float timeDiff;
55  //float times[100];
56  //float sum;
57  //float avg;
58  //float stddev;
59  int i = 0;
60 
61  ofstream imu_logfile;
62  ofstream imu_lastdatapoint;
63 
64 
65 
66  //myfile.open ("example.txt");
67  imu_logfile.open ("imu_log.dat", fstream::in | fstream::out | fstream::app);
68  //imu_lastdatapoint.open ("imu_log.dat", fstream::in | fstream::out | fstream::app);
69 
70 
71 
72  iretn = microstrain_connect("/dev/ttyOS3"); //"/dev/ttyUSB0"
73 
74  if (iretn < 0)
75  {
76  printf("Error: microstrain_connect() %d\n",iretn);
77  exit (1);
78  }
79 
80  handle = iretn;
81 
82  iretn_mag = microstrain_magfield(handle, &magref);
83 
84  while (1) { //i < 1e2
85 
86  imu_lastdatapoint.open ("imu_lastdatapoint.dat",ios::trunc);
87 
88  iretn = microstrain_euler_angles(handle, &euler);
89  roll = DEGOF(euler.b);
90  pitch = DEGOF(euler.e);
91  yaw = DEGOF(euler.h);
92  magX = magfield.col[0];
93  magY = magfield.col[1];
94  magZ = magfield.col[2];
95 
96 
97  iretn_mag = microstrain_magfield(handle, &magfield);
98  iretn_mag = microstrain_stab_accel_rate_magfield(handle,&accel,&rate,&stablemagfield);
99 
100 
101  stablemagfieldX = stablemagfield.col[0];
102  stablemagfieldY = stablemagfield.col[1];
103  stablemagfieldZ = stablemagfield.col[2];
104 
105  magdiff = rv_sub(magref,magfield);
106 
107  magdiffX = magdiff.col[0];
108  magdiffY = magdiff.col[1];
109  magdiffZ = magdiff.col[2];
110 
111  //
112  printf("%d: %' '3.2f %' '3.2f %' '3.2f | ",i, roll,pitch,yaw);
113  printf("%' '3.5f %' '3.5f %' '3.5f | ", magX,magY,magZ);
114  //printf("%' '3.2f %' '3.2f %' '3.2f | ", magdiffX,magdiffY,magdiffZ,length_rv(magfield));
115  printf("%' '3.2f %' '3.2f %' '3.2f | %f \n", stablemagfieldX,stablemagfieldY,stablemagfieldZ,length_rv(stablemagfield));
116 
117 
118  //imu_logfile << i << "," << roll << "," << pitch << "," << yaw << "\n";
119  imu_lastdatapoint << i << "," << roll << "," << pitch << "," << yaw << "\n";
120 
121  imu_lastdatapoint.close();
122 
123  i++;
124 
125  }
126 
127 
128  imu_logfile.close();
129 
130  iretn = microstrain_disconnect(handle);
131  void cssl_stop();
132 
133  return 0;
134 }
3 element generic row vector
Definition: vector.h:53
int i
Definition: rw_test.cpp:37
double length_rv(rvector v)
Length of row vector.
Definition: vector.cpp:748
int iretn
Definition: rw_test.cpp:37
app
Definition: imu_stream_plot.py:339
double e
Elevation.
Definition: vector.h:282
double b
Bank.
Definition: vector.h:284
3 element attitude vector.
Definition: vector.h:277
#define DEGOF(rad)
Degrees of a Radian value.
Definition: math/constants.h:33
int32_t cssl_stop()
Definition: cssl_lib.cpp:86
gige_handle * handle
Definition: kpc9612p_recv.cpp:33
double col[3]
Definition: vector.h:55
double h
Heading.
Definition: vector.h:280
rvector rv_sub(rvector a, rvector b)
Subtract two vectors.
Definition: vector.cpp:315