[324] | 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 |
|
---|
| 35 | using std::string;
|
---|
| 36 | using namespace flair::core;
|
---|
| 37 | using namespace flair::gui;
|
---|
| 38 | using namespace flair::filter;
|
---|
| 39 | using namespace flair::sensor;
|
---|
| 40 | using namespace flair::actuator;
|
---|
| 41 |
|
---|
| 42 | namespace {
|
---|
| 43 | flair::meta::Uav *uavSingleton = NULL;
|
---|
| 44 | }
|
---|
| 45 |
|
---|
| 46 | namespace flair {
|
---|
| 47 | namespace meta {
|
---|
| 48 |
|
---|
| 49 | Uav *GetUav(void) { return uavSingleton; }
|
---|
| 50 |
|
---|
| 51 | Uav::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 |
|
---|
| 66 | Uav::~Uav() {}
|
---|
| 67 |
|
---|
| 68 | void Uav::SetUsRangeFinder(const UsRangeFinder *inUs) {
|
---|
| 69 | us = (UsRangeFinder *)inUs;
|
---|
| 70 | meta_us = new MetaUsRangeFinder(us);
|
---|
| 71 | getFrameworkManager()->AddDeviceToLog(us);
|
---|
| 72 | }
|
---|
| 73 |
|
---|
| 74 | void 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 |
|
---|
| 81 | void Uav::SetBldc(const Bldc *inBldc) {
|
---|
| 82 | bldc = (Bldc *)inBldc;
|
---|
| 83 | }
|
---|
| 84 |
|
---|
| 85 | void Uav::SetBatteryMonitor(const BatteryMonitor *inBattery) {
|
---|
| 86 | battery = (BatteryMonitor *)inBattery;
|
---|
| 87 | }
|
---|
| 88 |
|
---|
| 89 | void Uav::SetMultiplex(const UavMultiplex *inMultiplex) {
|
---|
| 90 | multiplex = (UavMultiplex *)inMultiplex;
|
---|
| 91 | getFrameworkManager()->AddDeviceToLog(multiplex);
|
---|
| 92 | }
|
---|
| 93 |
|
---|
| 94 | void Uav::SetVerticalCamera(const Camera *inVerticalCamera) {
|
---|
| 95 | verticalCamera = (Camera *)inVerticalCamera;
|
---|
| 96 | }
|
---|
| 97 |
|
---|
| 98 | void Uav::SetHorizontalCamera(const Camera *inHorizontalCamera) {
|
---|
| 99 | horizontalCamera = (Camera *)inHorizontalCamera;
|
---|
| 100 | }
|
---|
| 101 |
|
---|
| 102 | void Uav::SetPressureSensor(const PressureSensor *inPressureSensor) {
|
---|
| 103 | pressureSensor=(PressureSensor *)inPressureSensor;
|
---|
| 104 | getFrameworkManager()->AddDeviceToLog(pressureSensor);
|
---|
| 105 | }
|
---|
| 106 |
|
---|
| 107 | void Uav::SetGps(const NmeaGps *inGps) {
|
---|
| 108 | gps=(NmeaGps *)inGps;
|
---|
| 109 | getFrameworkManager()->AddDeviceToLog(gps);
|
---|
| 110 | }
|
---|
| 111 |
|
---|
| 112 | void 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 |
|
---|
| 171 | UavMultiplex *Uav::GetUavMultiplex(void) const { return multiplex; }
|
---|
| 172 |
|
---|
| 173 | Bldc *Uav::GetBldc(void) const { return bldc; }
|
---|
| 174 |
|
---|
| 175 | Ahrs *Uav::GetAhrs(void) const { return ahrs; }
|
---|
| 176 |
|
---|
| 177 | Imu *Uav::GetImu(void) const { return imu; }
|
---|
| 178 |
|
---|
| 179 | MetaUsRangeFinder *Uav::GetMetaUsRangeFinder(void) const { return meta_us; }
|
---|
| 180 |
|
---|
| 181 | UsRangeFinder *Uav::GetUsRangeFinder(void) const { return us; }
|
---|
| 182 |
|
---|
| 183 | BatteryMonitor *Uav::GetBatteryMonitor(void) const { return battery; }
|
---|
| 184 |
|
---|
| 185 | Camera *Uav::GetVerticalCamera(void) const { return verticalCamera; }
|
---|
| 186 |
|
---|
| 187 | Camera *Uav::GetHorizontalCamera(void) const { return horizontalCamera; }
|
---|
| 188 |
|
---|
| 189 | NmeaGps *Uav::GetGps(void) const { return gps; }
|
---|
| 190 |
|
---|
| 191 | PressureSensor *Uav::GetPressureSensor(void) const { return pressureSensor; }
|
---|
| 192 |
|
---|
| 193 | } // end namespace meta
|
---|
| 194 | } // end namespace flair
|
---|