diff --git a/cmake/dependencies.cmake b/cmake/dependencies.cmake index 31286e428d19780d9c6f8c07aaed992cff7e5c6e..2f96687df87daa93c68bb634bba780abc776c704 100644 --- a/cmake/dependencies.cmake +++ b/cmake/dependencies.cmake @@ -65,6 +65,7 @@ set(RIG_V2_COMPUTER src/RIGv2/CanHandler/CanHandler.cpp src/RIGv2/StateMachines/GroundModeManager/GroundModeManager.cpp src/RIGv2/StateMachines/TARS1/TARS1.cpp + src/RIGv2/StateMachines/TARS3/TARS3.cpp ) set(CON_RIG_COMPUTER diff --git a/src/RIGv2/StateMachines/TARS1/TARS1.h b/src/RIGv2/StateMachines/TARS1/TARS1.h index cac66d3696db63a917c02fe5643a972d7ba80700..d0416c143aaacc6f6278ed04b7daf7e9845db35c 100644 --- a/src/RIGv2/StateMachines/TARS1/TARS1.h +++ b/src/RIGv2/StateMachines/TARS1/TARS1.h @@ -26,7 +26,7 @@ #include <RIGv2/BoardScheduler.h> #include <RIGv2/Configs/TARS1Config.h> #include <RIGv2/Sensors/Sensors.h> -#include <RIGv2/StateMachines/TARS1/MedianFilter.h> +#include <common/MedianFilter.h> #include <RIGv2/StateMachines/TARS1/TARS1Data.h> #include <events/FSM.h> #include <miosix.h> diff --git a/src/RIGv2/StateMachines/TARS3/MedianFilter.h b/src/RIGv2/StateMachines/TARS3/MedianFilter.h deleted file mode 100644 index 0d14f3f1b12f4cd83a2ecb0a3d01fbc5623fe371..0000000000000000000000000000000000000000 --- a/src/RIGv2/StateMachines/TARS3/MedianFilter.h +++ /dev/null @@ -1,57 +0,0 @@ -/* Copyright (c) 2024 Skyward Experimental Rocketry - * Authors: Davide Mor - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#pragma once - -#include <algorithm> -#include <array> -#include <memory> - -namespace RIGv2 -{ - -template <typename T, size_t Max> -class MedianFilter -{ -public: - MedianFilter() {} - - void reset() { idx = 0; } - - void add(T value) - { - values[idx] = value; - idx = (idx + 1) % Max; - } - - T calcMedian() - { - std::sort(values.begin(), values.end()); - return values[idx / 2]; - } - -private: - size_t idx = 0; - std::array<T, Max> values = {0}; -}; - -} // namespace RIGv2 diff --git a/src/RIGv2/StateMachines/TARS3/TARS3.cpp b/src/RIGv2/StateMachines/TARS3/TARS3.cpp index 942bba7e88834697161791f4b0530c6301425d52..e14b42d6fece328b340a84188937e81b6b6c0330 100644 --- a/src/RIGv2/StateMachines/TARS3/TARS3.cpp +++ b/src/RIGv2/StateMachines/TARS3/TARS3.cpp @@ -94,10 +94,12 @@ void TARS3::sample() void TARS3::logAction(Tars3Action action, float data) { - auto data = Tars3ActionData{.timestamp = TimestampTimer::getTimestamp(), - .action = action, - .data = data}; - sdLogger.log(data); + auto actionData = Tars3ActionData{ + .timestamp = TimestampTimer::getTimestamp(), + .action = action, + .data = data, + }; + sdLogger.log(actionData); } void TARS3::logSample(float pressure, float mass) @@ -408,3 +410,5 @@ State TARS3::RefuelingVenting(const Event& event) } } } + +} // namespace RIGv2 diff --git a/src/RIGv2/StateMachines/TARS3/TARS3.h b/src/RIGv2/StateMachines/TARS3/TARS3.h index 6d81274b8b685983bcf04c307d99d0014afcdff8..7ae7fcb9ea1aa288762a217b87ac23d087ade7f6 100644 --- a/src/RIGv2/StateMachines/TARS3/TARS3.h +++ b/src/RIGv2/StateMachines/TARS3/TARS3.h @@ -22,10 +22,13 @@ #pragma once +#include <RIGv2/Configs/TARS3Config.h> +#include <common/MedianFilter.h> #include <events/HSM.h> #include <utils/DependencyManager/DependencyManager.h> -#include "MedianFilter.h" +#include <chrono> + #include "TARS3Data.h" namespace RIGv2 @@ -87,8 +90,8 @@ private: void logAction(Tars3Action action, float data = 0); void logSample(float pressure, float mass); - std::chrono::milliseconds fillingTime = 0ms; - std::chrono::milliseconds ventingTime = 0ms; + std::chrono::milliseconds fillingTime{0}; + std::chrono::milliseconds ventingTime{0}; float previousPressure = 0; float currentPressure = 0; diff --git a/src/RIGv2/StateMachines/TARS1/MedianFilter.h b/src/common/MedianFilter.h similarity index 100% rename from src/RIGv2/StateMachines/TARS1/MedianFilter.h rename to src/common/MedianFilter.h