source: flair-src/trunk/lib/FlairSensorActuator/src/SimuPressureSensor.cpp@ 257

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

added simupressuresensor

File size: 1.9 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: 2018/05/24
6// filename: SimuPressureSensor.cpp
7//
8// author: Guillaume Sanahuja
9// Copyright Heudiasyc UMR UTC/CNRS 7253
10//
11// version: $Id: $
12//
13// purpose: Class for a simulation pressure sensor
14//
15//
16/*********************************************************************/
17#include "SimuPressureSensor.h"
18#include <FrameworkManager.h>
19#include <SpinBox.h>
20#include <GroupBox.h>
21#include <Matrix.h>
22#include <SharedMem.h>
23#include <sstream>
24
25using std::string;
26using std::ostringstream;
27using namespace flair::core;
28using namespace flair::gui;
29
30namespace flair {
31namespace sensor {
32
33SimuPressureSensor::SimuPressureSensor(string name, uint32_t modelId,uint32_t deviceId,
34 uint8_t priority)
35 : Thread(getFrameworkManager(), name, priority), PressureSensor( name) {
36 data_rate =
37 new SpinBox(GetGroupBox()->NewRow(), "data rate", " Hz", 1, 500, 1, 50);
38
39 shmem = new SharedMem((Thread *)this, ShMemName(modelId, deviceId), sizeof(float));
40
41 SetIsReady(true);
42}
43
44SimuPressureSensor::~SimuPressureSensor() {
45 SafeStop();
46 Join();
47}
48
49string SimuPressureSensor::ShMemName(uint32_t modelId,uint32_t deviceId) {
50 ostringstream dev_name;
51 dev_name << "simu" << modelId << "_pressure_" << deviceId;
52 return dev_name.str().c_str();
53}
54
55void SimuPressureSensor::Run(void) {
56 float p;
57
58 SetPeriodUS((uint32_t)(1000000. / data_rate->Value()));
59
60 while (!ToBeStopped()) {
61 WaitPeriod();
62
63 shmem->Read((char *)&p, sizeof(float));
64
65 if (data_rate->ValueChanged() == true) {
66 SetPeriodUS((uint32_t)(1000000. / data_rate->Value()));
67 }
68
69 output->SetValue(0, 0, p);
70 output->SetDataTime(GetTime());
71 ProcessUpdate(output);
72 }
73}
74
75} // end namespace sensor
76} // end namespace flair
Note: See TracBrowser for help on using the repository browser.