source: flair-src/trunk/lib/FlairMeta/src/Uav.cpp

Last change on this file was 377, checked in by Sanahuja Guillaume, 2 years ago

ugv update

File size: 5.5 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/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
34using std::string;
35using namespace flair::core;
36using namespace flair::gui;
37using namespace flair::filter;
38using namespace flair::sensor;
39using namespace flair::actuator;
40
41namespace {
42 flair::meta::Uav *uavSingleton = NULL;
43}
44
45namespace flair {
46namespace meta {
47
48Uav *GetUav(void) { return uavSingleton; }
49
50Uav::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
65Uav::~Uav() {}
66
67void Uav::SetUsRangeFinder(const UsRangeFinder *inUs) {
68 us = (UsRangeFinder *)inUs;
69 meta_us = new MetaUsRangeFinder(us);
70 getFrameworkManager()->AddDeviceToLog(us);
71}
72
73void 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
80void Uav::SetBldc(const Bldc *inBldc) {
81 bldc = (Bldc *)inBldc;
82}
83
84void Uav::SetBatteryMonitor(const BatteryMonitor *inBattery) {
85 battery = (BatteryMonitor *)inBattery;
86}
87
88void Uav::SetMultiplex(const UavMultiplex *inMultiplex) {
89 multiplex = (UavMultiplex *)inMultiplex;
90 getFrameworkManager()->AddDeviceToLog(multiplex);
91}
92
93void Uav::SetVerticalCamera(const Camera *inVerticalCamera) {
94 verticalCamera = (Camera *)inVerticalCamera;
95}
96
97void Uav::SetHorizontalCamera(const Camera *inHorizontalCamera) {
98 horizontalCamera = (Camera *)inHorizontalCamera;
99}
100
101void Uav::SetPressureSensor(const PressureSensor *inPressureSensor) {
102 pressureSensor=(PressureSensor *)inPressureSensor;
103 getFrameworkManager()->AddDeviceToLog(pressureSensor);
104}
105
106void Uav::SetGps(const NmeaGps *inGps) {
107 gps=(NmeaGps *)inGps;
108 getFrameworkManager()->AddDeviceToLog(gps);
109}
110
111void 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
170UavMultiplex *Uav::GetUavMultiplex(void) const { return multiplex; }
171
172Bldc *Uav::GetBldc(void) const { return bldc; }
173
174Ahrs *Uav::GetAhrs(void) const { return ahrs; }
175
176Imu *Uav::GetImu(void) const { return imu; }
177
178MetaUsRangeFinder *Uav::GetMetaUsRangeFinder(void) const { return meta_us; }
179
180UsRangeFinder *Uav::GetUsRangeFinder(void) const { return us; }
181
182BatteryMonitor *Uav::GetBatteryMonitor(void) const { return battery; }
183
184Camera *Uav::GetVerticalCamera(void) const { return verticalCamera; }
185
186Camera *Uav::GetHorizontalCamera(void) const { return horizontalCamera; }
187
188NmeaGps *Uav::GetGps(void) const { return gps; }
189
190PressureSensor *Uav::GetPressureSensor(void) const { return pressureSensor; }
191
192} // end namespace meta
193} // end namespace flair
Note: See TracBrowser for help on using the repository browser.