Skyward boardcore
Loading...
Searching...
No Matches
Pitot.h
Go to the documentation of this file.
1/* Copyright (c) 2022 Skyward Experimental Rocketry
2 * Authors: Alberto Nidasio, Arturo Benedetti
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 * THE SOFTWARE.
21 */
22
23#pragma once
24
27#include <sensors/Sensor.h>
29
30#include <functional>
31
32#include "PitotData.h"
33
34namespace Boardcore
35{
36
37class Pitot : public Sensor<PitotData>
38{
39public:
40 Pitot(std::function<float()> getTotalPressure,
41 std::function<float()> getStaticPressure)
42 : getTotalPressure(getTotalPressure),
43 getStaticPressure(getStaticPressure)
44 {
45 }
46
47 bool init() override { return true; }
48
49 bool selfTest() override { return true; }
50
51 void setReferenceValues(const ReferenceValues reference)
52 {
53 this->reference = reference;
54 }
55
56 ReferenceValues getReferenceValues() { return reference; }
57
58protected:
60 {
61 float totalPressure = getTotalPressure();
62 float staticPressure = getStaticPressure();
63 PitotData pitotSpeed;
64 if (totalPressure > 0 && staticPressure > 0 &&
65 totalPressure > staticPressure)
66 {
67 // NOTE: Here we assume that we are always at refTemperature, so
68 // calculations might be wrong at higher elevations!
70 totalPressure, staticPressure, 0, reference.refTemperature);
71 pitotSpeed.deltaP = totalPressure - staticPressure;
72 }
73 else
74 {
75 pitotSpeed.airspeed = 0;
76 pitotSpeed.deltaP = 0;
77 }
78 pitotSpeed.timestamp = TimestampTimer::getTimestamp();
79
80 return pitotSpeed;
81 }
82
83private:
84 std::function<float()> getTotalPressure;
85 std::function<float()> getStaticPressure;
86
87 ReferenceValues reference;
88};
89
90} // namespace Boardcore
void setReferenceValues(const ReferenceValues reference)
Definition Pitot.h:51
bool init() override
Initialize the sensor.
Definition Pitot.h:47
ReferenceValues getReferenceValues()
Definition Pitot.h:56
bool selfTest() override
Check if the sensor is working.
Definition Pitot.h:49
PitotData sampleImpl() override
Read a data sample from the sensor. In case of errors, the method should return the last available co...
Definition Pitot.h:59
Pitot(std::function< float()> getTotalPressure, std::function< float()> getStaticPressure)
Definition Pitot.h:40
Base sensor class with has to be extended by any sensor driver.
Definition Sensor.h:91
float computePitotAirspeed(float pressureTotal, float pressureStatic, float d, float t0)
Computes air speed relative to the pitot tube.
uint64_t getTimestamp()
Returns the current timer value in microseconds.
This file includes all the types the logdecoder script will decode.
Reference values for the Apogee Detection Algorithm.