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

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

maj imu

File size: 3.2 KB
RevLine 
[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: SimuX8.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 x8 uav
[7]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>
[185]27#include <SimuGps.h>
[7]28#include <Tab.h>
[160]29#include <FindArgument.h>
[7]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
[15]38namespace flair {
39namespace meta {
[7]40
[158]41SimuX8::SimuX8(string name, uint32_t simu_id,string options,
[15]42 filter::UavMultiplex *multiplex)
[122]43 : Uav(name, multiplex) {
[7]44
[15]45 if (multiplex == NULL)
[137]46 SetMultiplex(new X4X8Multiplex("motors", X4X8Multiplex::X8));
[7]47
[15]48 SetBldc(new SimuBldc(GetUavMultiplex(), GetUavMultiplex()->GetLayout(),
[158]49 "motors", GetUavMultiplex()->MotorsCount(), simu_id,0));
50 SetUsRangeFinder(new SimuUs("us", simu_id,0, 60));
[186]51 SetAhrs(new SimuAhrs("ahrs", simu_id, 0,70));
[122]52 Tab *bat_tab = new Tab(getFrameworkManager()->GetTabWidget(), "battery");
[15]53 SetBatteryMonitor(new BatteryMonitor(bat_tab->NewRow(), "battery"));
54 GetBatteryMonitor()->SetBatteryValue(12);
[160]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));
[185]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 }
[7]70}
71
[15]72SimuX8::~SimuX8() {}
[7]73
74void SimuX8::StartSensors(void) {
[157]75 ((SimuImu *)(GetAhrs()->GetImu()))->Start();
[15]76 ((SimuUs *)GetUsRangeFinder())->Start();
77 ((SimuCamera *)GetVerticalCamera())->Start();
[160]78 ((SimuCamera *)GetHorizontalCamera())->Start();
[186]79 if(GetGps()) ((SimuGps *)GetGps())->Start();
[7]80}
81
[160]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
[7]95} // end namespace meta
96} // end namespace flair
Note: See TracBrowser for help on using the repository browser.