source: flair-src/trunk/lib/FlairSensorActuator/src/SimuUs.cpp@ 224

Last change on this file since 224 was 224, checked in by Sanahuja Guillaume, 4 years ago

maj for armv5te

File size: 1.9 KB
RevLine 
[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 <SpinBox.h>
20#include <GroupBox.h>
[214]21#include <Matrix.h>
[3]22#include <SharedMem.h>
23#include <sstream>
24
25using std::string;
26using std::ostringstream;
27using namespace flair::core;
28using namespace flair::gui;
29
[15]30namespace flair {
31namespace sensor {
[3]32
[221]33//control part
[158]34SimuUs::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
[15]45SimuUs::~SimuUs() {
46 SafeStop();
47 Join();
[3]48}
49
[158]50string SimuUs::ShMemName(uint32_t modelId,uint32_t deviceId) {
51 ostringstream dev_name;
52 dev_name << "simu" << modelId << "_us_" << deviceId;
53 return dev_name.str().c_str();
54}
55
[15]56void SimuUs::Run(void) {
57 float z;
[3]58
[15]59 if (data_rate == NULL) {
60 Thread::Err("not applicable for simulation part.\n");
61 return;
62 }
[3]63
[15]64 SetPeriodUS((uint32_t)(1000000. / data_rate->Value()));
[3]65
[15]66 while (!ToBeStopped()) {
67 WaitPeriod();
[3]68
[15]69 shmem->Read((char *)&z, sizeof(float));
[3]70
[15]71 if (data_rate->ValueChanged() == true) {
72 SetPeriodUS((uint32_t)(1000000. / data_rate->Value()));
73 }
[3]74
[15]75 output->SetValue(0, 0, z);
76 output->SetDataTime(GetTime());
77 ProcessUpdate(output);
78 }
[3]79}
80
81} // end namespace sensor
82} // end namespace flair
Note: See TracBrowser for help on using the repository browser.