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