[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: 2016/02/08
|
---|
| 6 | // filename: SimuX4.cpp
|
---|
| 7 | //
|
---|
| 8 | // author: Guillaume Sanahuja
|
---|
| 9 | // Copyright Heudiasyc UMR UTC/CNRS 7253
|
---|
| 10 | //
|
---|
| 11 | // version: $Id: $
|
---|
| 12 | //
|
---|
[22] | 13 | // purpose: Class defining a simulation x4 uav
|
---|
[7] | 14 | //
|
---|
| 15 | //
|
---|
| 16 | /*********************************************************************/
|
---|
[268] | 17 | #ifdef CORE2_64
|
---|
[7] | 18 |
|
---|
| 19 | #include "SimuX4.h"
|
---|
| 20 | #include <FrameworkManager.h>
|
---|
| 21 | #include <X4X8Multiplex.h>
|
---|
[286] | 22 | #include <SimulatedImu.h>
|
---|
| 23 | #include <SimulatedAhrs.h>
|
---|
| 24 | #include <SimulatedBldc.h>
|
---|
| 25 | #include <SimulatedUs.h>
|
---|
| 26 | #include <SimulatedCamera.h>
|
---|
| 27 | #include <SimulatedPressureSensor.h>
|
---|
[7] | 28 | #include <BatteryMonitor.h>
|
---|
[286] | 29 | #include <SimulatedGps.h>
|
---|
[7] | 30 | #include <Tab.h>
|
---|
[157] | 31 | #include <FindArgument.h>
|
---|
[7] | 32 |
|
---|
| 33 | using std::string;
|
---|
| 34 | using namespace flair::core;
|
---|
| 35 | using namespace flair::gui;
|
---|
| 36 | using namespace flair::sensor;
|
---|
| 37 | using namespace flair::filter;
|
---|
| 38 | using namespace flair::actuator;
|
---|
| 39 |
|
---|
[15] | 40 | namespace flair {
|
---|
| 41 | namespace meta {
|
---|
[7] | 42 |
|
---|
[158] | 43 | SimuX4::SimuX4(string name, uint32_t simu_id,string options,
|
---|
[15] | 44 | filter::UavMultiplex *multiplex)
|
---|
[122] | 45 | : Uav(name, multiplex) {
|
---|
[7] | 46 |
|
---|
[15] | 47 | if (multiplex == NULL)
|
---|
[137] | 48 | SetMultiplex(new X4X8Multiplex("motors", X4X8Multiplex::X4));
|
---|
[7] | 49 |
|
---|
[286] | 50 | SetBldc(new SimulatedBldc(GetUavMultiplex(), GetUavMultiplex()->GetLayout(),
|
---|
[158] | 51 | "motors", GetUavMultiplex()->MotorsCount(), simu_id,0));
|
---|
[286] | 52 | SetUsRangeFinder(new SimulatedUs("us", simu_id,0, 60));
|
---|
| 53 | SetAhrs(new SimulatedAhrs("ahrs", simu_id, 0,70));
|
---|
[122] | 54 | Tab *bat_tab = new Tab(getFrameworkManager()->GetTabWidget(), "battery");
|
---|
[15] | 55 | SetBatteryMonitor(new BatteryMonitor(bat_tab->NewRow(), "battery"));
|
---|
| 56 | GetBatteryMonitor()->SetBatteryValue(12);
|
---|
[157] | 57 |
|
---|
| 58 | uint16_t camvWidth=320,camvHeight=240;
|
---|
[160] | 59 | ReadCameraResolutionOption(options,"camv",camvWidth,camvHeight);
|
---|
| 60 | Info("using vertical camera resolution: %ix%i\n",camvWidth, camvHeight);
|
---|
[286] | 61 | SetVerticalCamera(new SimulatedCamera("simu_cam_v", camvWidth, camvHeight, 3, simu_id,0, 10));
|
---|
[157] | 62 |
|
---|
[160] | 63 | uint16_t camhWidth=320,camhHeight=240;
|
---|
| 64 | ReadCameraResolutionOption(options,"camh",camhWidth,camhHeight);
|
---|
| 65 | Info("using horizontal camera resolution: %ix%i\n",camhWidth, camhHeight);
|
---|
[286] | 66 | SetHorizontalCamera(new SimulatedCamera("simu_cam_h", camhWidth, camhHeight, 3, simu_id,1, 10));
|
---|
[185] | 67 |
|
---|
| 68 | string useGps=FindArgument(options,"use_gps=",false);
|
---|
| 69 | if(useGps=="true") {
|
---|
[286] | 70 | SetGps(new SimulatedGps("gps", (NmeaGps::NMEAFlags_t)(NmeaGps::GGA | NmeaGps::VTG), 0,0, 40));
|
---|
[245] | 71 | }
|
---|
| 72 |
|
---|
| 73 | string usePressureSensor=FindArgument(options,"use_pressure_sensor=",false);
|
---|
| 74 | if(usePressureSensor=="true") {
|
---|
[286] | 75 | SetPressureSensor(new SimulatedPressureSensor("pressuresensor", 0,0, 10));
|
---|
[185] | 76 | }
|
---|
[7] | 77 | }
|
---|
| 78 |
|
---|
[15] | 79 | SimuX4::~SimuX4() {}
|
---|
[7] | 80 |
|
---|
| 81 | void SimuX4::StartSensors(void) {
|
---|
[286] | 82 | ((SimulatedImu *)(GetAhrs()->GetImu()))->Start();
|
---|
| 83 | ((SimulatedUs *)GetUsRangeFinder())->Start();
|
---|
| 84 | ((SimulatedCamera *)GetVerticalCamera())->Start();
|
---|
| 85 | ((SimulatedCamera *)GetHorizontalCamera())->Start();
|
---|
| 86 | if(GetGps()) ((SimulatedGps *)GetGps())->Start();
|
---|
| 87 | if(GetPressureSensor()) ((SimulatedPressureSensor *)GetPressureSensor())->Start();
|
---|
[7] | 88 | }
|
---|
| 89 |
|
---|
[160] | 90 | void SimuX4::ReadCameraResolutionOption(string options,string cameraName,uint16_t &camWidth,uint16_t &camHeight) const {
|
---|
| 91 | string camOpts=FindArgument(options,cameraName +"=",false);
|
---|
| 92 | if(camOpts!="") {
|
---|
| 93 | size_t position=camOpts.find("x");
|
---|
| 94 | if(position!=std::string::npos) {
|
---|
| 95 | camWidth=std::stoi(camOpts.substr(0,position));
|
---|
| 96 | camHeight=std::stoi(camOpts.substr(position+1,std::string::npos));
|
---|
| 97 | } else {
|
---|
| 98 | Warn("bad camera resolution parameter (%s) should be WIDTHxHEIGHT format\n",camOpts.c_str());
|
---|
| 99 | }
|
---|
| 100 | }
|
---|
| 101 | }
|
---|
[157] | 102 |
|
---|
[7] | 103 | } // end namespace meta
|
---|
| 104 | } // end namespace flair
|
---|
[268] | 105 |
|
---|
| 106 | #endif |
---|