From 6fd57022bdb5b43e168ff9a23057a99b5d2a99e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niccol=C3=B2=20Betto?= <niccolo.betto@skywarder.eu> Date: Thu, 13 Mar 2025 11:25:55 +0100 Subject: [PATCH] [RIGv2] Improve sensor initialization * Add missing pressure transducers initialization * Improve failure reporting * Add ADC specific enable flags --- src/RIGv2/Configs/SensorsConfig.h | 5 ++++- src/RIGv2/Sensors/Sensors.cpp | 26 ++++++++++++++++++-------- src/RIGv2/rig-v2-entry.cpp | 9 +++++---- 3 files changed, 27 insertions(+), 13 deletions(-) diff --git a/src/RIGv2/Configs/SensorsConfig.h b/src/RIGv2/Configs/SensorsConfig.h index 397a5bd8a..225da353d 100644 --- a/src/RIGv2/Configs/SensorsConfig.h +++ b/src/RIGv2/Configs/SensorsConfig.h @@ -46,7 +46,6 @@ constexpr auto OSR = Boardcore::ADS131M08Defs::OversamplingRatio::OSR_8192; constexpr bool GLOBAL_CHOP_MODE_EN = true; constexpr Hertz PERIOD = 100_hz; -constexpr bool ENABLED = true; // Servo current sensor calibration data // - A: 0.0 V: 2.520 @@ -62,6 +61,8 @@ constexpr float SERVO_CURRENT_ZERO = 2.520 / SERVO_CURRENT_SCALE; namespace ADC_1 { +constexpr bool ENABLED = true; + using Channel = Boardcore::ADS131M08Defs::Channel; constexpr auto OX_VESSEL_PT_CHANNEL = Channel::CHANNEL_0; @@ -82,6 +83,8 @@ constexpr float CH7_SHUNT_RESISTANCE = 29.0; // TODO: measure namespace ADC_2 { +constexpr bool ENABLED = true; + using Channel = Boardcore::ADS131M08Defs::Channel; constexpr auto OX_TANK_TOP_PT_CHANNEL = Channel::CHANNEL_0; diff --git a/src/RIGv2/Sensors/Sensors.cpp b/src/RIGv2/Sensors/Sensors.cpp index a6f3aed84..5eec560c6 100644 --- a/src/RIGv2/Sensors/Sensors.cpp +++ b/src/RIGv2/Sensors/Sensors.cpp @@ -26,6 +26,9 @@ #include <drivers/timer/TimestampTimer.h> #include <interfaces-impl/hwmapping.h> +#include <chrono> + +using namespace std::chrono; using namespace Boardcore; using namespace miosix; using namespace RIGv2; @@ -37,18 +40,25 @@ bool Sensors::start() if (Config::Sensors::InternalADC::ENABLED) internalAdcInit(); - if (Config::Sensors::ADS131M08::ENABLED) + if (Config::Sensors::ADC_1::ENABLED) { adc1Init(); - adc2Init(); oxVesselPressureInit(); oxFillingPressureInit(); - oxTankTopPressureInit(); - oxTankBottomPressureInit(); + n2Vessel1PressureInit(); + n2Vessel2PressureInit(); + n2FillingPressureInit(); oxVesselWeightInit(); oxTankWeightInit(); } + if (Config::Sensors::ADC_2::ENABLED) + { + adc2Init(); + oxTankTopPressureInit(); + oxTankBottomPressureInit(); + } + if (Config::Sensors::MAX31856::ENABLED) tc1Init(); @@ -297,11 +307,11 @@ std::vector<SensorInfo> Sensors::getSensorInfos() if (instance) \ infos.push_back(manager->getSensorInfo(instance.get())); \ else \ - infos.push_back(SensorInfo { #name, 0, nullptr, false }) + infos.push_back(SensorInfo{name, 0ns, nullptr, false}) - PUSH_SENSOR_INFO(adc1, "ADC1"); - PUSH_SENSOR_INFO(adc2, "ADC2"); - PUSH_SENSOR_INFO(tc1, "TC1"); + PUSH_SENSOR_INFO(adc1, "ADS131M08_1"); + PUSH_SENSOR_INFO(adc2, "ADS131M08_2"); + PUSH_SENSOR_INFO(tc1, "MAX31856_1"); PUSH_SENSOR_INFO(internalAdc, "InternalADC"); PUSH_SENSOR_INFO(oxVesselPressure, "OxVesselPressure"); PUSH_SENSOR_INFO(oxFillingPressure, "OxFillingPressure"); diff --git a/src/RIGv2/rig-v2-entry.cpp b/src/RIGv2/rig-v2-entry.cpp index b8ec84e95..013353999 100644 --- a/src/RIGv2/rig-v2-entry.cpp +++ b/src/RIGv2/rig-v2-entry.cpp @@ -37,9 +37,11 @@ #include <events/EventData.h> #include <events/utils/EventSniffer.h> +#include <chrono> #include <iomanip> #include <iostream> +using namespace std::chrono; using namespace Boardcore; using namespace Common; using namespace RIGv2; @@ -83,8 +85,6 @@ int main() manager.insert<GroundModeManager>(gmm) && manager.insert<TARS1>(tars1) && manager.inject(); - manager.graphviz(std::cout); - if (!initResult) { std::cout << "Failed to inject dependencies" << std::endl; @@ -208,11 +208,12 @@ int main() std::cout << "Sensor status:" << std::endl; for (auto info : sensors->getSensorInfos()) { - auto statusStr = !info.isEnabled ? "Disabled" + // The period being 0 means the sensor is disabled + auto statusStr = info.period == 0ns ? "Disabled" : info.isInitialized ? "Ok" : "Error"; - std::cout << "\t" << std::setw(16) << std::left << info.id << " " + std::cout << "\t" << std::setw(20) << std::left << info.id << " " << statusStr << std::endl; } -- GitLab