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: 2018/05/24
|
---|
6 | // filename: SimuPressureSensor.cpp
|
---|
7 | //
|
---|
8 | // author: Guillaume Sanahuja
|
---|
9 | // Copyright Heudiasyc UMR UTC/CNRS 7253
|
---|
10 | //
|
---|
11 | // version: $Id: $
|
---|
12 | //
|
---|
13 | // purpose: Class for a simulation pressure sensor
|
---|
14 | //
|
---|
15 | //
|
---|
16 | /*********************************************************************/
|
---|
17 | #include "SimuPressureSensor.h"
|
---|
18 | #include <SharedMem.h>
|
---|
19 | #include <Tab.h>
|
---|
20 | #include <DoubleSpinBox.h>
|
---|
21 | #include <Matrix.h>
|
---|
22 | #include "Model.h"
|
---|
23 | #include <sstream>
|
---|
24 | #include <math.h>
|
---|
25 |
|
---|
26 | using std::string;
|
---|
27 | using std::ostringstream;
|
---|
28 | using namespace flair::core;
|
---|
29 | using namespace flair::simulator;
|
---|
30 | using namespace flair::gui;
|
---|
31 |
|
---|
32 | namespace flair {
|
---|
33 | namespace sensor {
|
---|
34 |
|
---|
35 | SimuPressureSensor::SimuPressureSensor(const Model *parent, string name,uint32_t modelId,uint32_t deviceId)
|
---|
36 | : IODevice(parent,name) {
|
---|
37 | Tab *setup_tab = new Tab(parent->GetTabWidget(), name);
|
---|
38 | seaPressure = new DoubleSpinBox(setup_tab->NewRow(), "pressure at sea level:","Pa", 0, 200000, 1000,0,101325);
|
---|
39 |
|
---|
40 | shmem = new SharedMem(this, ShMemName(modelId, deviceId), sizeof(float));
|
---|
41 |
|
---|
42 | SetIsReady(true);
|
---|
43 | }
|
---|
44 |
|
---|
45 | SimuPressureSensor::~SimuPressureSensor() {
|
---|
46 | }
|
---|
47 |
|
---|
48 | string SimuPressureSensor::ShMemName(uint32_t modelId,uint32_t deviceId) {
|
---|
49 | ostringstream dev_name;
|
---|
50 | dev_name << "simu" << modelId << "_pressure_" << deviceId;
|
---|
51 | return dev_name.str().c_str();
|
---|
52 | }
|
---|
53 |
|
---|
54 | void SimuPressureSensor::UpdateFrom(const io_data *data) {
|
---|
55 | if (data != NULL) {
|
---|
56 | Matrix *input = (Matrix *)data;
|
---|
57 | float z_feet = -input->Value(6, 0)*3.28084;
|
---|
58 | float p = seaPressure->Value() *pow(1 - 6.87535*1e-6*z_feet,5.2561);//from https://www.brisbanehotairballooning.com.au/pressure-and-altitude-conversion/
|
---|
59 | shmem->Write((char *)&p, sizeof(float));
|
---|
60 | }
|
---|
61 | }
|
---|
62 |
|
---|
63 | } // end namespace sensor
|
---|
64 | } // end namespace flair
|
---|