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

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

draw vrpn axis in simulator

File size: 1.8 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:   SimulatedUs.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#ifdef CORE2_64
18
19#include "SimulatedUs.h"
20#include <FrameworkManager.h>
21#include <SpinBox.h>
22#include <GroupBox.h>
23#include <Matrix.h>
24#include <SharedMem.h>
25#include <sstream>
26
27using std::string;
28using std::ostringstream;
29using namespace flair::core;
30using namespace flair::gui;
31
32namespace flair {
33namespace sensor {
34
35SimulatedUs::SimulatedUs(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
46SimulatedUs::~SimulatedUs() {
47  SafeStop();
48  Join();
49}
50
51string SimulatedUs::ShMemName(uint32_t modelId,uint32_t deviceId) {
52  ostringstream dev_name;
53  dev_name << "simu" <<  modelId << "_us_" << deviceId;
54  return dev_name.str().c_str();
55}
56
57void SimulatedUs::Run(void) {
58  float z;
59 
60  SetPeriodUS((uint32_t)(1000000. / data_rate->Value()));
61
62  while (!ToBeStopped()) {
63    WaitPeriod();
64
65    shmem->Read((char *)&z, sizeof(float));
66
67    if (data_rate->ValueChanged() == true) {
68      SetPeriodUS((uint32_t)(1000000. / data_rate->Value()));
69    }
70
71    output->SetValue(0, 0, z);
72    output->SetDataTime(GetTime());
73    ProcessUpdate(output);
74  }
75}
76
77} // end namespace sensor
78} // end namespace flair
79
80#endif
Note: See TracBrowser for help on using the repository browser.