[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 "SimulatedLaser.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 |
|
---|
| 27 | using std::string;
|
---|
| 28 | using std::ostringstream;
|
---|
| 29 | using namespace flair::core;
|
---|
| 30 | using namespace flair::gui;
|
---|
| 31 |
|
---|
[15] | 32 | namespace flair {
|
---|
| 33 | namespace sensor {
|
---|
[3] | 34 |
|
---|
[286] | 35 | SimulatedLaser::SimulatedLaser(string name,
|
---|
[158] | 36 | uint32_t modelId,uint32_t deviceId, uint8_t priority)
|
---|
[137] | 37 | : Thread(getFrameworkManager(), name, priority), LaserRangeFinder(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),
|
---|
[157] | 42 | 360 * sizeof(float));
|
---|
| 43 | SetIsReady(true);
|
---|
[3] | 44 | }
|
---|
| 45 |
|
---|
[286] | 46 | SimulatedLaser::~SimulatedLaser() {
|
---|
[15] | 47 | SafeStop();
|
---|
| 48 | Join();
|
---|
[3] | 49 | }
|
---|
| 50 |
|
---|
[286] | 51 | string SimulatedLaser::ShMemName(uint32_t modelId,uint32_t deviceId) {
|
---|
[158] | 52 | ostringstream dev_name;
|
---|
| 53 | dev_name << "simu" << modelId << "_laser_" << deviceId;
|
---|
| 54 | return dev_name.str().c_str();
|
---|
| 55 | }
|
---|
| 56 |
|
---|
[286] | 57 | void SimulatedLaser::Run(void) {
|
---|
[15] | 58 | float z[360];
|
---|
[3] | 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, 360 * sizeof(float));
|
---|
[3] | 66 |
|
---|
[15] | 67 | if (data_rate->ValueChanged() == true) {
|
---|
| 68 | SetPeriodUS((uint32_t)(1000000. / data_rate->Value()));
|
---|
[3] | 69 | }
|
---|
[15] | 70 | for (int i = 0; i < 360; i++) {
|
---|
| 71 | output->SetValue(i, 0, z[i]); //*******
|
---|
| 72 | }
|
---|
| 73 | output->SetDataTime(GetTime());
|
---|
| 74 | ProcessUpdate(output);
|
---|
| 75 | }
|
---|
[3] | 76 | }
|
---|
| 77 |
|
---|
| 78 | } // end namespace sensor
|
---|
| 79 | } // end namespace flair
|
---|
[268] | 80 |
|
---|
| 81 | #endif |
---|