Changeset 15 in flair-src for trunk/lib/FlairSensorActuator/src/SimuUs.cpp
- Timestamp:
- Apr 8, 2016, 3:40:57 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/FlairSensorActuator/src/SimuUs.cpp
r3 r15 29 29 using namespace flair::gui; 30 30 31 namespace flair 32 { 33 namespace sensor 34 { 31 namespace flair { 32 namespace sensor { 35 33 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); 34 SimuUs::SimuUs(const FrameworkManager *parent, string name, uint32_t dev_id, 35 uint8_t priority) 36 : Thread(parent, name, priority), UsRangeFinder(parent, name) { 37 data_rate = 38 new SpinBox(GetGroupBox()->NewRow(), "data rate", " Hz", 1, 500, 1, 50); 39 39 40 41 42 shmem=new SharedMem((Thread*)this,dev_name.str().c_str(),sizeof(float));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 43 } 44 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;45 SimuUs::SimuUs(const IODevice *parent, string name, uint32_t dev_id) 46 : Thread(parent, name, 0), UsRangeFinder(parent, name) { 47 data_rate = NULL; 48 48 49 50 51 shmem=new SharedMem((Thread*)this,dev_name.str().c_str(),sizeof(float));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 52 } 53 53 54 SimuUs::~SimuUs() 55 { 56 SafeStop(); 57 Join(); 54 SimuUs::~SimuUs() { 55 SafeStop(); 56 Join(); 58 57 } 59 58 60 void SimuUs::Run(void) 61 { 62 float z; 59 void SimuUs::Run(void) { 60 float z; 63 61 64 if(data_rate==NULL) 65 { 66 Thread::Err("not applicable for simulation part.\n"); 67 return; 62 if (data_rate == NULL) { 63 Thread::Err("not applicable for simulation part.\n"); 64 return; 65 } 66 67 SetPeriodUS((uint32_t)(1000000. / data_rate->Value())); 68 69 while (!ToBeStopped()) { 70 WaitPeriod(); 71 72 shmem->Read((char *)&z, sizeof(float)); 73 74 if (data_rate->ValueChanged() == true) { 75 SetPeriodUS((uint32_t)(1000000. / data_rate->Value())); 68 76 } 69 77 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 } 78 output->SetValue(0, 0, z); 79 output->SetDataTime(GetTime()); 80 ProcessUpdate(output); 81 } 87 82 } 88 83
Note:
See TracChangeset
for help on using the changeset viewer.