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

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

maj for armv5te

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
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 if (dataRate == NULL) {
[15]65 Thread::Err("not applicable for simulation part.\n");
66 return;
67 }
[3]68
[55]69 SetPeriodUS((uint32_t)(1000000. / dataRate->Value()));
[3]70
[15]71 while (!ToBeStopped()) {
72 WaitPeriod();
[3]73
[55]74 if (dataRate->ValueChanged() == true) {
75 SetPeriodUS((uint32_t)(1000000. / dataRate->Value()));
[15]76 }
77 shmem->Read((char *)&state, sizeof(imu_states_t));
[202]78 Quaternion quaternion(state.q0, state.q1, state.q2, state.q3);
[173]79 Vector3Df angRate(state.wx, state.wy, state.wz);
[186]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);
[198]83 //we do not need rotation in simulation
84 /*
[173]85 ApplyRotation(angRate);
86 ApplyRotation(quaternion);
[186]87 ApplyRotation(rawAcc);
88 ApplyRotation(rawMag);
[198]89 ApplyRotation(rawGyr);*/
[173]90 ahrsData->SetQuaternionAndAngularRates(quaternion,angRate);
[186]91 imuData->SetRawAccMagAndGyr(rawAcc,rawMag,rawGyr);
[15]92 imuData->SetDataTime(GetTime());
93 ahrsData->SetDataTime(GetTime());
94 ProcessUpdate(ahrsData);
95 }
[3]96}
97
98} // end namespace sensor
99} // end namespace flair
Note: See TracBrowser for help on using the repository browser.