source: flair-src/branches/sanscv/lib/FlairSensorActuator/src/SimulatedImu.cpp@ 387

Last change on this file since 387 was 324, checked in by Sanahuja Guillaume, 5 years ago

removing opencv dependency

File size: 2.6 KB
Line 
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: SimulatedImu.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#ifdef CORE2_64
18
19#include "SimulatedImu.h"
20#include <FrameworkManager.h>
21#include <ImuData.h>
22#include <SpinBox.h>
23#include <GroupBox.h>
24#include <Matrix.h>
25#include <SharedMem.h>
26#include <AhrsData.h>
27#include <sstream>
28
29using std::string;
30using std::ostringstream;
31using namespace flair::core;
32using namespace flair::gui;
33
34namespace flair {
35namespace sensor {
36
37SimulatedImu::SimulatedImu(string name, uint32_t modelId,uint32_t deviceId,
38 uint8_t priority)
39 : Imu(name,false), Thread(getFrameworkManager(), name, priority) {
40 dataRate =
41 new SpinBox(GetGroupBox()->NewRow(), "data rate", " Hz", 1, 500, 1, 200);
42 ahrsData = new AhrsData((Imu *)this);
43
44 shmem = new SharedMem((Thread *)this, ShMemName(modelId, deviceId),
45 sizeof(imu_states_t));
46 SetIsReady(true);
47}
48
49SimulatedImu::~SimulatedImu() {
50 SafeStop();
51 Join();
52}
53
54string SimulatedImu::ShMemName(uint32_t modelId,uint32_t deviceId) {
55 ostringstream dev_name;
56 dev_name << "simu" << modelId << "_imu_" << deviceId;
57 return dev_name.str().c_str();
58}
59
60void SimulatedImu::Run(void) {
61 imu_states_t state;
62 ImuData *imuData;
63 GetDatas(&imuData);
64
65 SetPeriodUS((uint32_t)(1000000. / dataRate->Value()));
66
67 while (!ToBeStopped()) {
68 WaitPeriod();
69
70 if (dataRate->ValueChanged() == true) {
71 SetPeriodUS((uint32_t)(1000000. / dataRate->Value()));
72 }
73 shmem->Read((char *)&state, sizeof(imu_states_t));
74 Quaternion quaternion(state.q0, state.q1, state.q2, state.q3);
75 Vector3Df angRate(state.wx, state.wy, state.wz);
76 Vector3Df rawAcc(state.ax, state.ay, state.az);
77 Vector3Df rawMag(state.mx, state.my, state.mz);
78 Vector3Df rawGyr(state.wx, state.wy, state.wz);
79 //we do not need rotation in simulation
80 /*
81 ApplyRotation(angRate);
82 ApplyRotation(quaternion);
83 ApplyRotation(rawAcc);
84 ApplyRotation(rawMag);
85 ApplyRotation(rawGyr);*/
86 ahrsData->SetQuaternionAndAngularRates(quaternion,angRate);
87 imuData->SetRawAccMagAndGyr(rawAcc,rawMag,rawGyr);
88 imuData->SetDataTime(GetTime());
89 ahrsData->SetDataTime(GetTime());
90 ProcessUpdate(ahrsData);
91 }
92}
93
94} // end namespace sensor
95} // end namespace flair
96
97#endif
Note: See TracBrowser for help on using the repository browser.