source: flair-src/trunk/lib/FlairSensorActuator/src/SimulatedImu.cpp

Last change on this file was 286, checked in by Sanahuja Guillaume, 3 years ago

draw vrpn axis in simulator

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