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

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

modifs uav vrpn i686

File size: 4.9 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>
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
[122]40namespace {
41 flair::meta::Uav *uavSingleton = NULL;
42}
43
[15]44namespace flair {
45namespace meta {
[7]46
[122]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;
[15]57 verticalCamera = NULL;
[121]58 horizontalCamera = NULL;
[15]59 this->multiplex = multiplex;
[7]60}
61
[15]62Uav::~Uav() {}
[7]63
64void Uav::SetUsRangeFinder(const UsRangeFinder *inUs) {
[15]65 us = (UsRangeFinder *)inUs;
66 meta_us = new MetaUsRangeFinder(us);
67 getFrameworkManager()->AddDeviceToLog(us);
[7]68}
69
70void Uav::SetAhrs(const Ahrs *inAhrs) {
[15]71 ahrs = (Ahrs *)inAhrs;
72 imu = (Imu *)ahrs->GetImu();
73 getFrameworkManager()->AddDeviceToLog(imu);
[7]74}
75
[15]76void Uav::SetBldc(const Bldc *inBldc) { bldc = (Bldc *)inBldc; }
[7]77
[15]78void Uav::SetBatteryMonitor(const BatteryMonitor *inBattery) {
79 battery = (BatteryMonitor *)inBattery;
[7]80}
81
82void Uav::SetMultiplex(const UavMultiplex *inMultiplex) {
[15]83 multiplex = (UavMultiplex *)inMultiplex;
84 getFrameworkManager()->AddDeviceToLog(multiplex);
[7]85}
86
[15]87void Uav::SetVerticalCamera(const Camera *inVerticalCamera) {
88 verticalCamera = (Camera *)inVerticalCamera;
[7]89}
[121]90
91void Uav::SetHorizontalCamera(const Camera *inHorizontalCamera) {
92 horizontalCamera = (Camera *)inHorizontalCamera;
93}
[7]94
95void Uav::UseDefaultPlot(void) {
[15]96 multiplex->UseDefaultPlot();
[7]97
[15]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);
[7]107
[15]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));
[7]121 }
[15]122 }
[7]123
[15]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);
[7]131
[15]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));
[7]145 }
[15]146 }
[7]147
[15]148 meta_us->UseDefaultPlot();
149 ahrs->UseDefaultPlot();
[7]150}
151
[15]152UavMultiplex *Uav::GetUavMultiplex(void) const { return multiplex; }
[7]153
[15]154Bldc *Uav::GetBldc(void) const { return bldc; }
[7]155
[15]156Ahrs *Uav::GetAhrs(void) const { return ahrs; }
[7]157
[15]158Imu *Uav::GetImu(void) const { return imu; }
[7]159
[15]160MetaUsRangeFinder *Uav::GetMetaUsRangeFinder(void) const { return meta_us; }
[7]161
[15]162UsRangeFinder *Uav::GetUsRangeFinder(void) const { return us; }
[7]163
[15]164BatteryMonitor *Uav::GetBatteryMonitor(void) const { return battery; }
[7]165
[15]166Camera *Uav::GetVerticalCamera(void) const { return verticalCamera; }
[7]167
[121]168Camera *Uav::GetHorizontalCamera(void) const { return horizontalCamera; }
169
[7]170} // end namespace meta
171} // end namespace flair
Note: See TracBrowser for help on using the repository browser.