source: flair-src/trunk/lib/FlairSensorActuator/src/SimulatedUs.cpp@ 342

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

draw vrpn axis in simulator

File size: 1.8 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
[286]6// filename: SimulatedUs.cpp
[3]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/*********************************************************************/
[268]17#ifdef CORE2_64
18
[286]19#include "SimulatedUs.h"
[3]20#include <FrameworkManager.h>
21#include <SpinBox.h>
22#include <GroupBox.h>
[214]23#include <Matrix.h>
[3]24#include <SharedMem.h>
25#include <sstream>
26
27using std::string;
28using std::ostringstream;
29using namespace flair::core;
30using namespace flair::gui;
31
[15]32namespace flair {
33namespace sensor {
[3]34
[286]35SimulatedUs::SimulatedUs(string name, uint32_t modelId,uint32_t deviceId,
[15]36 uint8_t priority)
[137]37 : Thread(getFrameworkManager(), name, priority), UsRangeFinder( name) {
[15]38 data_rate =
39 new SpinBox(GetGroupBox()->NewRow(), "data rate", " Hz", 1, 500, 1, 50);
[3]40
[158]41 shmem = new SharedMem((Thread *)this, ShMemName(modelId, deviceId), sizeof(float));
[157]42
43 SetIsReady(true);
[3]44}
45
[286]46SimulatedUs::~SimulatedUs() {
[15]47 SafeStop();
48 Join();
[3]49}
50
[286]51string SimulatedUs::ShMemName(uint32_t modelId,uint32_t deviceId) {
[158]52 ostringstream dev_name;
53 dev_name << "simu" << modelId << "_us_" << deviceId;
54 return dev_name.str().c_str();
55}
56
[286]57void SimulatedUs::Run(void) {
[15]58 float z;
[245]59
[15]60 SetPeriodUS((uint32_t)(1000000. / data_rate->Value()));
[3]61
[15]62 while (!ToBeStopped()) {
63 WaitPeriod();
[3]64
[15]65 shmem->Read((char *)&z, sizeof(float));
[3]66
[15]67 if (data_rate->ValueChanged() == true) {
68 SetPeriodUS((uint32_t)(1000000. / data_rate->Value()));
69 }
[3]70
[15]71 output->SetValue(0, 0, z);
72 output->SetDataTime(GetTime());
73 ProcessUpdate(output);
74 }
[3]75}
76
77} // end namespace sensor
78} // end namespace flair
[268]79
80#endif
Note: See TracBrowser for help on using the repository browser.