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/06/10
|
---|
6 | // filename: Uav.cpp
|
---|
7 | //
|
---|
8 | // author: Guillaume Sanahuja
|
---|
9 | // Copyright Heudiasyc UMR UTC/CNRS 7253
|
---|
10 | //
|
---|
11 | // version: $Id: $
|
---|
12 | //
|
---|
13 | // purpose: Base class to construct sensors/actuators depending on uav type
|
---|
14 | //
|
---|
15 | //
|
---|
16 | /*********************************************************************/
|
---|
17 |
|
---|
18 | #include "Uav.h"
|
---|
19 | #include <FrameworkManager.h>
|
---|
20 | #include <Tab.h>
|
---|
21 | #include <GridLayout.h>
|
---|
22 | #include <DataPlot1D.h>
|
---|
23 | #include <Ahrs.h>
|
---|
24 | #include <Imu.h>
|
---|
25 | #include <UavMultiplex.h>
|
---|
26 | #include <UsRangeFinder.h>
|
---|
27 | #include <NmeaGps.h>
|
---|
28 | #include <PressureSensor.h>
|
---|
29 | #include <Bldc.h>
|
---|
30 | #include <Matrix.h>
|
---|
31 | #include "MetaUsRangeFinder.h"
|
---|
32 |
|
---|
33 |
|
---|
34 | using std::string;
|
---|
35 | using namespace flair::core;
|
---|
36 | using namespace flair::gui;
|
---|
37 | using namespace flair::filter;
|
---|
38 | using namespace flair::sensor;
|
---|
39 | using namespace flair::actuator;
|
---|
40 |
|
---|
41 | namespace {
|
---|
42 | flair::meta::Uav *uavSingleton = NULL;
|
---|
43 | }
|
---|
44 |
|
---|
45 | namespace flair {
|
---|
46 | namespace meta {
|
---|
47 |
|
---|
48 | Uav *GetUav(void) { return uavSingleton; }
|
---|
49 |
|
---|
50 | Uav::Uav(string name, UavMultiplex *multiplex)
|
---|
51 | : Object(getFrameworkManager(), name) {
|
---|
52 | if (uavSingleton != NULL) {
|
---|
53 | Err("Uav must be instanced only one time\n");
|
---|
54 | return;
|
---|
55 | }
|
---|
56 |
|
---|
57 | uavSingleton = this;
|
---|
58 | verticalCamera = NULL;
|
---|
59 | horizontalCamera = NULL;
|
---|
60 | gps = NULL;
|
---|
61 | pressureSensor = NULL;
|
---|
62 | this->multiplex = multiplex;
|
---|
63 | }
|
---|
64 |
|
---|
65 | Uav::~Uav() {}
|
---|
66 |
|
---|
67 | void Uav::SetUsRangeFinder(const UsRangeFinder *inUs) {
|
---|
68 | us = (UsRangeFinder *)inUs;
|
---|
69 | meta_us = new MetaUsRangeFinder(us);
|
---|
70 | getFrameworkManager()->AddDeviceToLog(us);
|
---|
71 | }
|
---|
72 |
|
---|
73 | void Uav::SetAhrs(const Ahrs *inAhrs) {
|
---|
74 | ahrs = (Ahrs *)inAhrs;
|
---|
75 | imu = (Imu *)ahrs->GetImu();
|
---|
76 | //only add imu; as ahrs is son of imu, it will be logged together
|
---|
77 | getFrameworkManager()->AddDeviceToLog(imu);
|
---|
78 | }
|
---|
79 |
|
---|
80 | void Uav::SetBldc(const Bldc *inBldc) {
|
---|
81 | bldc = (Bldc *)inBldc;
|
---|
82 | }
|
---|
83 |
|
---|
84 | void Uav::SetBatteryMonitor(const BatteryMonitor *inBattery) {
|
---|
85 | battery = (BatteryMonitor *)inBattery;
|
---|
86 | }
|
---|
87 |
|
---|
88 | void Uav::SetMultiplex(const UavMultiplex *inMultiplex) {
|
---|
89 | multiplex = (UavMultiplex *)inMultiplex;
|
---|
90 | getFrameworkManager()->AddDeviceToLog(multiplex);
|
---|
91 | }
|
---|
92 |
|
---|
93 | void Uav::SetVerticalCamera(const Camera *inVerticalCamera) {
|
---|
94 | verticalCamera = (Camera *)inVerticalCamera;
|
---|
95 | }
|
---|
96 |
|
---|
97 | void Uav::SetHorizontalCamera(const Camera *inHorizontalCamera) {
|
---|
98 | horizontalCamera = (Camera *)inHorizontalCamera;
|
---|
99 | }
|
---|
100 |
|
---|
101 | void Uav::SetPressureSensor(const PressureSensor *inPressureSensor) {
|
---|
102 | pressureSensor=(PressureSensor *)inPressureSensor;
|
---|
103 | getFrameworkManager()->AddDeviceToLog(pressureSensor);
|
---|
104 | }
|
---|
105 |
|
---|
106 | void Uav::SetGps(const NmeaGps *inGps) {
|
---|
107 | gps=(NmeaGps *)inGps;
|
---|
108 | getFrameworkManager()->AddDeviceToLog(gps);
|
---|
109 | }
|
---|
110 |
|
---|
111 | void Uav::UseDefaultPlot(void) {
|
---|
112 | multiplex->UseDefaultPlot();
|
---|
113 |
|
---|
114 | if (bldc->HasSpeedMeasurement()) {
|
---|
115 | Tab *plot_tab = new Tab(multiplex->GetTabWidget(), "Speeds");
|
---|
116 | DataPlot1D *plots[4];
|
---|
117 | plots[0] = new DataPlot1D(plot_tab->NewRow(), "front left", 0, 7000);
|
---|
118 | plots[1] =
|
---|
119 | new DataPlot1D(plot_tab->LastRowLastCol(), "front right", 0, 7000);
|
---|
120 | plots[2] = new DataPlot1D(plot_tab->NewRow(), "rear left", 0, 7000);
|
---|
121 | plots[3] =
|
---|
122 | new DataPlot1D(plot_tab->LastRowLastCol(), "rear right", 0, 7000);
|
---|
123 |
|
---|
124 | if (bldc->MotorsCount() == 8) {
|
---|
125 | for (int i = 0; i < 4; i++)
|
---|
126 | plots[i]->AddCurve(
|
---|
127 | bldc->Output()->Element(multiplex->MultiplexValue(i), 0),
|
---|
128 | DataPlot::Red, "top");
|
---|
129 | for (int i = 0; i < 4; i++)
|
---|
130 | plots[i]->AddCurve(
|
---|
131 | bldc->Output()->Element(multiplex->MultiplexValue(i + 4), 0),
|
---|
132 | DataPlot::Blue, "bottom");
|
---|
133 | } else {
|
---|
134 | for (int i = 0; i < 4; i++)
|
---|
135 | plots[i]->AddCurve(
|
---|
136 | bldc->Output()->Element(multiplex->MultiplexValue(i), 0));
|
---|
137 | }
|
---|
138 | }
|
---|
139 |
|
---|
140 | if (bldc->HasCurrentMeasurement()) {
|
---|
141 | Tab *plot_tab = new Tab(multiplex->GetTabWidget(), "Currents");
|
---|
142 | DataPlot1D *plots[4];
|
---|
143 | plots[0] = new DataPlot1D(plot_tab->NewRow(), "front left", 0, 10);
|
---|
144 | plots[1] = new DataPlot1D(plot_tab->LastRowLastCol(), "front right", 0, 10);
|
---|
145 | plots[2] = new DataPlot1D(plot_tab->NewRow(), "rear left", 0, 10);
|
---|
146 | plots[3] = new DataPlot1D(plot_tab->LastRowLastCol(), "rear right", 0, 10);
|
---|
147 |
|
---|
148 | if (bldc->MotorsCount() == 8) {
|
---|
149 | for (int i = 0; i < 4; i++)
|
---|
150 | plots[i]->AddCurve(
|
---|
151 | bldc->Output()->Element(multiplex->MultiplexValue(i), 1),
|
---|
152 | DataPlot::Red, "top");
|
---|
153 | for (int i = 0; i < 4; i++)
|
---|
154 | plots[i]->AddCurve(
|
---|
155 | bldc->Output()->Element(multiplex->MultiplexValue(i + 4), 1),
|
---|
156 | DataPlot::Blue, "bottom");
|
---|
157 | } else {
|
---|
158 | for (int i = 0; i < 4; i++)
|
---|
159 | plots[i]->AddCurve(
|
---|
160 | bldc->Output()->Element(multiplex->MultiplexValue(i), 1));
|
---|
161 | }
|
---|
162 | }
|
---|
163 |
|
---|
164 | meta_us->UseDefaultPlot();
|
---|
165 | ahrs->UseDefaultPlot();
|
---|
166 | if(gps!=NULL) gps->UseDefaultPlot();
|
---|
167 | if(pressureSensor!=NULL) pressureSensor->UseDefaultPlot();
|
---|
168 | }
|
---|
169 |
|
---|
170 | UavMultiplex *Uav::GetUavMultiplex(void) const { return multiplex; }
|
---|
171 |
|
---|
172 | Bldc *Uav::GetBldc(void) const { return bldc; }
|
---|
173 |
|
---|
174 | Ahrs *Uav::GetAhrs(void) const { return ahrs; }
|
---|
175 |
|
---|
176 | Imu *Uav::GetImu(void) const { return imu; }
|
---|
177 |
|
---|
178 | MetaUsRangeFinder *Uav::GetMetaUsRangeFinder(void) const { return meta_us; }
|
---|
179 |
|
---|
180 | UsRangeFinder *Uav::GetUsRangeFinder(void) const { return us; }
|
---|
181 |
|
---|
182 | BatteryMonitor *Uav::GetBatteryMonitor(void) const { return battery; }
|
---|
183 |
|
---|
184 | Camera *Uav::GetVerticalCamera(void) const { return verticalCamera; }
|
---|
185 |
|
---|
186 | Camera *Uav::GetHorizontalCamera(void) const { return horizontalCamera; }
|
---|
187 |
|
---|
188 | NmeaGps *Uav::GetGps(void) const { return gps; }
|
---|
189 |
|
---|
190 | PressureSensor *Uav::GetPressureSensor(void) const { return pressureSensor; }
|
---|
191 |
|
---|
192 | } // end namespace meta
|
---|
193 | } // end namespace flair
|
---|