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: 2013/04/08
|
---|
6 | // filename: MetaVrpnObject.cpp
|
---|
7 | //
|
---|
8 | // author: Guillaume Sanahuja
|
---|
9 | // Copyright Heudiasyc UMR UTC/CNRS 7253
|
---|
10 | //
|
---|
11 | // version: $Id: $
|
---|
12 | //
|
---|
13 | // purpose: objet integrant objet vrpn et une dérivée
|
---|
14 | // d'euler
|
---|
15 | //
|
---|
16 | //
|
---|
17 | /*********************************************************************/
|
---|
18 |
|
---|
19 | #include "MetaVrpnObject.h"
|
---|
20 | #include <EulerDerivative.h>
|
---|
21 | #include <LowPassFilter.h>
|
---|
22 | #include <IODevice.h>
|
---|
23 | #include <GridLayout.h>
|
---|
24 | #include <DataPlot1D.h>
|
---|
25 | #include <DataPlot2D.h>
|
---|
26 | #include <Tab.h>
|
---|
27 | #include <TabWidget.h>
|
---|
28 | #include <Matrix.h>
|
---|
29 | #include <AltitudeSensor.h>
|
---|
30 |
|
---|
31 | using std::string;
|
---|
32 | using namespace flair::core;
|
---|
33 | using namespace flair::gui;
|
---|
34 | using namespace flair::sensor;
|
---|
35 | using namespace flair::filter;
|
---|
36 |
|
---|
37 | namespace flair {
|
---|
38 | namespace sensor {
|
---|
39 | class MetaVrpnObjectAltitudeSensor : public AltitudeSensor {
|
---|
40 | public:
|
---|
41 | MetaVrpnObjectAltitudeSensor(meta::MetaVrpnObject* parent,std::string name): AltitudeSensor(parent,name) {
|
---|
42 | this->parent=parent;
|
---|
43 | }
|
---|
44 | ~MetaVrpnObjectAltitudeSensor() {
|
---|
45 | }
|
---|
46 |
|
---|
47 | //z and dz must be in uav's frame
|
---|
48 | float z(void) const {
|
---|
49 | Vector3Df uav_pos;
|
---|
50 | parent->GetPosition(uav_pos);
|
---|
51 | return -uav_pos.z;
|
---|
52 | }
|
---|
53 | float Vz(void) const {
|
---|
54 | Vector3Df uav_vel;
|
---|
55 | parent->GetSpeed(uav_vel);
|
---|
56 | return -uav_vel.z;
|
---|
57 | }
|
---|
58 |
|
---|
59 | private:
|
---|
60 | meta::MetaVrpnObject* parent;
|
---|
61 |
|
---|
62 | };
|
---|
63 | }// end namespace sensor
|
---|
64 | }// end namespace flair
|
---|
65 |
|
---|
66 | namespace flair {
|
---|
67 | namespace meta {
|
---|
68 |
|
---|
69 | MetaVrpnObject::MetaVrpnObject(string name,VrpnClient *client)
|
---|
70 | : VrpnObject( name, client->GetTabWidget(),client) {
|
---|
71 | ConstructorCommon(name,client);
|
---|
72 | }
|
---|
73 |
|
---|
74 | MetaVrpnObject::MetaVrpnObject(string name,uint8_t id,VrpnClient *client)
|
---|
75 | : VrpnObject(name, id, client->GetTabWidget(),client) {
|
---|
76 | ConstructorCommon( name,client);
|
---|
77 | }
|
---|
78 |
|
---|
79 | void MetaVrpnObject::ConstructorCommon(string name,VrpnClient *client) {
|
---|
80 | MatrixDescriptor *desc = new MatrixDescriptor(7, 1);
|
---|
81 | for (int i = 0; i < desc->Rows(); i++) {
|
---|
82 | desc->SetElementName(i, 0, Output()->Name(i, 0));
|
---|
83 | }
|
---|
84 | Matrix *prev_value = new Matrix(this, desc, floatType, name);
|
---|
85 | delete desc;
|
---|
86 |
|
---|
87 | pbas = new LowPassFilter(this, client->GetLayout()->NewRow(),
|
---|
88 | name + " Passe bas", prev_value);
|
---|
89 | delete prev_value;
|
---|
90 |
|
---|
91 | desc = new MatrixDescriptor(7, 1);
|
---|
92 | for (int i = 0; i < desc->Rows(); i++) {
|
---|
93 | desc->SetElementName(i, 0, "d" + Output()->Name(i, 0));
|
---|
94 | }
|
---|
95 | prev_value = new Matrix(this, desc, floatType, name);
|
---|
96 | delete desc;
|
---|
97 |
|
---|
98 | euler = new EulerDerivative(pbas, client->GetLayout()->NewRow(),
|
---|
99 | name + "_euler", prev_value);
|
---|
100 | delete prev_value;
|
---|
101 |
|
---|
102 | vx_opti_plot = new DataPlot1D(GetPlotTab()->NewRow(), "vx", -3, 3);
|
---|
103 | vx_opti_plot->AddCurve(euler->GetMatrix()->Element(4));
|
---|
104 | vy_opti_plot = new DataPlot1D(GetPlotTab()->LastRowLastCol(), "vy", -3, 3);
|
---|
105 | vy_opti_plot->AddCurve(euler->GetMatrix()->Element(5));
|
---|
106 | vz_opti_plot = new DataPlot1D(GetPlotTab()->LastRowLastCol(), "vz", -2, 2);
|
---|
107 | vz_opti_plot->AddCurve(euler->GetMatrix()->Element(6));
|
---|
108 |
|
---|
109 | plot_tab = new Tab(client->GetTabWidget(), "Mesures (xy) " + name);
|
---|
110 | xy_plot = new DataPlot2D(plot_tab->NewRow(), "xy", "y", -5, 5, "x", -5, 5);
|
---|
111 | xy_plot->AddCurve(Output()->Element(5, 0), Output()->Element(4, 0));
|
---|
112 |
|
---|
113 | altitudeSensor=new MetaVrpnObjectAltitudeSensor(this,name);
|
---|
114 | }
|
---|
115 |
|
---|
116 | sensor::AltitudeSensor *MetaVrpnObject::GetAltitudeSensor(void) const {
|
---|
117 | return altitudeSensor;
|
---|
118 | }
|
---|
119 |
|
---|
120 | MetaVrpnObject::~MetaVrpnObject() { delete plot_tab; }
|
---|
121 |
|
---|
122 | DataPlot1D *MetaVrpnObject::VxPlot(void) const { return vx_opti_plot; }
|
---|
123 |
|
---|
124 | DataPlot1D *MetaVrpnObject::VyPlot(void) const { return vy_opti_plot; }
|
---|
125 |
|
---|
126 | DataPlot1D *MetaVrpnObject::VzPlot(void) const { return vz_opti_plot; }
|
---|
127 |
|
---|
128 | DataPlot2D *MetaVrpnObject::XyPlot(void) const { return xy_plot; }
|
---|
129 |
|
---|
130 | void MetaVrpnObject::GetSpeed(Vector3Df &speed) const {
|
---|
131 | speed.x = euler->Output(4, 0);
|
---|
132 | speed.y = euler->Output(5, 0);
|
---|
133 | speed.z = euler->Output(6, 0);
|
---|
134 | }
|
---|
135 |
|
---|
136 | EulerDerivative* MetaVrpnObject::GetEulerDerivative(void) const {
|
---|
137 | return euler;
|
---|
138 | }
|
---|
139 |
|
---|
140 | } // end namespace meta
|
---|
141 | } // end namespace flair
|
---|