00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include <iostream>
00013 #include "DMU.h"
00014
00015 using namespace O_SESSAME;
00016 using namespace std;
00017
00018 DMU* DMU::s_instance = NULL;
00019
00020 DMU::DMU(int _mode)
00021 {
00022 Initialize(_mode);
00023 }
00024
00025 DMU* DMU::Instance(int _mode)
00026 {
00027
00028
00029
00030
00031
00032
00033
00034 if (s_instance==NULL)
00035 {
00036
00037 s_instance = new DMU(_mode);
00038 }
00039 return s_instance;
00040 }
00041
00042 int DMU::Initialize(int _mode)
00043 {
00044
00045
00046
00047
00048 Vector tempVector3(3);
00049 Vector tempQuat4(4);
00050
00051 tempVector3(1) = 0.0;
00052 tempVector3(2) = 0.0;
00053 tempVector3(3) = 0.0;
00054
00055 tempQuat4(1) = 0.0;
00056 tempQuat4(2) = 0.0;
00057 tempQuat4(3) = 0.0;
00058 tempQuat4(4) = 1.0;
00059
00060 SetLocation(tempVector3);
00061 SetSensorToBodyQuaternions(tempQuat4);
00062
00063
00064
00065
00066
00067 m_prate = 200;
00068 m_tempBuffSize = 100;
00069 m_timeToler = 31250;
00070
00071 m_numread = 0;
00072 m_firstCall = 1;
00073
00074
00075 m_ptrToReadData = new adat_t[m_tempBuffSize];
00076
00077
00078 switch(_mode)
00079 {
00080 case 1:
00081 if (dmuInit((long)1024, m_prate, 0)==-1)
00082 {
00083 cout << " oops, 'dmuInit()' failed " << endl;
00084
00085 return 1;
00086 }
00087 break;
00088 case 2:
00089
00090
00091
00092 break;
00093 default:
00094 cout << " bad mode! " << endl;
00095 }
00096 return 0;
00097 }
00098
00099 void DMU::SetLocation(const Vector& _newDeviceLocation)
00100 {
00101 m_location = _newDeviceLocation;
00102 }
00103
00104 Vector DMU::GetLocation()
00105 {
00106 return m_location;
00107 }
00108
00109 void DMU::SetSensorToBodyQuaternions(const Vector& _newDeviceQuaternion)
00110 {
00111 m_sensorToBodyQuaternion = _newDeviceQuaternion;
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130 Quaternion q1( 0.0, 0.0, 0.0, 1.0);
00131
00132
00133
00134
00135 Quaternion q2( 0.5, 0.5, 0.5, -0.5);
00136
00137
00138
00139
00140 Quaternion q3( 0.5, 0.5, 0.5, 0.5);
00141
00142
00143 Rotation R_rg1_to_dmu(q1);
00144
00145
00146 Rotation R_rg2_to_dmu(q2);
00147
00148
00149 Rotation R_rg3_to_dmu(q3);
00150
00151
00152 Quaternion q0(m_sensorToBodyQuaternion);
00153 Rotation R_dmu_to_b(q0);
00154
00155
00156 Rotation R_rg1_to_b;
00157 R_rg1_to_b = R_dmu_to_b * R_rg1_to_dmu;
00158
00159
00160 Rotation R_rg2_to_b;
00161 R_rg2_to_b = R_dmu_to_b * R_rg2_to_dmu;
00162
00163
00164 Rotation R_rg3_to_b;
00165 R_rg3_to_b = R_dmu_to_b * R_rg3_to_dmu;
00166
00167
00168
00169 Quaternion q_rg1_to_b;
00170 q_rg1_to_b = R_rg1_to_b.GetQuaternion();
00171 m_dmuXToBodyQuaternion = q_rg1_to_b;
00172
00173
00174
00175 Quaternion q_rg2_to_b;
00176 q_rg2_to_b = R_rg2_to_b.GetQuaternion();
00177 m_dmuYToBodyQuaternion = q_rg2_to_b;
00178
00179
00180
00181 Quaternion q_rg3_to_b;
00182 q_rg3_to_b = R_rg3_to_b.GetQuaternion();
00183 m_dmuZToBodyQuaternion = q_rg3_to_b;
00184 }
00185
00186 Vector DMU::GetSensorToBodyQuaternion( int id )
00187 {
00188
00189 if ( id == 1 | id == 4 )
00190 {
00191
00192 return m_dmuXToBodyQuaternion;
00193 }
00194 else if ( id == 2 | id == 5 )
00195 {
00196
00197 return m_dmuYToBodyQuaternion;
00198 }
00199 else if ( id == 3 | id == 6 )
00200 {
00201
00202 return m_dmuZToBodyQuaternion;
00203 }
00204
00205
00206
00207
00208 Vector errorQuat4;
00209 errorQuat4(1) = 0.0;
00210 errorQuat4(2) = 0.0;
00211 errorQuat4(3) = 0.0;
00212 errorQuat4(4) = 1.0;
00213 return errorQuat4;
00214 }
00215
00216 void DMU::GetAnalogReading( int _channelID, DAQCard* _mycard, timeval& _timeStamp, double& _rateData )
00217 {
00218
00219 gettimeofday(&_timeStamp, NULL);
00220
00221 _rateData = (double)ADscan(_mycard->m_cardData, (_channelID-1));
00222
00223
00224 m_GetReadingTime = _timeStamp;
00225 }
00226
00227 void DMU::GetDigitalReading( int _channelID, timeval& _timeStamp, double& _rateData )
00228 {
00229
00230 gettimeofday(&_timeStamp, NULL);
00231
00232
00233 if (m_firstCall==1)
00234 {
00235 m_numread = dmuReadData(&m_ptrToReadData, m_tempBuffSize);
00236 }
00237 else if (m_firstCall==0)
00238 {
00239
00240 m_delta_t = _timeStamp.tv_usec - m_GetReadingTime.tv_usec;
00241 if (m_delta_t < 0) m_delta_t += 1000000;
00242 if (m_delta_t > m_timeToler)
00243 {
00244
00245 m_numread = dmuReadData(&m_ptrToReadData, m_tempBuffSize);
00246 }
00247 }
00248
00249
00250
00251
00252 switch (_channelID)
00253 {
00254 case 1:
00255 _rateData = m_ptrToReadData[0].xrate;
00256 break;
00257 case 2:
00258 _rateData = m_ptrToReadData[0].yrate;
00259 break;
00260 case 3:
00261 _rateData = m_ptrToReadData[0].zrate;
00262 break;
00263 case 4:
00264 _rateData = m_ptrToReadData[0].xaccel;
00265 break;
00266 case 5:
00267 _rateData = m_ptrToReadData[0].yaccel;
00268 break;
00269 case 6:
00270 _rateData = m_ptrToReadData[0].zaccel;
00271 break;
00272 case 7:
00273 _rateData = m_ptrToReadData[0].temp;
00274 break;
00275 default:
00276 cout << " illegal channel value! " << endl;
00277
00278 }
00279
00280 m_GetReadingTime = _timeStamp;
00281
00282 }
00283
00284 DMU::~DMU()
00285 {
00286
00287 delete[] m_ptrToReadData;
00288 }
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310