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

Last change on this file since 39 was 15, checked in by Bayard Gildas, 9 years ago

sources reformatted with flair-format-dir script

File size: 3.8 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(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
46Imu::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
55Imu::~Imu() {
56 if (mainTab != NULL)
57 delete mainTab;
58}
59
60void Imu::GetDatas(ImuData **outImuData) const { *outImuData = imuData; }
61void Imu::UpdateImu() {
62 if (rotation == NULL) {
63 Err("not applicable for simulation part.\n");
64 return;
65 }
66 Vector3D rawAcc, rawMag, rawGyr;
67 imuData->GetRawAccMagAndGyr(rawAcc, rawMag, rawGyr);
68 rotation->ComputeRotation(rawAcc);
69 rotation->ComputeRotation(rawGyr);
70 rotation->ComputeRotation(rawMag);
71 imuData->SetRawAccMagAndGyr(rawAcc, rawMag, rawGyr);
72}
73
74GroupBox *Imu::GetGroupBox(void) const { return setupGroupbox; }
75
76Layout *Imu::GetLayout(void) const { return sensorTab; }
77
78void Imu::LockUserInterface(void) const {
79 if (sensorTab == NULL) {
80 Err("not applicable for simulation part.\n");
81 return;
82 }
83 sensorTab->setEnabled(false);
84}
85
86void Imu::UnlockUserInterface(void) const {
87 if (sensorTab == NULL) {
88 Err("not applicable for simulation part.\n");
89 return;
90 }
91 sensorTab->setEnabled(true);
92}
93
94void Imu::UseDefaultPlot(void) {
95 if (tab == NULL) {
96 Err("not applicable for simulation part.\n");
97 return;
98 }
99
100 plotTab = new Tab(tab, "IMU");
101 axPlot = new DataPlot1D(plotTab->NewRow(), "acc_x", -10, 10);
102 axPlot->AddCurve(imuData->Element(ImuData::RawAx));
103 ayPlot = new DataPlot1D(plotTab->LastRowLastCol(), "acc_y", -10, 10);
104 ayPlot->AddCurve(imuData->Element(ImuData::RawAy));
105 azPlot = new DataPlot1D(plotTab->LastRowLastCol(), "acc_z", -10, 10);
106 azPlot->AddCurve(imuData->Element(ImuData::RawAz));
107
108 if (plotTab == NULL)
109 plotTab = new Tab(tab, "IMU");
110 gxPlot = new DataPlot1D(plotTab->NewRow(), "gyr_x", -500, 500);
111 gxPlot->AddCurve(imuData->Element(ImuData::RawGxDeg));
112 gyPlot = new DataPlot1D(plotTab->LastRowLastCol(), "gyr_y", -500, 500);
113 gyPlot->AddCurve(imuData->Element(ImuData::RawGyDeg));
114 gzPlot = new DataPlot1D(plotTab->LastRowLastCol(), "gyr_z", -500, 500);
115 gzPlot->AddCurve(imuData->Element(ImuData::RawGzDeg));
116
117 if (plotTab == NULL)
118 plotTab = new Tab(tab, "IMU");
119 mxPlot = new DataPlot1D(plotTab->NewRow(), "mag_x", -500, 500);
120 mxPlot->AddCurve(imuData->Element(ImuData::RawMx));
121 myPlot = new DataPlot1D(plotTab->LastRowLastCol(), "mag_y", -500, 500);
122 myPlot->AddCurve(imuData->Element(ImuData::RawMy));
123 mzPlot = new DataPlot1D(plotTab->LastRowLastCol(), "mag_z", -500, 500);
124 mzPlot->AddCurve(imuData->Element(ImuData::RawMz));
125}
126
127Tab *Imu::GetPlotTab(void) const { return plotTab; }
128
129} // end namespace sensor
130} // end namespace flair
Note: See TracBrowser for help on using the repository browser.