source: flair-src/trunk/lib/FlairSensorActuator/src/Imu.cpp @ 157

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

singleton manager

File size: 3.8 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/01/16
6//  filename:   Imu.cpp
7//
8//  author:     Guillaume Sanahuja
9//              Copyright Heudiasyc UMR UTC/CNRS 7253
10//
11//  version:    $Id: $
12//
13//  purpose:    Virtual class for Imu
14//
15//
16/*********************************************************************/
17
18#include "Imu.h"
19#include <FrameworkManager.h>
20#include <Tab.h>
21#include <TabWidget.h>
22#include <GroupBox.h>
23#include <GridLayout.h>
24#include <DataPlot1D.h>
25#include <ImuData.h>
26#include <OneAxisRotation.h>
27
28using std::string;
29using namespace flair::core;
30using namespace flair::gui;
31
[15]32namespace flair {
33namespace sensor {
[3]34
[137]35Imu::Imu(string name) : IODevice(getFrameworkManager(), name) {
[15]36  imuData = new ImuData(this);
[3]37
[15]38  // station sol
[137]39  mainTab = new Tab(getFrameworkManager()->GetTabWidget(), name);
[15]40  tab = new TabWidget(mainTab->NewRow(), name);
41  sensorTab = new Tab(tab, "Reglages");
42  setupGroupbox = new GroupBox(sensorTab->NewRow(), name);
43  rotation = new OneAxisRotation(sensorTab->NewRow(), "post rotation");
[3]44}
45
[137]46Imu::Imu(const IODevice *parent,std::string name) : IODevice(parent, name) {
[15]47  imuData = new ImuData(this);
48  mainTab = NULL;
49  tab = NULL;
50  sensorTab = NULL;
51  setupGroupbox = NULL;
52  rotation = NULL;
[3]53}
54
55Imu::~Imu() {
[15]56  if (mainTab != NULL)
57    delete mainTab;
[3]58}
59
[15]60void Imu::GetDatas(ImuData **outImuData) const { *outImuData = imuData; }
[55]61
[99]62OneAxisRotation *Imu::GetOneAxisRotation(void) const {
63  return rotation;
64}
65
[3]66void Imu::UpdateImu() {
[15]67  if (rotation == NULL) {
68    Err("not applicable for simulation part.\n");
69    return;
70  }
71  Vector3D rawAcc, rawMag, rawGyr;
72  imuData->GetRawAccMagAndGyr(rawAcc, rawMag, rawGyr);
73  rotation->ComputeRotation(rawAcc);
74  rotation->ComputeRotation(rawGyr);
75  rotation->ComputeRotation(rawMag);
76  imuData->SetRawAccMagAndGyr(rawAcc, rawMag, rawGyr);
[3]77}
78
[15]79GroupBox *Imu::GetGroupBox(void) const { return setupGroupbox; }
[3]80
[15]81Layout *Imu::GetLayout(void) const { return sensorTab; }
[3]82
83void Imu::LockUserInterface(void) const {
[15]84  if (sensorTab == NULL) {
85    Err("not applicable for simulation part.\n");
86    return;
87  }
88  sensorTab->setEnabled(false);
[3]89}
90
91void Imu::UnlockUserInterface(void) const {
[15]92  if (sensorTab == NULL) {
93    Err("not applicable for simulation part.\n");
94    return;
95  }
96  sensorTab->setEnabled(true);
[3]97}
98
99void Imu::UseDefaultPlot(void) {
[15]100  if (tab == NULL) {
101    Err("not applicable for simulation part.\n");
102    return;
103  }
[3]104
[15]105  plotTab = new Tab(tab, "IMU");
106  axPlot = new DataPlot1D(plotTab->NewRow(), "acc_x", -10, 10);
107  axPlot->AddCurve(imuData->Element(ImuData::RawAx));
108  ayPlot = new DataPlot1D(plotTab->LastRowLastCol(), "acc_y", -10, 10);
109  ayPlot->AddCurve(imuData->Element(ImuData::RawAy));
110  azPlot = new DataPlot1D(plotTab->LastRowLastCol(), "acc_z", -10, 10);
111  azPlot->AddCurve(imuData->Element(ImuData::RawAz));
[3]112
[15]113  if (plotTab == NULL)
114    plotTab = new Tab(tab, "IMU");
115  gxPlot = new DataPlot1D(plotTab->NewRow(), "gyr_x", -500, 500);
116  gxPlot->AddCurve(imuData->Element(ImuData::RawGxDeg));
117  gyPlot = new DataPlot1D(plotTab->LastRowLastCol(), "gyr_y", -500, 500);
118  gyPlot->AddCurve(imuData->Element(ImuData::RawGyDeg));
119  gzPlot = new DataPlot1D(plotTab->LastRowLastCol(), "gyr_z", -500, 500);
120  gzPlot->AddCurve(imuData->Element(ImuData::RawGzDeg));
[3]121
[15]122  if (plotTab == NULL)
123    plotTab = new Tab(tab, "IMU");
124  mxPlot = new DataPlot1D(plotTab->NewRow(), "mag_x", -500, 500);
125  mxPlot->AddCurve(imuData->Element(ImuData::RawMx));
126  myPlot = new DataPlot1D(plotTab->LastRowLastCol(), "mag_y", -500, 500);
127  myPlot->AddCurve(imuData->Element(ImuData::RawMy));
128  mzPlot = new DataPlot1D(plotTab->LastRowLastCol(), "mag_z", -500, 500);
129  mzPlot->AddCurve(imuData->Element(ImuData::RawMz));
[3]130}
131
[15]132Tab *Imu::GetPlotTab(void) const { return plotTab; }
[3]133
134} // end namespace sensor
135} // end namespace flair
Note: See TracBrowser for help on using the repository browser.