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