Skyward boardcore
Loading...
Searching...
No Matches
SoftwareDifferentialPressureSensor.h
Go to the documentation of this file.
1/* Copyright (c) 2020 Skyward Experimental Rocketry
2 * Author: Luca Conterio
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
25#include <sensors/Sensor.h>
26#include <utils/KernelTime.h>
27
28namespace Boardcore
29{
30
38template <typename FirstPressureData, typename SecondPressureData>
39class SoftwareDifferentialPressureSensor : public Sensor<PressureData>
40{
41 static_assert(
42 checkIfProduces<Sensor<FirstPressureData>, PressureData>::value,
43 "First template argument must be a sensor that produces pressure "
44 "data.");
45 static_assert(
46 checkIfProduces<Sensor<SecondPressureData>, PressureData>::value,
47 "Second template argument must be a sensor that produces pressure "
48 "data.");
49
50public:
52 Sensor<FirstPressureData>* first_pressure_sensor,
53 Sensor<SecondPressureData>* second_pressure_sensor)
54 : first_pressure_sensor(first_pressure_sensor),
55 second_pressure_sensor(second_pressure_sensor)
56 {
57 }
58
59 bool init() override { return true; }
60
61 bool selfTest() override { return true; };
62
63protected:
68 {
69 float p1 = first_pressure_sensor->getLastSample().pressure;
70 float p2 = second_pressure_sensor->getLastSample().pressure;
71
72 return PressureData{Kernel::getOldTick(), p1 - p2};
73 }
74
75private:
76 Sensor<FirstPressureData>* first_pressure_sensor;
77 Sensor<SecondPressureData>* second_pressure_sensor;
78};
79
80} // namespace Boardcore
Base sensor class with has to be extended by any sensor driver.
Definition Sensor.h:91
virtual Data getLastSample()
Definition Sensor.h:131
Class used to simulate a differential pressure sensor in software.
bool selfTest() override
Check if the sensor is working.
SoftwareDifferentialPressureSensor(Sensor< FirstPressureData > *first_pressure_sensor, Sensor< SecondPressureData > *second_pressure_sensor)
long long getOldTick()
Get the current time in milliseconds.
Definition KernelTime.h:43
This file includes all the types the logdecoder script will decode.