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 "SimuUs.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 | SimuUs::SimuUs(const FrameworkManager* parent,string name,uint32_t dev_id,uint8_t priority) : Thread(parent,name,priority), UsRangeFinder(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_us_" << dev_id;
|
---|
42 | shmem=new SharedMem((Thread*)this,dev_name.str().c_str(),sizeof(float));
|
---|
43 | }
|
---|
44 |
|
---|
45 | SimuUs::SimuUs(const IODevice* parent,string name,uint32_t dev_id) : Thread(parent,name,0), UsRangeFinder(parent,name)
|
---|
46 | {
|
---|
47 | data_rate=NULL;
|
---|
48 |
|
---|
49 | ostringstream dev_name;
|
---|
50 | dev_name << "simu_us_" << dev_id;
|
---|
51 | shmem=new SharedMem((Thread*)this,dev_name.str().c_str(),sizeof(float));
|
---|
52 | }
|
---|
53 |
|
---|
54 | SimuUs::~SimuUs()
|
---|
55 | {
|
---|
56 | SafeStop();
|
---|
57 | Join();
|
---|
58 | }
|
---|
59 |
|
---|
60 | void SimuUs::Run(void)
|
---|
61 | {
|
---|
62 | float z;
|
---|
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,sizeof(float));
|
---|
77 |
|
---|
78 | if(data_rate->ValueChanged()==true)
|
---|
79 | {
|
---|
80 | SetPeriodUS((uint32_t)(1000000./data_rate->Value()));
|
---|
81 | }
|
---|
82 |
|
---|
83 | output->SetValue(0,0,z);
|
---|
84 | output->SetDataTime(GetTime());
|
---|
85 | ProcessUpdate(output);
|
---|
86 | }
|
---|
87 | }
|
---|
88 |
|
---|
89 | } // end namespace sensor
|
---|
90 | } // end namespace flair
|
---|