source: flair-src/trunk/lib/FlairSimulator/src/SimuPressureSensor.cpp@ 245

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

added simupressuresensor

File size: 1.8 KB
Line 
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
26using std::string;
27using std::ostringstream;
28using namespace flair::core;
29using namespace flair::simulator;
30using namespace flair::gui;
31
32namespace flair {
33namespace sensor {
34
35SimuPressureSensor::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
45SimuPressureSensor::~SimuPressureSensor() {
46}
47
48string 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
54void 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
Note: See TracBrowser for help on using the repository browser.