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 <VrpnClient.h>
|
---|
24 | #include <Ahrs.h>
|
---|
25 | #include <Imu.h>
|
---|
26 | #include <UavMultiplex.h>
|
---|
27 | #include <UsRangeFinder.h>
|
---|
28 | #include <Bldc.h>
|
---|
29 | #include <cvmatrix.h>
|
---|
30 | #include "MetaUsRangeFinder.h"
|
---|
31 | #include "MetaVrpnObject.h"
|
---|
32 |
|
---|
33 | using std::string;
|
---|
34 | using namespace flair::core;
|
---|
35 | using namespace flair::gui;
|
---|
36 | using namespace flair::filter;
|
---|
37 | using namespace flair::sensor;
|
---|
38 | using namespace flair::actuator;
|
---|
39 |
|
---|
40 | namespace {
|
---|
41 | flair::meta::Uav *uavSingleton = NULL;
|
---|
42 | }
|
---|
43 |
|
---|
44 | namespace flair {
|
---|
45 | namespace meta {
|
---|
46 |
|
---|
47 | Uav *GetUav(void) { return uavSingleton; }
|
---|
48 |
|
---|
49 | Uav::Uav(string name, UavMultiplex *multiplex)
|
---|
50 | : Object(getFrameworkManager(), name) {
|
---|
51 | if (uavSingleton != NULL) {
|
---|
52 | Err("Uav must be instanced only one time\n");
|
---|
53 | return;
|
---|
54 | }
|
---|
55 |
|
---|
56 | uavSingleton = this;
|
---|
57 | verticalCamera = NULL;
|
---|
58 | horizontalCamera = NULL;
|
---|
59 | this->multiplex = multiplex;
|
---|
60 | }
|
---|
61 |
|
---|
62 | Uav::~Uav() {}
|
---|
63 |
|
---|
64 | void Uav::SetUsRangeFinder(const UsRangeFinder *inUs) {
|
---|
65 | us = (UsRangeFinder *)inUs;
|
---|
66 | meta_us = new MetaUsRangeFinder(us);
|
---|
67 | getFrameworkManager()->AddDeviceToLog(us);
|
---|
68 | }
|
---|
69 |
|
---|
70 | void Uav::SetAhrs(const Ahrs *inAhrs) {
|
---|
71 | ahrs = (Ahrs *)inAhrs;
|
---|
72 | imu = (Imu *)ahrs->GetImu();
|
---|
73 | getFrameworkManager()->AddDeviceToLog(imu);
|
---|
74 | }
|
---|
75 |
|
---|
76 | void Uav::SetBldc(const Bldc *inBldc) { bldc = (Bldc *)inBldc; }
|
---|
77 |
|
---|
78 | void Uav::SetBatteryMonitor(const BatteryMonitor *inBattery) {
|
---|
79 | battery = (BatteryMonitor *)inBattery;
|
---|
80 | }
|
---|
81 |
|
---|
82 | void Uav::SetMultiplex(const UavMultiplex *inMultiplex) {
|
---|
83 | multiplex = (UavMultiplex *)inMultiplex;
|
---|
84 | getFrameworkManager()->AddDeviceToLog(multiplex);
|
---|
85 | }
|
---|
86 |
|
---|
87 | void Uav::SetVerticalCamera(const Camera *inVerticalCamera) {
|
---|
88 | verticalCamera = (Camera *)inVerticalCamera;
|
---|
89 | }
|
---|
90 |
|
---|
91 | void Uav::SetHorizontalCamera(const Camera *inHorizontalCamera) {
|
---|
92 | horizontalCamera = (Camera *)inHorizontalCamera;
|
---|
93 | }
|
---|
94 |
|
---|
95 | void Uav::UseDefaultPlot(void) {
|
---|
96 | multiplex->UseDefaultPlot();
|
---|
97 |
|
---|
98 | if (bldc->HasSpeedMeasurement()) {
|
---|
99 | Tab *plot_tab = new Tab(multiplex->GetTabWidget(), "Speeds");
|
---|
100 | DataPlot1D *plots[4];
|
---|
101 | plots[0] = new DataPlot1D(plot_tab->NewRow(), "front left", 0, 7000);
|
---|
102 | plots[1] =
|
---|
103 | new DataPlot1D(plot_tab->LastRowLastCol(), "front right", 0, 7000);
|
---|
104 | plots[2] = new DataPlot1D(plot_tab->NewRow(), "rear left", 0, 7000);
|
---|
105 | plots[3] =
|
---|
106 | new DataPlot1D(plot_tab->LastRowLastCol(), "rear right", 0, 7000);
|
---|
107 |
|
---|
108 | if (bldc->MotorsCount() == 8) {
|
---|
109 | for (int i = 0; i < 4; i++)
|
---|
110 | plots[i]->AddCurve(
|
---|
111 | bldc->Output()->Element(multiplex->MultiplexValue(i), 0),
|
---|
112 | DataPlot::Red, "top");
|
---|
113 | for (int i = 0; i < 4; i++)
|
---|
114 | plots[i]->AddCurve(
|
---|
115 | bldc->Output()->Element(multiplex->MultiplexValue(i + 4), 0),
|
---|
116 | DataPlot::Blue, "bottom");
|
---|
117 | } else {
|
---|
118 | for (int i = 0; i < 4; i++)
|
---|
119 | plots[i]->AddCurve(
|
---|
120 | bldc->Output()->Element(multiplex->MultiplexValue(i), 0));
|
---|
121 | }
|
---|
122 | }
|
---|
123 |
|
---|
124 | if (bldc->HasCurrentMeasurement()) {
|
---|
125 | Tab *plot_tab = new Tab(multiplex->GetTabWidget(), "Currents");
|
---|
126 | DataPlot1D *plots[4];
|
---|
127 | plots[0] = new DataPlot1D(plot_tab->NewRow(), "front left", 0, 10);
|
---|
128 | plots[1] = new DataPlot1D(plot_tab->LastRowLastCol(), "front right", 0, 10);
|
---|
129 | plots[2] = new DataPlot1D(plot_tab->NewRow(), "rear left", 0, 10);
|
---|
130 | plots[3] = new DataPlot1D(plot_tab->LastRowLastCol(), "rear right", 0, 10);
|
---|
131 |
|
---|
132 | if (bldc->MotorsCount() == 8) {
|
---|
133 | for (int i = 0; i < 4; i++)
|
---|
134 | plots[i]->AddCurve(
|
---|
135 | bldc->Output()->Element(multiplex->MultiplexValue(i), 1),
|
---|
136 | DataPlot::Red, "top");
|
---|
137 | for (int i = 0; i < 4; i++)
|
---|
138 | plots[i]->AddCurve(
|
---|
139 | bldc->Output()->Element(multiplex->MultiplexValue(i + 4), 1),
|
---|
140 | DataPlot::Blue, "bottom");
|
---|
141 | } else {
|
---|
142 | for (int i = 0; i < 4; i++)
|
---|
143 | plots[i]->AddCurve(
|
---|
144 | bldc->Output()->Element(multiplex->MultiplexValue(i), 1));
|
---|
145 | }
|
---|
146 | }
|
---|
147 |
|
---|
148 | meta_us->UseDefaultPlot();
|
---|
149 | ahrs->UseDefaultPlot();
|
---|
150 | }
|
---|
151 |
|
---|
152 | UavMultiplex *Uav::GetUavMultiplex(void) const { return multiplex; }
|
---|
153 |
|
---|
154 | Bldc *Uav::GetBldc(void) const { return bldc; }
|
---|
155 |
|
---|
156 | Ahrs *Uav::GetAhrs(void) const { return ahrs; }
|
---|
157 |
|
---|
158 | Imu *Uav::GetImu(void) const { return imu; }
|
---|
159 |
|
---|
160 | MetaUsRangeFinder *Uav::GetMetaUsRangeFinder(void) const { return meta_us; }
|
---|
161 |
|
---|
162 | UsRangeFinder *Uav::GetUsRangeFinder(void) const { return us; }
|
---|
163 |
|
---|
164 | BatteryMonitor *Uav::GetBatteryMonitor(void) const { return battery; }
|
---|
165 |
|
---|
166 | Camera *Uav::GetVerticalCamera(void) const { return verticalCamera; }
|
---|
167 |
|
---|
168 | Camera *Uav::GetHorizontalCamera(void) const { return horizontalCamera; }
|
---|
169 |
|
---|
170 | } // end namespace meta
|
---|
171 | } // end namespace flair
|
---|