[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 |
|
---|
| 33 | using std::string;
|
---|
| 34 | using namespace flair::core;
|
---|
| 35 | using namespace flair::gui;
|
---|
| 36 | using namespace flair::filter;
|
---|
| 37 | using namespace flair::sensor;
|
---|
| 38 | using namespace flair::actuator;
|
---|
| 39 |
|
---|
[122] | 40 | namespace {
|
---|
| 41 | flair::meta::Uav *uavSingleton = NULL;
|
---|
| 42 | }
|
---|
| 43 |
|
---|
[15] | 44 | namespace flair {
|
---|
| 45 | namespace meta {
|
---|
[7] | 46 |
|
---|
[122] | 47 | Uav *GetUav(void) { return uavSingleton; }
|
---|
| 48 |
|
---|
| 49 | Uav::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] | 62 | Uav::~Uav() {}
|
---|
[7] | 63 |
|
---|
| 64 | void Uav::SetUsRangeFinder(const UsRangeFinder *inUs) {
|
---|
[15] | 65 | us = (UsRangeFinder *)inUs;
|
---|
| 66 | meta_us = new MetaUsRangeFinder(us);
|
---|
| 67 | getFrameworkManager()->AddDeviceToLog(us);
|
---|
[7] | 68 | }
|
---|
| 69 |
|
---|
| 70 | void Uav::SetAhrs(const Ahrs *inAhrs) {
|
---|
[15] | 71 | ahrs = (Ahrs *)inAhrs;
|
---|
| 72 | imu = (Imu *)ahrs->GetImu();
|
---|
| 73 | getFrameworkManager()->AddDeviceToLog(imu);
|
---|
[7] | 74 | }
|
---|
| 75 |
|
---|
[15] | 76 | void Uav::SetBldc(const Bldc *inBldc) { bldc = (Bldc *)inBldc; }
|
---|
[7] | 77 |
|
---|
[15] | 78 | void Uav::SetBatteryMonitor(const BatteryMonitor *inBattery) {
|
---|
| 79 | battery = (BatteryMonitor *)inBattery;
|
---|
[7] | 80 | }
|
---|
| 81 |
|
---|
| 82 | void Uav::SetMultiplex(const UavMultiplex *inMultiplex) {
|
---|
[15] | 83 | multiplex = (UavMultiplex *)inMultiplex;
|
---|
| 84 | getFrameworkManager()->AddDeviceToLog(multiplex);
|
---|
[7] | 85 | }
|
---|
| 86 |
|
---|
[15] | 87 | void Uav::SetVerticalCamera(const Camera *inVerticalCamera) {
|
---|
| 88 | verticalCamera = (Camera *)inVerticalCamera;
|
---|
[7] | 89 | }
|
---|
[121] | 90 |
|
---|
| 91 | void Uav::SetHorizontalCamera(const Camera *inHorizontalCamera) {
|
---|
| 92 | horizontalCamera = (Camera *)inHorizontalCamera;
|
---|
| 93 | }
|
---|
[7] | 94 |
|
---|
| 95 | void 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] | 152 | UavMultiplex *Uav::GetUavMultiplex(void) const { return multiplex; }
|
---|
[7] | 153 |
|
---|
[15] | 154 | Bldc *Uav::GetBldc(void) const { return bldc; }
|
---|
[7] | 155 |
|
---|
[15] | 156 | Ahrs *Uav::GetAhrs(void) const { return ahrs; }
|
---|
[7] | 157 |
|
---|
[15] | 158 | Imu *Uav::GetImu(void) const { return imu; }
|
---|
[7] | 159 |
|
---|
[15] | 160 | MetaUsRangeFinder *Uav::GetMetaUsRangeFinder(void) const { return meta_us; }
|
---|
[7] | 161 |
|
---|
[15] | 162 | UsRangeFinder *Uav::GetUsRangeFinder(void) const { return us; }
|
---|
[7] | 163 |
|
---|
[15] | 164 | BatteryMonitor *Uav::GetBatteryMonitor(void) const { return battery; }
|
---|
[7] | 165 |
|
---|
[15] | 166 | Camera *Uav::GetVerticalCamera(void) const { return verticalCamera; }
|
---|
[7] | 167 |
|
---|
[121] | 168 | Camera *Uav::GetHorizontalCamera(void) const { return horizontalCamera; }
|
---|
| 169 |
|
---|
[7] | 170 | } // end namespace meta
|
---|
| 171 | } // end namespace flair
|
---|