1 | // %flair:license{
|
---|
2 | // This file is part of the Flair framework distributed under the
|
---|
3 | // CECILL-C License, Version 1.0.
|
---|
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 |
|
---|
28 | using std::string;
|
---|
29 | using namespace flair::core;
|
---|
30 | using namespace flair::gui;
|
---|
31 |
|
---|
32 | namespace flair {
|
---|
33 | namespace sensor {
|
---|
34 |
|
---|
35 | Imu::Imu(const FrameworkManager *parent, string name) : IODevice(parent, name) {
|
---|
36 | imuData = new ImuData(this);
|
---|
37 |
|
---|
38 | // station sol
|
---|
39 | mainTab = new Tab(parent->GetTabWidget(), name);
|
---|
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");
|
---|
44 | }
|
---|
45 |
|
---|
46 | Imu::Imu(const IODevice *parent, std::string name) : IODevice(parent, name) {
|
---|
47 | imuData = new ImuData(this);
|
---|
48 | mainTab = NULL;
|
---|
49 | tab = NULL;
|
---|
50 | sensorTab = NULL;
|
---|
51 | setupGroupbox = NULL;
|
---|
52 | rotation = NULL;
|
---|
53 | }
|
---|
54 |
|
---|
55 | Imu::~Imu() {
|
---|
56 | if (mainTab != NULL)
|
---|
57 | delete mainTab;
|
---|
58 | }
|
---|
59 |
|
---|
60 | void Imu::GetDatas(ImuData **outImuData) const { *outImuData = imuData; }
|
---|
61 |
|
---|
62 | void Imu::UpdateImu() {
|
---|
63 | if (rotation == NULL) {
|
---|
64 | Err("not applicable for simulation part.\n");
|
---|
65 | return;
|
---|
66 | }
|
---|
67 | Vector3D rawAcc, rawMag, rawGyr;
|
---|
68 | imuData->GetRawAccMagAndGyr(rawAcc, rawMag, rawGyr);
|
---|
69 | rotation->ComputeRotation(rawAcc);
|
---|
70 | rotation->ComputeRotation(rawGyr);
|
---|
71 | rotation->ComputeRotation(rawMag);
|
---|
72 | imuData->SetRawAccMagAndGyr(rawAcc, rawMag, rawGyr);
|
---|
73 | }
|
---|
74 |
|
---|
75 | GroupBox *Imu::GetGroupBox(void) const { return setupGroupbox; }
|
---|
76 |
|
---|
77 | Layout *Imu::GetLayout(void) const { return sensorTab; }
|
---|
78 |
|
---|
79 | void Imu::LockUserInterface(void) const {
|
---|
80 | if (sensorTab == NULL) {
|
---|
81 | Err("not applicable for simulation part.\n");
|
---|
82 | return;
|
---|
83 | }
|
---|
84 | sensorTab->setEnabled(false);
|
---|
85 | }
|
---|
86 |
|
---|
87 | void Imu::UnlockUserInterface(void) const {
|
---|
88 | if (sensorTab == NULL) {
|
---|
89 | Err("not applicable for simulation part.\n");
|
---|
90 | return;
|
---|
91 | }
|
---|
92 | sensorTab->setEnabled(true);
|
---|
93 | }
|
---|
94 |
|
---|
95 | void Imu::UseDefaultPlot(void) {
|
---|
96 | if (tab == NULL) {
|
---|
97 | Err("not applicable for simulation part.\n");
|
---|
98 | return;
|
---|
99 | }
|
---|
100 |
|
---|
101 | plotTab = new Tab(tab, "IMU");
|
---|
102 | axPlot = new DataPlot1D(plotTab->NewRow(), "acc_x", -10, 10);
|
---|
103 | axPlot->AddCurve(imuData->Element(ImuData::RawAx));
|
---|
104 | ayPlot = new DataPlot1D(plotTab->LastRowLastCol(), "acc_y", -10, 10);
|
---|
105 | ayPlot->AddCurve(imuData->Element(ImuData::RawAy));
|
---|
106 | azPlot = new DataPlot1D(plotTab->LastRowLastCol(), "acc_z", -10, 10);
|
---|
107 | azPlot->AddCurve(imuData->Element(ImuData::RawAz));
|
---|
108 |
|
---|
109 | if (plotTab == NULL)
|
---|
110 | plotTab = new Tab(tab, "IMU");
|
---|
111 | gxPlot = new DataPlot1D(plotTab->NewRow(), "gyr_x", -500, 500);
|
---|
112 | gxPlot->AddCurve(imuData->Element(ImuData::RawGxDeg));
|
---|
113 | gyPlot = new DataPlot1D(plotTab->LastRowLastCol(), "gyr_y", -500, 500);
|
---|
114 | gyPlot->AddCurve(imuData->Element(ImuData::RawGyDeg));
|
---|
115 | gzPlot = new DataPlot1D(plotTab->LastRowLastCol(), "gyr_z", -500, 500);
|
---|
116 | gzPlot->AddCurve(imuData->Element(ImuData::RawGzDeg));
|
---|
117 |
|
---|
118 | if (plotTab == NULL)
|
---|
119 | plotTab = new Tab(tab, "IMU");
|
---|
120 | mxPlot = new DataPlot1D(plotTab->NewRow(), "mag_x", -500, 500);
|
---|
121 | mxPlot->AddCurve(imuData->Element(ImuData::RawMx));
|
---|
122 | myPlot = new DataPlot1D(plotTab->LastRowLastCol(), "mag_y", -500, 500);
|
---|
123 | myPlot->AddCurve(imuData->Element(ImuData::RawMy));
|
---|
124 | mzPlot = new DataPlot1D(plotTab->LastRowLastCol(), "mag_z", -500, 500);
|
---|
125 | mzPlot->AddCurve(imuData->Element(ImuData::RawMz));
|
---|
126 | }
|
---|
127 |
|
---|
128 | Tab *Imu::GetPlotTab(void) const { return plotTab; }
|
---|
129 |
|
---|
130 | } // end namespace sensor
|
---|
131 | } // end namespace flair
|
---|