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

Last change on this file since 110 was 15, checked in by Bayard Gildas, 9 years ago

sources reformatted with flair-format-dir script

File size: 2.0 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: 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
31namespace flair {
32namespace sensor {
33
34SimuUs::SimuUs(const FrameworkManager *parent, string name, uint32_t dev_id,
35 uint8_t priority)
36 : Thread(parent, name, priority), UsRangeFinder(parent, name) {
37 data_rate =
38 new SpinBox(GetGroupBox()->NewRow(), "data rate", " Hz", 1, 500, 1, 50);
39
40 ostringstream dev_name;
41 dev_name << "simu_us_" << dev_id;
42 shmem = new SharedMem((Thread *)this, dev_name.str().c_str(), sizeof(float));
43}
44
45SimuUs::SimuUs(const IODevice *parent, string name, uint32_t dev_id)
46 : Thread(parent, name, 0), UsRangeFinder(parent, name) {
47 data_rate = NULL;
48
49 ostringstream dev_name;
50 dev_name << "simu_us_" << dev_id;
51 shmem = new SharedMem((Thread *)this, dev_name.str().c_str(), sizeof(float));
52}
53
54SimuUs::~SimuUs() {
55 SafeStop();
56 Join();
57}
58
59void SimuUs::Run(void) {
60 float z;
61
62 if (data_rate == NULL) {
63 Thread::Err("not applicable for simulation part.\n");
64 return;
65 }
66
67 SetPeriodUS((uint32_t)(1000000. / data_rate->Value()));
68
69 while (!ToBeStopped()) {
70 WaitPeriod();
71
72 shmem->Read((char *)&z, sizeof(float));
73
74 if (data_rate->ValueChanged() == true) {
75 SetPeriodUS((uint32_t)(1000000. / data_rate->Value()));
76 }
77
78 output->SetValue(0, 0, z);
79 output->SetDataTime(GetTime());
80 ProcessUpdate(output);
81 }
82}
83
84} // end namespace sensor
85} // end namespace flair
Note: See TracBrowser for help on using the repository browser.