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

Last change on this file since 198 was 198, checked in by Sanahuja Guillaume, 4 years ago

modifs imu

File size: 4.0 KB
Line 
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
28using std::string;
29using namespace flair::core;
30using namespace flair::gui;
31
32namespace flair {
33namespace sensor {
34
35Imu::Imu(string name,bool needRotation) : IODevice(getFrameworkManager(), name) {
36 imuData = new ImuData(this);
37
38 // station sol
39 mainTab = new Tab(getFrameworkManager()->GetTabWidget(), name);
40 tab = new TabWidget(mainTab->NewRow(), name);
41 sensorTab = new Tab(tab, "Reglages");
42 setupGroupbox = new GroupBox(sensorTab->NewRow(), name);
43 if(needRotation) {
44 rotation = new OneAxisRotation(sensorTab->NewRow(), "post rotation",OneAxisRotation::PostRotation);
45 } else {
46 rotation=NULL;
47 }
48 AddDataToLog(imuData);
49}
50
51Imu::Imu(const IODevice *parent,std::string name) : IODevice(parent, name) {
52 imuData = new ImuData(this);
53 mainTab = NULL;
54 tab = NULL;
55 sensorTab = NULL;
56 setupGroupbox = NULL;
57 rotation = NULL;
58}
59
60Imu::~Imu() {
61 if (mainTab != NULL)
62 delete mainTab;
63}
64
65const ImuData *Imu::GetDatas(void) const {
66 return imuData;
67}
68
69void Imu::GetDatas(ImuData **outImuData) const { *outImuData = imuData; }
70
71OneAxisRotation *Imu::GetOneAxisRotation(void) const {
72 if (rotation == NULL) {
73 Err("not applicable\n");
74 }
75 return rotation;
76}
77
78void Imu::ApplyRotation(Vector3Df& vector) {
79 if (rotation == NULL) {
80 Err("not applicable\n");
81 return;
82 }
83 rotation->ComputeRotation(vector);
84}
85
86void Imu::ApplyRotation(Quaternion& quaternion) {
87 if (rotation == NULL) {
88 Err("not applicable\n");
89 return;
90 }
91 rotation->ComputeRotation(quaternion);
92}
93
94GroupBox *Imu::GetGroupBox(void) const { return setupGroupbox; }
95
96Layout *Imu::GetLayout(void) const { return sensorTab; }
97
98void Imu::LockUserInterface(void) const {
99 if (sensorTab == NULL) {
100 Err("not applicable for simulation part.\n");
101 return;
102 }
103 sensorTab->setEnabled(false);
104}
105
106void Imu::UnlockUserInterface(void) const {
107 if (sensorTab == NULL) {
108 Err("not applicable for simulation part.\n");
109 return;
110 }
111 sensorTab->setEnabled(true);
112}
113
114void Imu::UseDefaultPlot(void) {
115 if (tab == NULL) {
116 Err("not applicable for simulation part.\n");
117 return;
118 }
119
120 plotTab = new Tab(tab, "IMU");
121 axPlot = new DataPlot1D(plotTab->NewRow(), "acc_x", -10, 10);
122 axPlot->AddCurve(imuData->Element(ImuData::RawAx));
123 ayPlot = new DataPlot1D(plotTab->LastRowLastCol(), "acc_y", -10, 10);
124 ayPlot->AddCurve(imuData->Element(ImuData::RawAy));
125 azPlot = new DataPlot1D(plotTab->LastRowLastCol(), "acc_z", -10, 10);
126 azPlot->AddCurve(imuData->Element(ImuData::RawAz));
127
128 if (plotTab == NULL)
129 plotTab = new Tab(tab, "IMU");
130 gxPlot = new DataPlot1D(plotTab->NewRow(), "gyr_x", -500, 500);
131 gxPlot->AddCurve(imuData->Element(ImuData::RawGxDeg));
132 gyPlot = new DataPlot1D(plotTab->LastRowLastCol(), "gyr_y", -500, 500);
133 gyPlot->AddCurve(imuData->Element(ImuData::RawGyDeg));
134 gzPlot = new DataPlot1D(plotTab->LastRowLastCol(), "gyr_z", -500, 500);
135 gzPlot->AddCurve(imuData->Element(ImuData::RawGzDeg));
136
137 if (plotTab == NULL)
138 plotTab = new Tab(tab, "IMU");
139 mxPlot = new DataPlot1D(plotTab->NewRow(), "mag_x", -500, 500);
140 mxPlot->AddCurve(imuData->Element(ImuData::RawMx));
141 myPlot = new DataPlot1D(plotTab->LastRowLastCol(), "mag_y", -500, 500);
142 myPlot->AddCurve(imuData->Element(ImuData::RawMy));
143 mzPlot = new DataPlot1D(plotTab->LastRowLastCol(), "mag_z", -500, 500);
144 mzPlot->AddCurve(imuData->Element(ImuData::RawMz));
145}
146
147Tab *Imu::GetPlotTab(void) const { return plotTab; }
148
149} // end namespace sensor
150} // end namespace flair
Note: See TracBrowser for help on using the repository browser.