source: flair-src/trunk/lib/FlairSensorActuator/src/SimulatedLaser.cpp@ 286

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

draw vrpn axis in simulator

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: 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 "SimulatedLaser.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
35SimulatedLaser::SimulatedLaser(string name,
36 uint32_t modelId,uint32_t deviceId, uint8_t priority)
37 : Thread(getFrameworkManager(), name, priority), LaserRangeFinder(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),
42 360 * sizeof(float));
43 SetIsReady(true);
44}
45
46SimulatedLaser::~SimulatedLaser() {
47 SafeStop();
48 Join();
49}
50
51string SimulatedLaser::ShMemName(uint32_t modelId,uint32_t deviceId) {
52 ostringstream dev_name;
53 dev_name << "simu" << modelId << "_laser_" << deviceId;
54 return dev_name.str().c_str();
55}
56
57void SimulatedLaser::Run(void) {
58 float z[360];
59
60 SetPeriodUS((uint32_t)(1000000. / data_rate->Value()));
61
62 while (!ToBeStopped()) {
63 WaitPeriod();
64
65 shmem->Read((char *)z, 360 * sizeof(float));
66
67 if (data_rate->ValueChanged() == true) {
68 SetPeriodUS((uint32_t)(1000000. / data_rate->Value()));
69 }
70 for (int i = 0; i < 360; i++) {
71 output->SetValue(i, 0, z[i]); //*******
72 }
73 output->SetDataTime(GetTime());
74 ProcessUpdate(output);
75 }
76}
77
78} // end namespace sensor
79} // end namespace flair
80
81#endif
Note: See TracBrowser for help on using the repository browser.