source: flair-src/trunk/lib/FlairSensorActuator/src/SimuLaser.cpp@ 166

Last change on this file since 166 was 158, checked in by Sanahuja Guillaume, 8 years ago

corrected simu/device id for sensors

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