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

Last change on this file since 160 was 160, checked in by Sanahuja Guillaume, 5 years ago

cam

File size: 2.9 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>
27#include <Tab.h>
[160]28#include <FindArgument.h>
[7]29
30using std::string;
31using namespace flair::core;
32using namespace flair::gui;
33using namespace flair::sensor;
34using namespace flair::filter;
35using namespace flair::actuator;
36
[15]37namespace flair {
38namespace meta {
[7]39
[158]40SimuX8::SimuX8(string name, uint32_t simu_id,string options,
[15]41 filter::UavMultiplex *multiplex)
[122]42 : Uav(name, multiplex) {
[7]43
[15]44 if (multiplex == NULL)
[137]45 SetMultiplex(new X4X8Multiplex("motors", X4X8Multiplex::X8));
[7]46
[15]47 SetBldc(new SimuBldc(GetUavMultiplex(), GetUavMultiplex()->GetLayout(),
[158]48 "motors", GetUavMultiplex()->MotorsCount(), simu_id,0));
49 SetUsRangeFinder(new SimuUs("us", simu_id,0, 60));
50 SetAhrs(new SimuAhrs("imu", simu_id, 0,70));
[122]51 Tab *bat_tab = new Tab(getFrameworkManager()->GetTabWidget(), "battery");
[15]52 SetBatteryMonitor(new BatteryMonitor(bat_tab->NewRow(), "battery"));
53 GetBatteryMonitor()->SetBatteryValue(12);
[160]54
55 uint16_t camvWidth=320,camvHeight=240;
56 ReadCameraResolutionOption(options,"camv",camvWidth,camvHeight);
57 Info("using vertical camera resolution: %ix%i\n",camvWidth, camvHeight);
58 SetVerticalCamera(new SimuCamera("simu_cam_v", camvWidth, camvHeight, 3, simu_id,0, 10));
59
60 uint16_t camhWidth=320,camhHeight=240;
61 ReadCameraResolutionOption(options,"camh",camhWidth,camhHeight);
62 Info("using horizontal camera resolution: %ix%i\n",camhWidth, camhHeight);
63 SetHorizontalCamera(new SimuCamera("simu_cam_h", camhWidth, camhHeight, 3, simu_id,1, 10));
[7]64}
65
[15]66SimuX8::~SimuX8() {}
[7]67
68void SimuX8::StartSensors(void) {
[157]69 ((SimuImu *)(GetAhrs()->GetImu()))->Start();
[15]70 ((SimuUs *)GetUsRangeFinder())->Start();
71 ((SimuCamera *)GetVerticalCamera())->Start();
[160]72 ((SimuCamera *)GetHorizontalCamera())->Start();
[7]73}
74
[160]75void SimuX8::ReadCameraResolutionOption(string options,string cameraName,uint16_t &camWidth,uint16_t &camHeight) const {
76 string camOpts=FindArgument(options,cameraName +"=",false);
77 if(camOpts!="") {
78 size_t position=camOpts.find("x");
79 if(position!=std::string::npos) {
80 camWidth=std::stoi(camOpts.substr(0,position));
81 camHeight=std::stoi(camOpts.substr(position+1,std::string::npos));
82 } else {
83 Warn("bad camera resolution parameter (%s) should be WIDTHxHEIGHT format\n",camOpts.c_str());
84 }
85 }
86}
87
[7]88} // end namespace meta
89} // end namespace flair
Note: See TracBrowser for help on using the repository browser.