[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 "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 |
|
---|
[15] | 31 | namespace flair {
|
---|
| 32 | namespace sensor {
|
---|
[3] | 33 |
|
---|
[158] | 34 | SimuUs::SimuUs(string name, uint32_t modelId,uint32_t deviceId,
|
---|
[15] | 35 | uint8_t priority)
|
---|
[137] | 36 | : Thread(getFrameworkManager(), name, priority), UsRangeFinder( name) {
|
---|
[15] | 37 | data_rate =
|
---|
| 38 | new SpinBox(GetGroupBox()->NewRow(), "data rate", " Hz", 1, 500, 1, 50);
|
---|
[3] | 39 |
|
---|
[158] | 40 | shmem = new SharedMem((Thread *)this, ShMemName(modelId, deviceId), sizeof(float));
|
---|
[157] | 41 |
|
---|
| 42 | SetIsReady(true);
|
---|
[3] | 43 | }
|
---|
| 44 |
|
---|
[158] | 45 | SimuUs::SimuUs(const IODevice *parent, string name,uint32_t modelId,uint32_t deviceId)
|
---|
[137] | 46 | : Thread(parent, name, 0), UsRangeFinder(parent,name) {
|
---|
[15] | 47 | data_rate = NULL;
|
---|
[3] | 48 |
|
---|
[158] | 49 | shmem = new SharedMem((Thread *)this, ShMemName(modelId, deviceId), sizeof(float));
|
---|
[157] | 50 |
|
---|
| 51 | SetIsReady(true);
|
---|
[3] | 52 | }
|
---|
| 53 |
|
---|
[15] | 54 | SimuUs::~SimuUs() {
|
---|
| 55 | SafeStop();
|
---|
| 56 | Join();
|
---|
[3] | 57 | }
|
---|
| 58 |
|
---|
[158] | 59 | string SimuUs::ShMemName(uint32_t modelId,uint32_t deviceId) {
|
---|
| 60 | ostringstream dev_name;
|
---|
| 61 | dev_name << "simu" << modelId << "_us_" << deviceId;
|
---|
| 62 | return dev_name.str().c_str();
|
---|
| 63 | }
|
---|
| 64 |
|
---|
[15] | 65 | void SimuUs::Run(void) {
|
---|
| 66 | float z;
|
---|
[3] | 67 |
|
---|
[15] | 68 | if (data_rate == NULL) {
|
---|
| 69 | Thread::Err("not applicable for simulation part.\n");
|
---|
| 70 | return;
|
---|
| 71 | }
|
---|
[3] | 72 |
|
---|
[15] | 73 | SetPeriodUS((uint32_t)(1000000. / data_rate->Value()));
|
---|
[3] | 74 |
|
---|
[15] | 75 | while (!ToBeStopped()) {
|
---|
| 76 | WaitPeriod();
|
---|
[3] | 77 |
|
---|
[15] | 78 | shmem->Read((char *)&z, sizeof(float));
|
---|
[3] | 79 |
|
---|
[15] | 80 | if (data_rate->ValueChanged() == true) {
|
---|
| 81 | SetPeriodUS((uint32_t)(1000000. / data_rate->Value()));
|
---|
| 82 | }
|
---|
[3] | 83 |
|
---|
[15] | 84 | output->SetValue(0, 0, z);
|
---|
| 85 | output->SetDataTime(GetTime());
|
---|
| 86 | ProcessUpdate(output);
|
---|
| 87 | }
|
---|
[3] | 88 | }
|
---|
| 89 |
|
---|
| 90 | } // end namespace sensor
|
---|
| 91 | } // end namespace flair
|
---|