[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 <SpinBox.h>
|
---|
| 20 | #include <GroupBox.h>
|
---|
[214] | 21 | #include <Matrix.h>
|
---|
[3] | 22 | #include <SharedMem.h>
|
---|
| 23 | #include <sstream>
|
---|
| 24 |
|
---|
| 25 | using std::string;
|
---|
| 26 | using std::ostringstream;
|
---|
| 27 | using namespace flair::core;
|
---|
| 28 | using namespace flair::gui;
|
---|
| 29 |
|
---|
[15] | 30 | namespace flair {
|
---|
| 31 | namespace sensor {
|
---|
[3] | 32 |
|
---|
[137] | 33 | SimuLaser::SimuLaser(string name,
|
---|
[158] | 34 | uint32_t modelId,uint32_t deviceId, uint8_t priority)
|
---|
[137] | 35 | : Thread(getFrameworkManager(), name, priority), LaserRangeFinder(name) {
|
---|
[15] | 36 | data_rate =
|
---|
| 37 | new SpinBox(GetGroupBox()->NewRow(), "data rate", " Hz", 1, 500, 1, 50);
|
---|
[3] | 38 |
|
---|
[158] | 39 | shmem = new SharedMem((Thread *)this, ShMemName(modelId, deviceId),
|
---|
[157] | 40 | 360 * sizeof(float));
|
---|
| 41 | SetIsReady(true);
|
---|
[3] | 42 | }
|
---|
| 43 |
|
---|
[15] | 44 | SimuLaser::~SimuLaser() {
|
---|
| 45 | SafeStop();
|
---|
| 46 | Join();
|
---|
[3] | 47 | }
|
---|
| 48 |
|
---|
[158] | 49 | string SimuLaser::ShMemName(uint32_t modelId,uint32_t deviceId) {
|
---|
| 50 | ostringstream dev_name;
|
---|
| 51 | dev_name << "simu" << modelId << "_laser_" << deviceId;
|
---|
| 52 | return dev_name.str().c_str();
|
---|
| 53 | }
|
---|
| 54 |
|
---|
[15] | 55 | void SimuLaser::Run(void) {
|
---|
| 56 | float z[360];
|
---|
[3] | 57 |
|
---|
[15] | 58 | SetPeriodUS((uint32_t)(1000000. / data_rate->Value()));
|
---|
[3] | 59 |
|
---|
[15] | 60 | while (!ToBeStopped()) {
|
---|
| 61 | WaitPeriod();
|
---|
[3] | 62 |
|
---|
[15] | 63 | shmem->Read((char *)z, 360 * sizeof(float));
|
---|
[3] | 64 |
|
---|
[15] | 65 | if (data_rate->ValueChanged() == true) {
|
---|
| 66 | SetPeriodUS((uint32_t)(1000000. / data_rate->Value()));
|
---|
[3] | 67 | }
|
---|
[15] | 68 | for (int i = 0; i < 360; i++) {
|
---|
| 69 | output->SetValue(i, 0, z[i]); //*******
|
---|
| 70 | }
|
---|
| 71 | output->SetDataTime(GetTime());
|
---|
| 72 | ProcessUpdate(output);
|
---|
| 73 | }
|
---|
[3] | 74 | }
|
---|
| 75 |
|
---|
| 76 | } // end namespace sensor
|
---|
| 77 | } // end namespace flair
|
---|