| 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 | SetPeriodUS((uint32_t)(1000000. / dataRate->Value()));
|
---|
| 65 |
|
---|
| 66 | while (!ToBeStopped()) {
|
---|
| 67 | WaitPeriod();
|
---|
| 68 |
|
---|
| 69 | if (dataRate->ValueChanged() == true) {
|
---|
| 70 | SetPeriodUS((uint32_t)(1000000. / dataRate->Value()));
|
---|
| 71 | }
|
---|
| 72 | shmem->Read((char *)&state, sizeof(imu_states_t));
|
---|
| 73 | Quaternion quaternion(state.q0, state.q1, state.q2, state.q3);
|
---|
| 74 | Vector3Df angRate(state.wx, state.wy, state.wz);
|
---|
| 75 | Vector3Df rawAcc(state.ax, state.ay, state.az);
|
---|
| 76 | Vector3Df rawMag(state.mx, state.my, state.mz);
|
---|
| 77 | Vector3Df rawGyr(state.wx, state.wy, state.wz);
|
---|
| 78 | //we do not need rotation in simulation
|
---|
| 79 | /*
|
---|
| 80 | ApplyRotation(angRate);
|
---|
| 81 | ApplyRotation(quaternion);
|
---|
| 82 | ApplyRotation(rawAcc);
|
---|
| 83 | ApplyRotation(rawMag);
|
---|
| 84 | ApplyRotation(rawGyr);*/
|
---|
| 85 | ahrsData->SetQuaternionAndAngularRates(quaternion,angRate);
|
---|
| 86 | imuData->SetRawAccMagAndGyr(rawAcc,rawMag,rawGyr);
|
---|
| 87 | imuData->SetDataTime(GetTime());
|
---|
| 88 | ahrsData->SetDataTime(GetTime());
|
---|
| 89 | ProcessUpdate(ahrsData);
|
---|
| 90 | }
|
---|
| 91 | }
|
---|
| 92 |
|
---|
| 93 | } // end namespace sensor
|
---|
| 94 | } // end namespace flair
|
---|