[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 |
|
---|
| 26 | using std::string;
|
---|
| 27 | using std::ostringstream;
|
---|
| 28 | using namespace flair::core;
|
---|
| 29 | using namespace flair::gui;
|
---|
| 30 |
|
---|
[15] | 31 | namespace flair {
|
---|
| 32 | namespace sensor {
|
---|
[3] | 33 |
|
---|
[15] | 34 | SimuLaser::SimuLaser(const FrameworkManager *parent, string name,
|
---|
| 35 | uint32_t dev_id, uint8_t priority)
|
---|
| 36 | : Thread(parent, name, priority), LaserRangeFinder(parent, name) {
|
---|
| 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] | 46 | SimuLaser::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] | 56 | SimuLaser::~SimuLaser() {
|
---|
| 57 | SafeStop();
|
---|
| 58 | Join();
|
---|
[3] | 59 | }
|
---|
| 60 |
|
---|
[15] | 61 | void 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
|
---|