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

Last change on this file since 125 was 55, checked in by Sanahuja Guillaume, 8 years ago

simu gps

File size: 2.9 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>
23#include <cvmatrix.h>
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
[15]36SimuImu::SimuImu(const FrameworkManager *parent, string name, uint32_t dev_id,
37 uint8_t priority)
38 : Imu(parent, name), Thread(parent, name, priority) {
[55]39 dataRate =
[15]40 new SpinBox(GetGroupBox()->NewRow(), "data rate", " Hz", 1, 500, 1, 200);
41 ahrsData = new AhrsData((Imu *)this);
[3]42
[15]43 ostringstream dev_name;
44 dev_name << "simu_imu_" << dev_id;
45 shmem = new SharedMem((Thread *)this, dev_name.str().c_str(),
46 sizeof(imu_states_t));
[3]47}
48
[15]49SimuImu::SimuImu(const IODevice *parent, string name, uint32_t dev_id)
50 : Imu(parent, name), Thread(parent, name, 0) {
[55]51 dataRate = NULL;
[3]52
[15]53 ostringstream dev_name;
54 dev_name << "simu_imu_" << dev_id;
55 shmem = new SharedMem((Thread *)this, dev_name.str().c_str(),
56 sizeof(imu_states_t));
[3]57}
58
59SimuImu::~SimuImu() {
[15]60 SafeStop();
61 Join();
[3]62}
63
64void SimuImu::UpdateFrom(const io_data *data) {
[15]65 if (data != NULL) {
66 cvmatrix *input = (cvmatrix *)data;
67 imu_states_t state;
[3]68
[15]69 input->GetMutex();
70 state.q0 = input->ValueNoMutex(0, 0);
71 state.q1 = input->ValueNoMutex(1, 0);
72 state.q2 = input->ValueNoMutex(2, 0);
73 state.q3 = input->ValueNoMutex(3, 0);
74 state.wx = input->ValueNoMutex(7, 0);
75 state.wy = input->ValueNoMutex(8, 0);
76 state.wz = input->ValueNoMutex(9, 0);
77 input->ReleaseMutex();
[3]78
[15]79 shmem->Write((char *)&state, sizeof(imu_states_t));
80 }
[3]81}
82
83void SimuImu::Run(void) {
[15]84 imu_states_t state;
85 ImuData *imuData;
86 GetDatas(&imuData);
[3]87
[55]88 if (dataRate == NULL) {
[15]89 Thread::Err("not applicable for simulation part.\n");
90 return;
91 }
[3]92
[55]93 SetPeriodUS((uint32_t)(1000000. / dataRate->Value()));
[3]94
[15]95 while (!ToBeStopped()) {
96 WaitPeriod();
[3]97
[55]98 if (dataRate->ValueChanged() == true) {
99 SetPeriodUS((uint32_t)(1000000. / dataRate->Value()));
[15]100 }
[3]101
[15]102 shmem->Read((char *)&state, sizeof(imu_states_t));
103 ahrsData->SetQuaternionAndAngularRates(
104 Quaternion(state.q0, state.q1, state.q2, state.q3),
105 Vector3D(state.wx, state.wy, state.wz));
[3]106
[15]107 imuData->SetDataTime(GetTime());
108 ahrsData->SetDataTime(GetTime());
[3]109
[15]110 UpdateImu();
111 ProcessUpdate(ahrsData);
112 }
[3]113}
114
115} // end namespace sensor
116} // end namespace flair
Note: See TracBrowser for help on using the repository browser.