1 | // %flair:license{
|
---|
2 | // This file is part of the Flair framework distributed under the
|
---|
3 | // CECILL-C License, Version 1.0.
|
---|
4 | // %flair:license}
|
---|
5 | // created: 2014/02/07
|
---|
6 | // filename: SimuImu.cpp
|
---|
7 | //
|
---|
8 | // author: Guillaume Sanahuja
|
---|
9 | // Copyright Heudiasyc UMR UTC/CNRS 7253
|
---|
10 | //
|
---|
11 | // version: $Id: $
|
---|
12 | //
|
---|
13 | // purpose: Class for a simulation imu
|
---|
14 | //
|
---|
15 | //
|
---|
16 | /*********************************************************************/
|
---|
17 |
|
---|
18 | #include "SimuImu.h"
|
---|
19 | #include <FrameworkManager.h>
|
---|
20 | #include <ImuData.h>
|
---|
21 | #include <SpinBox.h>
|
---|
22 | #include <GroupBox.h>
|
---|
23 | #include <Matrix.h>
|
---|
24 | #include <SharedMem.h>
|
---|
25 | #include <AhrsData.h>
|
---|
26 | #include <sstream>
|
---|
27 |
|
---|
28 | using std::string;
|
---|
29 | using std::ostringstream;
|
---|
30 | using namespace flair::core;
|
---|
31 | using namespace flair::gui;
|
---|
32 |
|
---|
33 | namespace flair {
|
---|
34 | namespace sensor {
|
---|
35 |
|
---|
36 | SimuImu::SimuImu(string name, uint32_t modelId,uint32_t deviceId,
|
---|
37 | uint8_t priority)
|
---|
38 | : Imu(name,false), Thread(getFrameworkManager(), name, priority) {
|
---|
39 | dataRate =
|
---|
40 | new SpinBox(GetGroupBox()->NewRow(), "data rate", " Hz", 1, 500, 1, 200);
|
---|
41 | ahrsData = new AhrsData((Imu *)this);
|
---|
42 |
|
---|
43 | shmem = new SharedMem((Thread *)this, ShMemName(modelId, deviceId),
|
---|
44 | sizeof(imu_states_t));
|
---|
45 | SetIsReady(true);
|
---|
46 | }
|
---|
47 |
|
---|
48 | SimuImu::~SimuImu() {
|
---|
49 | SafeStop();
|
---|
50 | Join();
|
---|
51 | }
|
---|
52 |
|
---|
53 | string SimuImu::ShMemName(uint32_t modelId,uint32_t deviceId) {
|
---|
54 | ostringstream dev_name;
|
---|
55 | dev_name << "simu" << modelId << "_imu_" << deviceId;
|
---|
56 | return dev_name.str().c_str();
|
---|
57 | }
|
---|
58 |
|
---|
59 | void SimuImu::Run(void) {
|
---|
60 | imu_states_t state;
|
---|
61 | ImuData *imuData;
|
---|
62 | GetDatas(&imuData);
|
---|
63 |
|
---|
64 | if (dataRate == NULL) {
|
---|
65 | Thread::Err("not applicable for simulation part.\n");
|
---|
66 | return;
|
---|
67 | }
|
---|
68 |
|
---|
69 | SetPeriodUS((uint32_t)(1000000. / dataRate->Value()));
|
---|
70 |
|
---|
71 | while (!ToBeStopped()) {
|
---|
72 | WaitPeriod();
|
---|
73 |
|
---|
74 | if (dataRate->ValueChanged() == true) {
|
---|
75 | SetPeriodUS((uint32_t)(1000000. / dataRate->Value()));
|
---|
76 | }
|
---|
77 | shmem->Read((char *)&state, sizeof(imu_states_t));
|
---|
78 | Quaternion quaternion(state.q0, state.q1, state.q2, state.q3);
|
---|
79 | Vector3Df angRate(state.wx, state.wy, state.wz);
|
---|
80 | Vector3Df rawAcc(state.ax, state.ay, state.az);
|
---|
81 | Vector3Df rawMag(state.mx, state.my, state.mz);
|
---|
82 | Vector3Df rawGyr(state.wx, state.wy, state.wz);
|
---|
83 | //we do not need rotation in simulation
|
---|
84 | /*
|
---|
85 | ApplyRotation(angRate);
|
---|
86 | ApplyRotation(quaternion);
|
---|
87 | ApplyRotation(rawAcc);
|
---|
88 | ApplyRotation(rawMag);
|
---|
89 | ApplyRotation(rawGyr);*/
|
---|
90 | ahrsData->SetQuaternionAndAngularRates(quaternion,angRate);
|
---|
91 | imuData->SetRawAccMagAndGyr(rawAcc,rawMag,rawGyr);
|
---|
92 | imuData->SetDataTime(GetTime());
|
---|
93 | ahrsData->SetDataTime(GetTime());
|
---|
94 | ProcessUpdate(ahrsData);
|
---|
95 | }
|
---|
96 | }
|
---|
97 |
|
---|
98 | } // end namespace sensor
|
---|
99 | } // end namespace flair
|
---|