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