source: flair-src/trunk/lib/FlairMeta/src/SimuX8.cpp@ 195

Last change on this file since 195 was 186, checked in by Sanahuja Guillaume, 7 years ago

maj imu

File size: 3.2 KB
Line 
1// %flair:license{
2// This file is part of the Flair framework distributed under the
3// CECILL-C License, Version 1.0.
4// %flair:license}
5// created: 2016/02/08
6// filename: SimuX8.cpp
7//
8// author: Guillaume Sanahuja
9// Copyright Heudiasyc UMR UTC/CNRS 7253
10//
11// version: $Id: $
12//
13// purpose: Class defining a simulation x8 uav
14//
15//
16/*********************************************************************/
17
18#include "SimuX8.h"
19#include <FrameworkManager.h>
20#include <X4X8Multiplex.h>
21#include <SimuImu.h>
22#include <SimuAhrs.h>
23#include <SimuBldc.h>
24#include <SimuUs.h>
25#include <SimuCamera.h>
26#include <BatteryMonitor.h>
27#include <SimuGps.h>
28#include <Tab.h>
29#include <FindArgument.h>
30
31using std::string;
32using namespace flair::core;
33using namespace flair::gui;
34using namespace flair::sensor;
35using namespace flair::filter;
36using namespace flair::actuator;
37
38namespace flair {
39namespace meta {
40
41SimuX8::SimuX8(string name, uint32_t simu_id,string options,
42 filter::UavMultiplex *multiplex)
43 : Uav(name, multiplex) {
44
45 if (multiplex == NULL)
46 SetMultiplex(new X4X8Multiplex("motors", X4X8Multiplex::X8));
47
48 SetBldc(new SimuBldc(GetUavMultiplex(), GetUavMultiplex()->GetLayout(),
49 "motors", GetUavMultiplex()->MotorsCount(), simu_id,0));
50 SetUsRangeFinder(new SimuUs("us", simu_id,0, 60));
51 SetAhrs(new SimuAhrs("ahrs", simu_id, 0,70));
52 Tab *bat_tab = new Tab(getFrameworkManager()->GetTabWidget(), "battery");
53 SetBatteryMonitor(new BatteryMonitor(bat_tab->NewRow(), "battery"));
54 GetBatteryMonitor()->SetBatteryValue(12);
55
56 uint16_t camvWidth=320,camvHeight=240;
57 ReadCameraResolutionOption(options,"camv",camvWidth,camvHeight);
58 Info("using vertical camera resolution: %ix%i\n",camvWidth, camvHeight);
59 SetVerticalCamera(new SimuCamera("simu_cam_v", camvWidth, camvHeight, 3, simu_id,0, 10));
60
61 uint16_t camhWidth=320,camhHeight=240;
62 ReadCameraResolutionOption(options,"camh",camhWidth,camhHeight);
63 Info("using horizontal camera resolution: %ix%i\n",camhWidth, camhHeight);
64 SetHorizontalCamera(new SimuCamera("simu_cam_h", camhWidth, camhHeight, 3, simu_id,1, 10));
65
66 string useGps=FindArgument(options,"use_gps=",false);
67 if(useGps=="true") {
68 SetGps(new SimuGps("gps", (NmeaGps::NMEAFlags_t)(NmeaGps::GGA | NmeaGps::VTG), 0,0, 40));
69 }
70}
71
72SimuX8::~SimuX8() {}
73
74void SimuX8::StartSensors(void) {
75 ((SimuImu *)(GetAhrs()->GetImu()))->Start();
76 ((SimuUs *)GetUsRangeFinder())->Start();
77 ((SimuCamera *)GetVerticalCamera())->Start();
78 ((SimuCamera *)GetHorizontalCamera())->Start();
79 if(GetGps()) ((SimuGps *)GetGps())->Start();
80}
81
82void SimuX8::ReadCameraResolutionOption(string options,string cameraName,uint16_t &camWidth,uint16_t &camHeight) const {
83 string camOpts=FindArgument(options,cameraName +"=",false);
84 if(camOpts!="") {
85 size_t position=camOpts.find("x");
86 if(position!=std::string::npos) {
87 camWidth=std::stoi(camOpts.substr(0,position));
88 camHeight=std::stoi(camOpts.substr(position+1,std::string::npos));
89 } else {
90 Warn("bad camera resolution parameter (%s) should be WIDTHxHEIGHT format\n",camOpts.c_str());
91 }
92 }
93}
94
95} // end namespace meta
96} // end namespace flair
Note: See TracBrowser for help on using the repository browser.