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

Last change on this file since 427 was 377, checked in by Sanahuja Guillaume, 4 years ago

ugv update

File size: 5.5 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 <Ahrs.h>
24#include <Imu.h>
25#include <UavMultiplex.h>
26#include <UsRangeFinder.h>
[185]27#include <NmeaGps.h>
[215]28#include <PressureSensor.h>
[7]29#include <Bldc.h>
[214]30#include <Matrix.h>
[7]31#include "MetaUsRangeFinder.h"
32
[377]33
[7]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;
[215]61 pressureSensor = NULL;
[15]62 this->multiplex = multiplex;
[7]63}
64
[15]65Uav::~Uav() {}
[7]66
67void Uav::SetUsRangeFinder(const UsRangeFinder *inUs) {
[15]68 us = (UsRangeFinder *)inUs;
69 meta_us = new MetaUsRangeFinder(us);
70 getFrameworkManager()->AddDeviceToLog(us);
[7]71}
72
73void Uav::SetAhrs(const Ahrs *inAhrs) {
[15]74 ahrs = (Ahrs *)inAhrs;
75 imu = (Imu *)ahrs->GetImu();
[186]76 //only add imu; as ahrs is son of imu, it will be logged together
[15]77 getFrameworkManager()->AddDeviceToLog(imu);
[7]78}
79
[215]80void Uav::SetBldc(const Bldc *inBldc) {
81 bldc = (Bldc *)inBldc;
82}
[7]83
[15]84void Uav::SetBatteryMonitor(const BatteryMonitor *inBattery) {
85 battery = (BatteryMonitor *)inBattery;
[7]86}
87
88void Uav::SetMultiplex(const UavMultiplex *inMultiplex) {
[15]89 multiplex = (UavMultiplex *)inMultiplex;
90 getFrameworkManager()->AddDeviceToLog(multiplex);
[7]91}
92
[15]93void Uav::SetVerticalCamera(const Camera *inVerticalCamera) {
94 verticalCamera = (Camera *)inVerticalCamera;
[7]95}
[121]96
97void Uav::SetHorizontalCamera(const Camera *inHorizontalCamera) {
98 horizontalCamera = (Camera *)inHorizontalCamera;
99}
[7]100
[215]101void Uav::SetPressureSensor(const PressureSensor *inPressureSensor) {
102 pressureSensor=(PressureSensor *)inPressureSensor;
103 getFrameworkManager()->AddDeviceToLog(pressureSensor);
104}
105
[185]106void Uav::SetGps(const NmeaGps *inGps) {
[215]107 gps=(NmeaGps *)inGps;
[185]108 getFrameworkManager()->AddDeviceToLog(gps);
109}
110
[7]111void Uav::UseDefaultPlot(void) {
[15]112 multiplex->UseDefaultPlot();
[7]113
[15]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);
[7]123
[15]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));
[7]137 }
[15]138 }
[7]139
[15]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);
[7]147
[15]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));
[7]161 }
[15]162 }
[7]163
[15]164 meta_us->UseDefaultPlot();
165 ahrs->UseDefaultPlot();
[185]166 if(gps!=NULL) gps->UseDefaultPlot();
[215]167 if(pressureSensor!=NULL) pressureSensor->UseDefaultPlot();
[7]168}
169
[15]170UavMultiplex *Uav::GetUavMultiplex(void) const { return multiplex; }
[7]171
[15]172Bldc *Uav::GetBldc(void) const { return bldc; }
[7]173
[15]174Ahrs *Uav::GetAhrs(void) const { return ahrs; }
[7]175
[15]176Imu *Uav::GetImu(void) const { return imu; }
[7]177
[15]178MetaUsRangeFinder *Uav::GetMetaUsRangeFinder(void) const { return meta_us; }
[7]179
[15]180UsRangeFinder *Uav::GetUsRangeFinder(void) const { return us; }
[7]181
[15]182BatteryMonitor *Uav::GetBatteryMonitor(void) const { return battery; }
[7]183
[15]184Camera *Uav::GetVerticalCamera(void) const { return verticalCamera; }
[7]185
[121]186Camera *Uav::GetHorizontalCamera(void) const { return horizontalCamera; }
187
[185]188NmeaGps *Uav::GetGps(void) const { return gps; }
189
[215]190PressureSensor *Uav::GetPressureSensor(void) const { return pressureSensor; }
191
[7]192} // end namespace meta
193} // end namespace flair
Note: See TracBrowser for help on using the repository browser.