[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 |
|
---|
[15] | 40 | namespace flair {
|
---|
| 41 | namespace meta {
|
---|
[7] | 42 |
|
---|
[15] | 43 | Uav::Uav(FrameworkManager *parent, string name, UavMultiplex *multiplex)
|
---|
| 44 | : Object(parent, name) {
|
---|
| 45 | vrpnclient = NULL;
|
---|
| 46 | uav_vrpn = NULL;
|
---|
| 47 | verticalCamera = NULL;
|
---|
[121] | 48 | horizontalCamera = NULL;
|
---|
[15] | 49 | this->multiplex = multiplex;
|
---|
[7] | 50 | }
|
---|
| 51 |
|
---|
[15] | 52 | Uav::~Uav() {}
|
---|
[7] | 53 |
|
---|
| 54 | void Uav::SetUsRangeFinder(const UsRangeFinder *inUs) {
|
---|
[15] | 55 | us = (UsRangeFinder *)inUs;
|
---|
| 56 | meta_us = new MetaUsRangeFinder(us);
|
---|
| 57 | getFrameworkManager()->AddDeviceToLog(us);
|
---|
[7] | 58 | }
|
---|
| 59 |
|
---|
| 60 | void Uav::SetAhrs(const Ahrs *inAhrs) {
|
---|
[15] | 61 | ahrs = (Ahrs *)inAhrs;
|
---|
| 62 | imu = (Imu *)ahrs->GetImu();
|
---|
| 63 | getFrameworkManager()->AddDeviceToLog(imu);
|
---|
[7] | 64 | }
|
---|
| 65 |
|
---|
[15] | 66 | void Uav::SetBldc(const Bldc *inBldc) { bldc = (Bldc *)inBldc; }
|
---|
[7] | 67 |
|
---|
[15] | 68 | void Uav::SetBatteryMonitor(const BatteryMonitor *inBattery) {
|
---|
| 69 | battery = (BatteryMonitor *)inBattery;
|
---|
[7] | 70 | }
|
---|
| 71 |
|
---|
| 72 | void Uav::SetMultiplex(const UavMultiplex *inMultiplex) {
|
---|
[15] | 73 | multiplex = (UavMultiplex *)inMultiplex;
|
---|
| 74 | getFrameworkManager()->AddDeviceToLog(multiplex);
|
---|
[7] | 75 | }
|
---|
| 76 |
|
---|
[15] | 77 | void Uav::SetVerticalCamera(const Camera *inVerticalCamera) {
|
---|
| 78 | verticalCamera = (Camera *)inVerticalCamera;
|
---|
[7] | 79 | }
|
---|
[121] | 80 |
|
---|
| 81 | void Uav::SetHorizontalCamera(const Camera *inHorizontalCamera) {
|
---|
| 82 | horizontalCamera = (Camera *)inHorizontalCamera;
|
---|
| 83 | }
|
---|
[7] | 84 | /*
|
---|
[15] | 85 | void Uav::SetupVRPNSerial(SerialPort *vrpn_port,string name,int
|
---|
| 86 | VRPNSerialObjectId) {
|
---|
[7] | 87 | vrpnclient=new VrpnClient(getFrameworkManager(),"vrpn",vrpn_port,10000,80);
|
---|
| 88 | uav_vrpn=new MetaVrpnObject(vrpnclient,name,VRPNSerialObjectId);
|
---|
| 89 |
|
---|
| 90 | getFrameworkManager()->AddDeviceToLog(uav_vrpn);
|
---|
| 91 | }
|
---|
| 92 | */
|
---|
| 93 | void Uav::SetupVRPNAutoIP(string name) {
|
---|
[15] | 94 | SetupVRPN("192.168.147.197:3883", name);
|
---|
[7] | 95 | }
|
---|
| 96 |
|
---|
[15] | 97 | void Uav::SetupVRPN(string optitrack_address, string name) {
|
---|
| 98 | vrpnclient = new VrpnClient(getFrameworkManager(), "vrpn", optitrack_address,
|
---|
| 99 | 10000, 80);
|
---|
| 100 | uav_vrpn = new MetaVrpnObject(vrpnclient, name);
|
---|
[7] | 101 |
|
---|
[15] | 102 | getFrameworkManager()->AddDeviceToLog(uav_vrpn);
|
---|
[7] | 103 |
|
---|
[15] | 104 | GetAhrs()->YawPlot()->AddCurve(uav_vrpn->State()->Element(2),
|
---|
| 105 | DataPlot::Green);
|
---|
| 106 | // GetAhrs()->RollPlot()->AddCurve(uav_vrpn->State()->Element(0),DataPlot::Green);
|
---|
| 107 | // GetAhrs()->PitchPlot()->AddCurve(uav_vrpn->State()->Element(1),DataPlot::Green);
|
---|
[7] | 108 | }
|
---|
| 109 |
|
---|
[15] | 110 | void Uav::StartSensors(void) {
|
---|
| 111 | if (vrpnclient != NULL) {
|
---|
| 112 | vrpnclient->Start();
|
---|
| 113 | }
|
---|
[7] | 114 | }
|
---|
| 115 | void Uav::UseDefaultPlot(void) {
|
---|
[15] | 116 | multiplex->UseDefaultPlot();
|
---|
[7] | 117 |
|
---|
[15] | 118 | if (bldc->HasSpeedMeasurement()) {
|
---|
| 119 | Tab *plot_tab = new Tab(multiplex->GetTabWidget(), "Speeds");
|
---|
| 120 | DataPlot1D *plots[4];
|
---|
| 121 | plots[0] = new DataPlot1D(plot_tab->NewRow(), "front left", 0, 7000);
|
---|
| 122 | plots[1] =
|
---|
| 123 | new DataPlot1D(plot_tab->LastRowLastCol(), "front right", 0, 7000);
|
---|
| 124 | plots[2] = new DataPlot1D(plot_tab->NewRow(), "rear left", 0, 7000);
|
---|
| 125 | plots[3] =
|
---|
| 126 | new DataPlot1D(plot_tab->LastRowLastCol(), "rear right", 0, 7000);
|
---|
[7] | 127 |
|
---|
[15] | 128 | if (bldc->MotorsCount() == 8) {
|
---|
| 129 | for (int i = 0; i < 4; i++)
|
---|
| 130 | plots[i]->AddCurve(
|
---|
| 131 | bldc->Output()->Element(multiplex->MultiplexValue(i), 0),
|
---|
| 132 | DataPlot::Red, "top");
|
---|
| 133 | for (int i = 0; i < 4; i++)
|
---|
| 134 | plots[i]->AddCurve(
|
---|
| 135 | bldc->Output()->Element(multiplex->MultiplexValue(i + 4), 0),
|
---|
| 136 | DataPlot::Blue, "bottom");
|
---|
| 137 | } else {
|
---|
| 138 | for (int i = 0; i < 4; i++)
|
---|
| 139 | plots[i]->AddCurve(
|
---|
| 140 | bldc->Output()->Element(multiplex->MultiplexValue(i), 0));
|
---|
[7] | 141 | }
|
---|
[15] | 142 | }
|
---|
[7] | 143 |
|
---|
[15] | 144 | if (bldc->HasCurrentMeasurement()) {
|
---|
| 145 | Tab *plot_tab = new Tab(multiplex->GetTabWidget(), "Currents");
|
---|
| 146 | DataPlot1D *plots[4];
|
---|
| 147 | plots[0] = new DataPlot1D(plot_tab->NewRow(), "front left", 0, 10);
|
---|
| 148 | plots[1] = new DataPlot1D(plot_tab->LastRowLastCol(), "front right", 0, 10);
|
---|
| 149 | plots[2] = new DataPlot1D(plot_tab->NewRow(), "rear left", 0, 10);
|
---|
| 150 | plots[3] = new DataPlot1D(plot_tab->LastRowLastCol(), "rear right", 0, 10);
|
---|
[7] | 151 |
|
---|
[15] | 152 | if (bldc->MotorsCount() == 8) {
|
---|
| 153 | for (int i = 0; i < 4; i++)
|
---|
| 154 | plots[i]->AddCurve(
|
---|
| 155 | bldc->Output()->Element(multiplex->MultiplexValue(i), 1),
|
---|
| 156 | DataPlot::Red, "top");
|
---|
| 157 | for (int i = 0; i < 4; i++)
|
---|
| 158 | plots[i]->AddCurve(
|
---|
| 159 | bldc->Output()->Element(multiplex->MultiplexValue(i + 4), 1),
|
---|
| 160 | DataPlot::Blue, "bottom");
|
---|
| 161 | } else {
|
---|
| 162 | for (int i = 0; i < 4; i++)
|
---|
| 163 | plots[i]->AddCurve(
|
---|
| 164 | bldc->Output()->Element(multiplex->MultiplexValue(i), 1));
|
---|
[7] | 165 | }
|
---|
[15] | 166 | }
|
---|
[7] | 167 |
|
---|
[15] | 168 | meta_us->UseDefaultPlot();
|
---|
| 169 | ahrs->UseDefaultPlot();
|
---|
[7] | 170 | }
|
---|
| 171 |
|
---|
[15] | 172 | UavMultiplex *Uav::GetUavMultiplex(void) const { return multiplex; }
|
---|
[7] | 173 |
|
---|
[15] | 174 | Bldc *Uav::GetBldc(void) const { return bldc; }
|
---|
[7] | 175 |
|
---|
[15] | 176 | Ahrs *Uav::GetAhrs(void) const { return ahrs; }
|
---|
[7] | 177 |
|
---|
[15] | 178 | Imu *Uav::GetImu(void) const { return imu; }
|
---|
[7] | 179 |
|
---|
[15] | 180 | MetaUsRangeFinder *Uav::GetMetaUsRangeFinder(void) const { return meta_us; }
|
---|
[7] | 181 |
|
---|
[15] | 182 | UsRangeFinder *Uav::GetUsRangeFinder(void) const { return us; }
|
---|
[7] | 183 |
|
---|
[15] | 184 | BatteryMonitor *Uav::GetBatteryMonitor(void) const { return battery; }
|
---|
[7] | 185 |
|
---|
[15] | 186 | VrpnClient *Uav::GetVrpnClient(void) const {
|
---|
| 187 | if (vrpnclient == NULL)
|
---|
| 188 | Err("vrpn is not setup, call SetupVRPN before\n");
|
---|
| 189 | return vrpnclient;
|
---|
[7] | 190 | }
|
---|
| 191 |
|
---|
[15] | 192 | MetaVrpnObject *Uav::GetVrpnObject(void) const { return uav_vrpn; }
|
---|
[7] | 193 |
|
---|
[15] | 194 | Camera *Uav::GetVerticalCamera(void) const { return verticalCamera; }
|
---|
[7] | 195 |
|
---|
[121] | 196 | Camera *Uav::GetHorizontalCamera(void) const { return horizontalCamera; }
|
---|
| 197 |
|
---|
[7] | 198 | } // end namespace meta
|
---|
| 199 | } // end namespace flair
|
---|