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 |
|
---|
26 | using std::string;
|
---|
27 | using std::ostringstream;
|
---|
28 | using namespace flair::core;
|
---|
29 | using namespace flair::gui;
|
---|
30 |
|
---|
31 | namespace flair {
|
---|
32 | namespace sensor {
|
---|
33 |
|
---|
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);
|
---|
39 |
|
---|
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)); //****
|
---|
44 | }
|
---|
45 |
|
---|
46 | SimuLaser::SimuLaser(const IODevice *parent, string name, uint32_t dev_id)
|
---|
47 | : Thread(parent, name, 0), LaserRangeFinder(parent, name) {
|
---|
48 | data_rate = NULL;
|
---|
49 |
|
---|
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));
|
---|
54 | }
|
---|
55 |
|
---|
56 | SimuLaser::~SimuLaser() {
|
---|
57 | SafeStop();
|
---|
58 | Join();
|
---|
59 | }
|
---|
60 |
|
---|
61 | void SimuLaser::Run(void) {
|
---|
62 | float z[360];
|
---|
63 |
|
---|
64 | if (data_rate == NULL) {
|
---|
65 | Thread::Err("not applicable for simulation part.\n");
|
---|
66 | return;
|
---|
67 | }
|
---|
68 |
|
---|
69 | SetPeriodUS((uint32_t)(1000000. / data_rate->Value()));
|
---|
70 |
|
---|
71 | while (!ToBeStopped()) {
|
---|
72 | WaitPeriod();
|
---|
73 |
|
---|
74 | shmem->Read((char *)z, 360 * sizeof(float));
|
---|
75 |
|
---|
76 | if (data_rate->ValueChanged() == true) {
|
---|
77 | SetPeriodUS((uint32_t)(1000000. / data_rate->Value()));
|
---|
78 | }
|
---|
79 | for (int i = 0; i < 360; i++) {
|
---|
80 | output->SetValue(i, 0, z[i]); //*******
|
---|
81 | }
|
---|
82 | output->SetDataTime(GetTime());
|
---|
83 | ProcessUpdate(output);
|
---|
84 | }
|
---|
85 | }
|
---|
86 |
|
---|
87 | } // end namespace sensor
|
---|
88 | } // end namespace flair
|
---|