source: flair-src/trunk/lib/FlairSensorActuator/src/SimuImu.cpp@ 251

Last change on this file since 251 was 245, checked in by Sanahuja Guillaume, 6 years ago

added simupressuresensor

File size: 2.5 KB
RevLine 
[3]1// %flair:license{
[15]2// This file is part of the Flair framework distributed under the
3// CECILL-C License, Version 1.0.
[3]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>
[214]23#include <Matrix.h>
[3]24#include <SharedMem.h>
25#include <AhrsData.h>
26#include <sstream>
27
28using std::string;
29using std::ostringstream;
30using namespace flair::core;
31using namespace flair::gui;
32
[15]33namespace flair {
34namespace sensor {
[3]35
[158]36SimuImu::SimuImu(string name, uint32_t modelId,uint32_t deviceId,
[15]37 uint8_t priority)
[198]38 : Imu(name,false), Thread(getFrameworkManager(), name, priority) {
[55]39 dataRate =
[15]40 new SpinBox(GetGroupBox()->NewRow(), "data rate", " Hz", 1, 500, 1, 200);
41 ahrsData = new AhrsData((Imu *)this);
[158]42
43 shmem = new SharedMem((Thread *)this, ShMemName(modelId, deviceId),
[15]44 sizeof(imu_states_t));
[157]45 SetIsReady(true);
[3]46}
47
48SimuImu::~SimuImu() {
[15]49 SafeStop();
50 Join();
[3]51}
52
[158]53string 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
[3]59void SimuImu::Run(void) {
[15]60 imu_states_t state;
61 ImuData *imuData;
62 GetDatas(&imuData);
[3]63
[55]64 SetPeriodUS((uint32_t)(1000000. / dataRate->Value()));
[3]65
[15]66 while (!ToBeStopped()) {
67 WaitPeriod();
[3]68
[55]69 if (dataRate->ValueChanged() == true) {
70 SetPeriodUS((uint32_t)(1000000. / dataRate->Value()));
[15]71 }
72 shmem->Read((char *)&state, sizeof(imu_states_t));
[202]73 Quaternion quaternion(state.q0, state.q1, state.q2, state.q3);
[173]74 Vector3Df angRate(state.wx, state.wy, state.wz);
[186]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);
[198]78 //we do not need rotation in simulation
79 /*
[173]80 ApplyRotation(angRate);
81 ApplyRotation(quaternion);
[186]82 ApplyRotation(rawAcc);
83 ApplyRotation(rawMag);
[198]84 ApplyRotation(rawGyr);*/
[173]85 ahrsData->SetQuaternionAndAngularRates(quaternion,angRate);
[186]86 imuData->SetRawAccMagAndGyr(rawAcc,rawMag,rawGyr);
[15]87 imuData->SetDataTime(GetTime());
88 ahrsData->SetDataTime(GetTime());
89 ProcessUpdate(ahrsData);
90 }
[3]91}
92
93} // end namespace sensor
94} // end namespace flair
Note: See TracBrowser for help on using the repository browser.