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

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

modifs gps

File size: 5.1 KB
RevLine 
[10]1// %flair:license{
[15]2// This file is part of the Flair framework distributed under the
3// CECILL-C License, Version 1.0.
[10]4// %flair:license}
[7]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>
[185]28#include <NmeaGps.h>
[7]29#include <Bldc.h>
30#include <cvmatrix.h>
31#include "MetaUsRangeFinder.h"
32#include "MetaVrpnObject.h"
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
[122]41namespace {
42 flair::meta::Uav *uavSingleton = NULL;
43}
44
[15]45namespace flair {
46namespace meta {
[7]47
[122]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;
[15]58 verticalCamera = NULL;
[121]59 horizontalCamera = NULL;
[185]60 gps = NULL;
[15]61 this->multiplex = multiplex;
[7]62}
63
[15]64Uav::~Uav() {}
[7]65
66void Uav::SetUsRangeFinder(const UsRangeFinder *inUs) {
[15]67 us = (UsRangeFinder *)inUs;
68 meta_us = new MetaUsRangeFinder(us);
69 getFrameworkManager()->AddDeviceToLog(us);
[7]70}
71
72void Uav::SetAhrs(const Ahrs *inAhrs) {
[15]73 ahrs = (Ahrs *)inAhrs;
74 imu = (Imu *)ahrs->GetImu();
75 getFrameworkManager()->AddDeviceToLog(imu);
[7]76}
77
[15]78void Uav::SetBldc(const Bldc *inBldc) { bldc = (Bldc *)inBldc; }
[7]79
[15]80void Uav::SetBatteryMonitor(const BatteryMonitor *inBattery) {
81 battery = (BatteryMonitor *)inBattery;
[7]82}
83
84void Uav::SetMultiplex(const UavMultiplex *inMultiplex) {
[15]85 multiplex = (UavMultiplex *)inMultiplex;
86 getFrameworkManager()->AddDeviceToLog(multiplex);
[7]87}
88
[15]89void Uav::SetVerticalCamera(const Camera *inVerticalCamera) {
90 verticalCamera = (Camera *)inVerticalCamera;
[7]91}
[121]92
93void Uav::SetHorizontalCamera(const Camera *inHorizontalCamera) {
94 horizontalCamera = (Camera *)inHorizontalCamera;
95}
[7]96
[185]97void Uav::SetGps(const NmeaGps *inGps) {
98 gps=(NmeaGps*)inGps;
99 getFrameworkManager()->AddDeviceToLog(gps);
100}
101
[7]102void Uav::UseDefaultPlot(void) {
[15]103 multiplex->UseDefaultPlot();
[7]104
[15]105 if (bldc->HasSpeedMeasurement()) {
106 Tab *plot_tab = new Tab(multiplex->GetTabWidget(), "Speeds");
107 DataPlot1D *plots[4];
108 plots[0] = new DataPlot1D(plot_tab->NewRow(), "front left", 0, 7000);
109 plots[1] =
110 new DataPlot1D(plot_tab->LastRowLastCol(), "front right", 0, 7000);
111 plots[2] = new DataPlot1D(plot_tab->NewRow(), "rear left", 0, 7000);
112 plots[3] =
113 new DataPlot1D(plot_tab->LastRowLastCol(), "rear right", 0, 7000);
[7]114
[15]115 if (bldc->MotorsCount() == 8) {
116 for (int i = 0; i < 4; i++)
117 plots[i]->AddCurve(
118 bldc->Output()->Element(multiplex->MultiplexValue(i), 0),
119 DataPlot::Red, "top");
120 for (int i = 0; i < 4; i++)
121 plots[i]->AddCurve(
122 bldc->Output()->Element(multiplex->MultiplexValue(i + 4), 0),
123 DataPlot::Blue, "bottom");
124 } else {
125 for (int i = 0; i < 4; i++)
126 plots[i]->AddCurve(
127 bldc->Output()->Element(multiplex->MultiplexValue(i), 0));
[7]128 }
[15]129 }
[7]130
[15]131 if (bldc->HasCurrentMeasurement()) {
132 Tab *plot_tab = new Tab(multiplex->GetTabWidget(), "Currents");
133 DataPlot1D *plots[4];
134 plots[0] = new DataPlot1D(plot_tab->NewRow(), "front left", 0, 10);
135 plots[1] = new DataPlot1D(plot_tab->LastRowLastCol(), "front right", 0, 10);
136 plots[2] = new DataPlot1D(plot_tab->NewRow(), "rear left", 0, 10);
137 plots[3] = new DataPlot1D(plot_tab->LastRowLastCol(), "rear right", 0, 10);
[7]138
[15]139 if (bldc->MotorsCount() == 8) {
140 for (int i = 0; i < 4; i++)
141 plots[i]->AddCurve(
142 bldc->Output()->Element(multiplex->MultiplexValue(i), 1),
143 DataPlot::Red, "top");
144 for (int i = 0; i < 4; i++)
145 plots[i]->AddCurve(
146 bldc->Output()->Element(multiplex->MultiplexValue(i + 4), 1),
147 DataPlot::Blue, "bottom");
148 } else {
149 for (int i = 0; i < 4; i++)
150 plots[i]->AddCurve(
151 bldc->Output()->Element(multiplex->MultiplexValue(i), 1));
[7]152 }
[15]153 }
[7]154
[15]155 meta_us->UseDefaultPlot();
156 ahrs->UseDefaultPlot();
[185]157 if(gps!=NULL) gps->UseDefaultPlot();
[7]158}
159
[15]160UavMultiplex *Uav::GetUavMultiplex(void) const { return multiplex; }
[7]161
[15]162Bldc *Uav::GetBldc(void) const { return bldc; }
[7]163
[15]164Ahrs *Uav::GetAhrs(void) const { return ahrs; }
[7]165
[15]166Imu *Uav::GetImu(void) const { return imu; }
[7]167
[15]168MetaUsRangeFinder *Uav::GetMetaUsRangeFinder(void) const { return meta_us; }
[7]169
[15]170UsRangeFinder *Uav::GetUsRangeFinder(void) const { return us; }
[7]171
[15]172BatteryMonitor *Uav::GetBatteryMonitor(void) const { return battery; }
[7]173
[15]174Camera *Uav::GetVerticalCamera(void) const { return verticalCamera; }
[7]175
[121]176Camera *Uav::GetHorizontalCamera(void) const { return horizontalCamera; }
177
[185]178NmeaGps *Uav::GetGps(void) const { return gps; }
179
[7]180} // end namespace meta
181} // end namespace flair
Note: See TracBrowser for help on using the repository browser.