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

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

singleton manager

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