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

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

add us plot

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