source: flair-src/trunk/lib/FlairSensorActuator/src/SimuUs.cpp@ 157

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

iadded isready to iodevice:
avoid problem of imu not ready in ardrone2

File size: 2.0 KB
RevLine 
[3]1// %flair:license{
[15]2// This file is part of the Flair framework distributed under the
3// CECILL-C License, Version 1.0.
[3]4// %flair:license}
5// created: 2014/02/07
6// filename: SimuUs.cpp
7//
8// author: Guillaume Sanahuja
9// Copyright Heudiasyc UMR UTC/CNRS 7253
10//
11// version: $Id: $
12//
13// purpose: Class for a simulation us
14//
15//
16/*********************************************************************/
17#include "SimuUs.h"
18#include <FrameworkManager.h>
19#include <ImuData.h>
20#include <SpinBox.h>
21#include <GroupBox.h>
22#include <cvmatrix.h>
23#include <SharedMem.h>
24#include <sstream>
25
26using std::string;
27using std::ostringstream;
28using namespace flair::core;
29using namespace flair::gui;
30
[15]31namespace flair {
32namespace sensor {
[3]33
[137]34SimuUs::SimuUs(string name, uint32_t dev_id,
[15]35 uint8_t priority)
[137]36 : Thread(getFrameworkManager(), name, priority), UsRangeFinder( name) {
[15]37 data_rate =
38 new SpinBox(GetGroupBox()->NewRow(), "data rate", " Hz", 1, 500, 1, 50);
[3]39
[15]40 ostringstream dev_name;
41 dev_name << "simu_us_" << dev_id;
42 shmem = new SharedMem((Thread *)this, dev_name.str().c_str(), sizeof(float));
[157]43
44 SetIsReady(true);
[3]45}
46
[15]47SimuUs::SimuUs(const IODevice *parent, string name, uint32_t dev_id)
[137]48 : Thread(parent, name, 0), UsRangeFinder(parent,name) {
[15]49 data_rate = NULL;
[3]50
[15]51 ostringstream dev_name;
52 dev_name << "simu_us_" << dev_id;
53 shmem = new SharedMem((Thread *)this, dev_name.str().c_str(), sizeof(float));
[157]54
55 SetIsReady(true);
[3]56}
57
[15]58SimuUs::~SimuUs() {
59 SafeStop();
60 Join();
[3]61}
62
[15]63void SimuUs::Run(void) {
64 float z;
[3]65
[15]66 if (data_rate == NULL) {
67 Thread::Err("not applicable for simulation part.\n");
68 return;
69 }
[3]70
[15]71 SetPeriodUS((uint32_t)(1000000. / data_rate->Value()));
[3]72
[15]73 while (!ToBeStopped()) {
74 WaitPeriod();
[3]75
[15]76 shmem->Read((char *)&z, sizeof(float));
[3]77
[15]78 if (data_rate->ValueChanged() == true) {
79 SetPeriodUS((uint32_t)(1000000. / data_rate->Value()));
80 }
[3]81
[15]82 output->SetValue(0, 0, z);
83 output->SetDataTime(GetTime());
84 ProcessUpdate(output);
85 }
[3]86}
87
88} // end namespace sensor
89} // end namespace flair
Note: See TracBrowser for help on using the repository browser.