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