COSMOS core  1.0.2 (beta)
Comprehensive Open-architecture Solution for Mission Operations Systems
measure_trods_C.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 <stdio.h>
#include <unistd.h>
#include "vmt35_lib.h"
Include dependency graph for measure_trods_C.cpp:

Functions

int main ()
 

Function Documentation

int main ( )
45 {
46  int iretn, handle, iretn_mag;
47  avector euler;
48  //rvector ;
49  rvector magfield, magref, magdiff, stablemagfield,magCF,rod_F;
50  float magX,magY,magZ;
51  float magdiffX,magdiffY,magdiffZ;
52  float stablemagfieldX,stablemagfieldY,stablemagfieldZ;
53  float roll, pitch, yaw;
54  rvector accel,rate;
55  //struct timeval first, last, delta;
56  //struct timezone x;
57  //float timeDiff;
58  //float times[100];
59  //float sum;
60  //float avg;
61  //float stddev;
62  int i = 0;
63 
64  ofstream imu_logfile;
65  ofstream imu_lastdatapoint;
66 
67 
68 
69  //myfile.open ("example.txt");
70  imu_logfile.open ("imu_log.dat", fstream::in | fstream::out | fstream::app);
71  //imu_lastdatapoint.open ("imu_log.dat", fstream::in | fstream::out | fstream::app);
72 
73 
74 
75  iretn = microstrain_connect("/dev/ttyOS3"); //"/dev/ttyUSB0"
76 
77  if (iretn < 0)
78  {
79  printf("Error: microstrain_connect() %d\n",iretn);
80  exit (1);
81  }
82 
83  handle = iretn;
84 
85  iretn_mag = microstrain_magfield(handle, &magref);
86 
87  while (1) { //i < 1e2
88 
89  imu_lastdatapoint.open ("imu_lastdatapoint.dat",ios::trunc);
90 
91  iretn = microstrain_euler_angles(handle, &euler);
92  roll = DEGOF(euler.b);
93  pitch = DEGOF(euler.e);
94  yaw = DEGOF(euler.h);
95  magX = magfield.col[0];
96  magY = magfield.col[1];
97  magZ = magfield.col[2];
98 
99  rod_F.col[0]=1;
100  rod_F.col[1]=1;
101  rod_F.col[2]=0;
102 
103 
104 
105  magCF=rv_cross(magfield,rod_F);
106 
107 
108  iretn_mag = microstrain_magfield(handle, &magfield);
109  iretn_mag = microstrain_stab_accel_rate_magfield(handle,&accel,&rate,&stablemagfield);
110 
111 
112  stablemagfieldX = stablemagfield.col[0];
113  stablemagfieldY = stablemagfield.col[1];
114  stablemagfieldZ = stablemagfield.col[2];
115 
116  magdiff = rv_sub(stablemagfield,magfield);
117 
118  magdiffX = magdiff.col[0];
119  magdiffY = magdiff.col[1];
120  magdiffZ = magdiff.col[2];
121 
122  //
123  printf("%d: %' '3.2f %' '3.2f %' '3.2f | ",i, roll,pitch,yaw);
124  printf("%' '3.5f %' '3.5f %' '3.5f | ", magX,magY,magZ);
125  printf("%' '3.2f %' '3.2f %' '3.2f | ", magdiffX,magdiffY,magdiffZ,length_rv(magfield));
126  printf("%' '3.2f %' '3.2f %' '3.2f |%f ||", stablemagfieldX,stablemagfieldY,stablemagfieldZ,length_rv(stablemagfield));
127 
128  printf("%' '3.2f %' '3.2f %' '3.2f | %f \n", magCF.col[0],magCF.col[0],magCF.col[0],length_rv(magCF));
129 
130  //imu_logfile << i << "," << roll << "," << pitch << "," << yaw << "\n";
131  imu_lastdatapoint << i << "," << roll << "," << pitch << "," << yaw << "\n";
132 
133  imu_lastdatapoint.close();
134 
135  i++;
136  /*
137  vmt35_set_amps(0,current);
138  vmt35_set_amps(1,current);
139  vmt35_set_amps(3,0);
140  */
141  }
142 
143 
144  imu_logfile.close();
145 
146  iretn = microstrain_disconnect(handle);
147  void cssl_stop();
148 
149  return 0;
150 }
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
rvector rv_cross(rvector a, rvector b)
Take cross product of two row vectors.
Definition: vector.cpp:363