source: flair-src/branches/sanscv/lib/FlairMeta/src/Uav.cpp@ 383

Last change on this file since 383 was 324, checked in by Sanahuja Guillaume, 5 years ago

removing opencv dependency

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