From 81865d597b3ddd62ca14254b2159a09f2fa9421b Mon Sep 17 00:00:00 2001 From: Ettore Pane <ettore.pane@skywarder.eu> Date: Tue, 26 Nov 2024 16:21:13 +0100 Subject: [PATCH] [PITOT] Fixing the issue of uninitialized values in Pitot sensor The Pitot constructor now takes an additional parameter initialReference of type ReferenceValues and initializes the reference member variable with it. This ensures that the reference values are always initialized when an instance of the Pitot class is created. --- src/shared/sensors/analog/Pitot/Pitot.h | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/shared/sensors/analog/Pitot/Pitot.h b/src/shared/sensors/analog/Pitot/Pitot.h index 952e3c2b9..9f5574123 100644 --- a/src/shared/sensors/analog/Pitot/Pitot.h +++ b/src/shared/sensors/analog/Pitot/Pitot.h @@ -1,5 +1,5 @@ -/* Copyright (c) 2022 Skyward Experimental Rocketry - * Authors: Alberto Nidasio, Arturo Benedetti +/* Copyright (c) 2024 Skyward Experimental Rocketry + * Authors: Alberto Nidasio, Arturo Benedetti, Ettore Pane * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -38,9 +38,11 @@ class Pitot : public Sensor<PitotData> { public: Pitot(std::function<float()> getTotalPressure, - std::function<float()> getStaticPressure) + std::function<float()> getStaticPressure, + const ReferenceValues& initialReference) : getTotalPressure(getTotalPressure), - getStaticPressure(getStaticPressure) + getStaticPressure(getStaticPressure), + reference(initialReference) { } @@ -48,7 +50,7 @@ public: bool selfTest() override { return true; } - void setReferenceValues(const ReferenceValues reference) + void setReferenceValues(const ReferenceValues& reference) { this->reference = reference; } @@ -66,7 +68,7 @@ protected: { // NOTE: Here we assume that we are always at refTemperature, so // calculations might be wrong at higher elevations! - pitotSpeed.airspeed = Aeroutils::computePitotAirspeed( + pitotSpeed.airspeed = AeroUtils::computePitotAirspeed( totalPressure, staticPressure, 0, reference.refTemperature); pitotSpeed.deltaP = totalPressure - staticPressure; } @@ -87,4 +89,4 @@ private: ReferenceValues reference; }; -} // namespace Boardcore +} // namespace Boardcore \ No newline at end of file -- GitLab