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

Last change on this file since 123 was 122, checked in by Sanahuja Guillaume, 8 years ago

modifs uav vrpn i686

File size: 4.9 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 <Bldc.h>
29#include <cvmatrix.h>
30#include "MetaUsRangeFinder.h"
31#include "MetaVrpnObject.h"
32
33using std::string;
34using namespace flair::core;
35using namespace flair::gui;
36using namespace flair::filter;
37using namespace flair::sensor;
38using namespace flair::actuator;
39
40namespace {
41 flair::meta::Uav *uavSingleton = NULL;
42}
43
44namespace flair {
45namespace meta {
46
47Uav *GetUav(void) { return uavSingleton; }
48
49Uav::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
62Uav::~Uav() {}
63
64void Uav::SetUsRangeFinder(const UsRangeFinder *inUs) {
65 us = (UsRangeFinder *)inUs;
66 meta_us = new MetaUsRangeFinder(us);
67 getFrameworkManager()->AddDeviceToLog(us);
68}
69
70void Uav::SetAhrs(const Ahrs *inAhrs) {
71 ahrs = (Ahrs *)inAhrs;
72 imu = (Imu *)ahrs->GetImu();
73 getFrameworkManager()->AddDeviceToLog(imu);
74}
75
76void Uav::SetBldc(const Bldc *inBldc) { bldc = (Bldc *)inBldc; }
77
78void Uav::SetBatteryMonitor(const BatteryMonitor *inBattery) {
79 battery = (BatteryMonitor *)inBattery;
80}
81
82void Uav::SetMultiplex(const UavMultiplex *inMultiplex) {
83 multiplex = (UavMultiplex *)inMultiplex;
84 getFrameworkManager()->AddDeviceToLog(multiplex);
85}
86
87void Uav::SetVerticalCamera(const Camera *inVerticalCamera) {
88 verticalCamera = (Camera *)inVerticalCamera;
89}
90
91void Uav::SetHorizontalCamera(const Camera *inHorizontalCamera) {
92 horizontalCamera = (Camera *)inHorizontalCamera;
93}
94
95void 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
152UavMultiplex *Uav::GetUavMultiplex(void) const { return multiplex; }
153
154Bldc *Uav::GetBldc(void) const { return bldc; }
155
156Ahrs *Uav::GetAhrs(void) const { return ahrs; }
157
158Imu *Uav::GetImu(void) const { return imu; }
159
160MetaUsRangeFinder *Uav::GetMetaUsRangeFinder(void) const { return meta_us; }
161
162UsRangeFinder *Uav::GetUsRangeFinder(void) const { return us; }
163
164BatteryMonitor *Uav::GetBatteryMonitor(void) const { return battery; }
165
166Camera *Uav::GetVerticalCamera(void) const { return verticalCamera; }
167
168Camera *Uav::GetHorizontalCamera(void) const { return horizontalCamera; }
169
170} // end namespace meta
171} // end namespace flair
Note: See TracBrowser for help on using the repository browser.