diff --git a/README.md b/README.md index a477147b6..ab4f87535 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[![Giraffe Unit Tests](https://github.com/joshua-jerred/Giraffe/actions/workflows/unit_tests.yml/badge.svg?branch=main)](https://github.com/joshua-jerred/Giraffe/actions/workflows/unit_tests.yml) +[![Giraffe Unit Tests](https://github.com/joshua-jerred/Giraffe/actions/workflows/giraffe_ci.yml/badge.svg)](https://github.com/joshua-jerred/Giraffe/actions/workflows/giraffe_ci.yml) # Giraffe ### A Unified Flight Command and Control System diff --git a/lib/Boost_erSeat b/lib/Boost_erSeat index deb4c1aab..a09b21c53 160000 --- a/lib/Boost_erSeat +++ b/lib/Boost_erSeat @@ -1 +1 @@ -Subproject commit deb4c1aabb5abd0cce59a0fd706f422d38f526ac +Subproject commit a09b21c53c849f9645dc2dbd5d9162e6b6bda7af diff --git a/src/data_link/include/gdl_transport_layer.hpp b/src/data_link/include/gdl_transport_layer.hpp index db1f8dc2b..be3e2341e 100644 --- a/src/data_link/include/gdl_transport_layer.hpp +++ b/src/data_link/include/gdl_transport_layer.hpp @@ -143,7 +143,7 @@ class TransportLayer { GdlConfig config_; - BoosterSeat::Timer timer_; + bst::Timer timer_; Message current_message_{}; diff --git a/src/flight_system/extensions/adc_extension_base.hpp b/src/flight_system/extensions/adc_extension_base.hpp index 117a9c2e6..6d7fee6c6 100644 --- a/src/flight_system/extensions/adc_extension_base.hpp +++ b/src/flight_system/extensions/adc_extension_base.hpp @@ -119,7 +119,7 @@ template class AdcExtensionBase : public Extension { const uint32_t adc_resolution_ = AdcResolution; AdcConfig adc_config_{}; - BoosterSeat::Timer adc_watchdog_; + bst::Timer adc_watchdog_; }; } // namespace extension diff --git a/src/flight_system/extensions/bme280.cpp b/src/flight_system/extensions/bme280.cpp index a2775389f..5b4aab55e 100644 --- a/src/flight_system/extensions/bme280.cpp +++ b/src/flight_system/extensions/bme280.cpp @@ -42,7 +42,7 @@ void Bme280Extension::startup() { constexpr uint32_t kStartupTimeout = 5000; // ms constexpr uint32_t kStartupRetryDelay = 100; // ms - BoosterSeat::Timer startup_timer(kStartupTimeout); + bst::Timer startup_timer(kStartupTimeout); startup_timer.reset(); StartupState state = StartupState::I2C_CONNECT; diff --git a/src/flight_system/extensions/bme280.hpp b/src/flight_system/extensions/bme280.hpp index 96f31cde1..8b3c5011b 100644 --- a/src/flight_system/extensions/bme280.hpp +++ b/src/flight_system/extensions/bme280.hpp @@ -143,12 +143,12 @@ class Bme280Extension : public Extension { * @brief A timer that is used to read the sensor's compensation data at a * configured interval. */ - BoosterSeat::Timer compensation_timer_; + bst::Timer compensation_timer_; /** * @brief A timer used with loop() to verify that the sensor is functioning. */ - BoosterSeat::Timer read_timer_; + bst::Timer read_timer_; uint32_t raw_temperature_ = 0; uint32_t raw_pressure_ = 0; diff --git a/src/flight_system/extensions/ds18b20.hpp b/src/flight_system/extensions/ds18b20.hpp index 0facbc0dc..2a5c488c0 100644 --- a/src/flight_system/extensions/ds18b20.hpp +++ b/src/flight_system/extensions/ds18b20.hpp @@ -36,8 +36,8 @@ class Ds18b20Extension : public Extension { bool init(DiagnosticId &fault); bool readData(DiagnosticId &fault); - BoosterSeat::Timer init_timer_; - BoosterSeat::Timer read_timer_; + bst::Timer init_timer_; + bst::Timer read_timer_; OneWireInterface device_{}; double temperature_ = 0.0; // degrees C diff --git a/src/flight_system/extensions/extension_base.cpp b/src/flight_system/extensions/extension_base.cpp index fbf582cf4..3bd655e66 100644 --- a/src/flight_system/extensions/extension_base.cpp +++ b/src/flight_system/extensions/extension_base.cpp @@ -61,7 +61,7 @@ void Extension::stop() { } stop_flag_ = true; // signal the stop - BoosterSeat::Timer timer(kExtensionStopTimeoutMs); + bst::Timer timer(kExtensionStopTimeoutMs); while (!timer.isDone()) { BoosterSeat::threadSleep(kExtensionStopCheckIntervalMs); @@ -176,7 +176,7 @@ void Extension::sleep() { std::clamp(sleep_ms / 10, kMinimumSleepTimeMs, kMaximumCheckInterval); // Sleep for the specified amount of time - BoosterSeat::Timer timer(sleep_ms); + bst::Timer timer(sleep_ms); while (!timer.isDone()) { BoosterSeat::threadSleep(check_interval); if (stopRequested()) { diff --git a/src/flight_system/extensions/i2c_extension_adapter.hpp b/src/flight_system/extensions/i2c_extension_adapter.hpp index b2271e864..4e8567e13 100644 --- a/src/flight_system/extensions/i2c_extension_adapter.hpp +++ b/src/flight_system/extensions/i2c_extension_adapter.hpp @@ -77,7 +77,7 @@ class I2cExtensionAdapter { I2cInterface i2c_; private: - BoosterSeat::Timer handshake_timer_; + bst::Timer handshake_timer_; uint32_t retry_delay_ms_; }; diff --git a/src/flight_system/extensions/samm8q.cpp b/src/flight_system/extensions/samm8q.cpp index 8203feaac..894dde059 100644 --- a/src/flight_system/extensions/samm8q.cpp +++ b/src/flight_system/extensions/samm8q.cpp @@ -43,7 +43,7 @@ void SamM8qExtension::startup() { constexpr uint32_t kStartupTimeout = 5000; // ms constexpr uint32_t kStartupRetryDelay = 400; // ms - BoosterSeat::Timer startup_timer(kStartupTimeout); + bst::Timer startup_timer(kStartupTimeout); startup_timer.reset(); StartupState start_state = StartupState::I2C_CONNECT; diff --git a/src/flight_system/extensions/samm8q.hpp b/src/flight_system/extensions/samm8q.hpp index 4e6d75109..52d804f9c 100644 --- a/src/flight_system/extensions/samm8q.hpp +++ b/src/flight_system/extensions/samm8q.hpp @@ -87,18 +87,18 @@ class SamM8qExtension : public Extension { /** * @brief This timer should have the largest value of all timers. */ - BoosterSeat::Timer primary_watchdog_timer_; + bst::Timer primary_watchdog_timer_; /** * @brief */ - BoosterSeat::Timer read_watchdog_timer_; + bst::Timer read_watchdog_timer_; /** * @brief The timer used to give the sensor time to reset after the reset * command is sent. */ - BoosterSeat::Timer reset_wait_timer_; + bst::Timer reset_wait_timer_; /** * @brief Use to keep track of how many times we have attempted to configure diff --git a/src/flight_system/extensions/simulated_extensions.hpp b/src/flight_system/extensions/simulated_extensions.hpp index 69408aa15..65cbd6b48 100644 --- a/src/flight_system/extensions/simulated_extensions.hpp +++ b/src/flight_system/extensions/simulated_extensions.hpp @@ -94,28 +94,33 @@ class SimGpsSensor : public Extension { public: SimGpsSensor(ExtensionResources &resources, cfg::ExtensionMetadata metadata) : Extension(resources, metadata) { + gps_frame.gps_utc_time = BoosterSeat::clck::now(); + gps_frame.is_valid = true; + gps_frame.fix = data::GpsFix::FIX_3D; + gps_frame.num_satellites = 10; + gps_frame.latitude = 40.0; + gps_frame.longitude = -80.0; + gps_frame.horz_accuracy = 5.0; + gps_frame.altitude = 1000.0; + gps_frame.vert_accuracy = 1.0; + gps_frame.vertical_speed = 1.0; + gps_frame.horizontal_speed = 1.0; + gps_frame.speed_accuracy = 1.0; + gps_frame.heading_of_motion = 1.0; + gps_frame.heading_accuracy = 1.0; } void loop() override { - data::GpsFrame frame; - frame.gps_utc_time = BoosterSeat::clck::now(); - frame.fix = data::GpsFix::FIX_3D; - frame.num_satellites = 10; - frame.latitude = 40.0; - frame.longitude = -80.0; - frame.horz_accuracy = 5.0; - frame.altitude = 1000.0; - frame.vert_accuracy = 5.0; - frame.vertical_speed = 0.0; - frame.horizontal_speed = 0.0; - frame.speed_accuracy = 0.0; - frame.heading_of_motion = 0.0; - frame.heading_accuracy = 0.0; - data(frame); + gps_frame.gps_utc_time = BoosterSeat::clck::now(); + gps_frame.latitude += increasing_ ? 0.0001 : -0.0001; + gps_frame.longitude += increasing_ ? 0.0001 : -0.0001; + gps_frame.altitude += increasing_ ? 0.1 : -0.1; + data(gps_frame); } private: - bool increasing_ = false; + data::GpsFrame gps_frame{}; + bool increasing_ = true; }; class SimImuSensor : public Extension { diff --git a/src/flight_system/interface/ubx/ubx_protocol.cpp b/src/flight_system/interface/ubx/ubx_protocol.cpp index 4e5c263d6..87b099c2e 100644 --- a/src/flight_system/interface/ubx/ubx_protocol.cpp +++ b/src/flight_system/interface/ubx/ubx_protocol.cpp @@ -184,7 +184,7 @@ bool readNextUBX(I2cInterface &i2c, UBXMessage &message) { bool found_sync = false; I2cInterface::Result result; - BoosterSeat::Timer timer(kTimeoutMs); + bst::Timer timer(kTimeoutMs); while (!timer.isDone()) { stream_size = getStreamSize(i2c); if (stream_size <= 8) { @@ -539,7 +539,7 @@ ACK setDynamicModel(I2cInterface &i2c, const DYNAMIC_MODEL model) { bool pollMessage(I2cInterface &i2c, UBXMessage &message, const uint8_t msg_class, const uint8_t msg_id, const int expected_size, const unsigned int timeout_ms) { - BoosterSeat::Timer timer(timeout_ms); + bst::Timer timer(timeout_ms); while (!timer.isDone()) { // Check if the stream is empty, if not, flush it. diff --git a/src/flight_system/modules/console/console_pages.cpp b/src/flight_system/modules/console/console_pages.cpp index 559800e2d..f4df6a33c 100644 --- a/src/flight_system/modules/console/console_pages.cpp +++ b/src/flight_system/modules/console/console_pages.cpp @@ -312,6 +312,7 @@ void console_pages::Pages::location() { auto data = shared_data_.blocks.location_data.get(); // auto last_valid = data.last_valid_gps_frame; auto cur = data.last_gps_frame; + auto last_valid = data.last_valid_gps_frame; // clang-format off content_ = { " -- Most Recent GPS Frame -- ", @@ -326,7 +327,21 @@ void console_pages::Pages::location() { "Accuracy - Hor, Vert, H/S: " + BoosterSeat::string::f2s(cur.horz_accuracy, 1) + " m, " + BoosterSeat::string::f2s(cur.vert_accuracy, 1) + " m, " + - BoosterSeat::string::f2s(cur.horizontal_speed, 1) + " m/s" + BoosterSeat::string::f2s(cur.horizontal_speed, 1) + " m/s", + "", + " -- Last Valid GPS Frame -- ", + "Fix, Num Sats, UTC: " + data::K_GPS_FIX_TO_STRING_MAP.at(last_valid.fix) + ", " + + std::to_string(last_valid.num_satellites) + ", utc time", + "Lat, Lon, H/S: " + BoosterSeat::string::f2s(last_valid.latitude, 6) + ", " + + BoosterSeat::string::f2s(last_valid.longitude, 6) + ", " + + BoosterSeat::string::f2s(last_valid.horizontal_speed, 1) + " m/s", + "ALT, V/S, HDG: " + BoosterSeat::string::f2s(last_valid.altitude, 1) + + " m" + ", " + BoosterSeat::string::f2s(last_valid.heading_of_motion, 1) + + " deg", + "Accuracy - Hor, Vert, H/S: " + + BoosterSeat::string::f2s(last_valid.horz_accuracy, 1) + " m, " + + BoosterSeat::string::f2s(last_valid.vert_accuracy, 1) + " m, " + + BoosterSeat::string::f2s(last_valid.horizontal_speed, 1) + " m/s" }; // clang-format on } diff --git a/src/flight_system/modules/data/data_formatting.cpp b/src/flight_system/modules/data/data_formatting.cpp index ea2c5aecc..913b9e191 100644 --- a/src/flight_system/modules/data/data_formatting.cpp +++ b/src/flight_system/modules/data/data_formatting.cpp @@ -34,6 +34,7 @@ std::string DataFormatter::fullFrame() { addComponent(DataFrameComponent::SYSTEM_INFO, frame); addComponent(DataFrameComponent::ENVIRONMENTAL_DATA, frame); addComponent(DataFrameComponent::TELEMETRY_DATA, frame); + addComponent(DataFrameComponent::CALCULATED_DATA, frame); return frame.dump(); } @@ -86,6 +87,9 @@ void DataFormatter::addComponent(DataFrameComponent component, Json &frame) { frame["data"]["telemetry"] = shared_data_.blocks.telemetry_module_stats.get().toJson(); break; + case DataFrameComponent::CALCULATED_DATA: + frame["data"]["calculated"] = + shared_data_.blocks.calculated_data.get().toJson(); } } diff --git a/src/flight_system/modules/data/data_formatting.hpp b/src/flight_system/modules/data/data_formatting.hpp index 17421f352..3d5e503de 100644 --- a/src/flight_system/modules/data/data_formatting.hpp +++ b/src/flight_system/modules/data/data_formatting.hpp @@ -31,7 +31,8 @@ enum class DataFrameComponent { SERVER_STATS, SYSTEM_INFO, ENVIRONMENTAL_DATA, - TELEMETRY_DATA + TELEMETRY_DATA, + CALCULATED_DATA }; class DataFormatter { diff --git a/src/flight_system/modules/data/data_module.cpp b/src/flight_system/modules/data/data_module.cpp index a3ce1f686..525c1c0cf 100644 --- a/src/flight_system/modules/data/data_module.cpp +++ b/src/flight_system/modules/data/data_module.cpp @@ -30,10 +30,10 @@ void modules::DataModule::loop() { configuration_.data_module_log.getErrorLogStrategy(); } - influxdb_enabled_ = configuration_.data_module_influxdb.getInfluxEnabled(); - processAllStreams(); + calculateCalculatedData(); + if (data_file_enabled_ && (data_file_logging_strategy_ == cfg::gEnum::LogStrategy::INTERVAL || data_file_logging_strategy_ == @@ -47,6 +47,7 @@ void modules::DataModule::loop() { data_log_.logErrorFrame(); } + influxdb_enabled_ = configuration_.data_module_influxdb.getInfluxEnabled(); if (influxdb_enabled_) { influxdb_.writeFrames(); // timer taken care of inside of influxdb_ } @@ -147,6 +148,7 @@ void modules::DataModule::processDataPacket(const data::DataPacket &packet) { void modules::DataModule::parseGeneralDataPacket( const data::DataPacket &packet) { (void)packet; + /// @todo Implement general data packet parsing // Process packet here } @@ -260,6 +262,7 @@ void modules::DataModule::processGpsFramePacket( location_data.last_gps_frame = packet.frame; location_data.current_gps_fix = packet.frame.fix; + if (isGpsFrameValid(packet.frame)) { location_data.last_valid_gps_frame = packet.frame; location_data.last_valid_gps_fix = packet.frame.fix; @@ -281,3 +284,121 @@ void modules::DataModule::processImuFramePacket( shared_data_.blocks.imu_data.set(data_block); } + +/** + * @brief Calculates the altitude in meters from the pressure in hPa. + * @param pressure The pressure in hPa. + * @return double The altitude in meters. + * + * @todo Detect initial launch (movement from the launch point). + */ +inline double calculatePressureAltitude(double pressure) { + return (1 - std::pow(pressure / 1013.25, 0.190284)) * 145366.45 * 0.3048; +} + +void modules::DataModule::calculateCalculatedData() { + // Calculate pressure altitude + auto pres_data = shared_data_.frames.env_pres.getAll(); + + if (pres_data.size() == 0) { + calculated_data_.pressure_altitude_valid = false; + } else { + std::string pres_string = pres_data.begin()->second.value; + try { + double pres = std::stod(pres_string); + calculated_data_.pressure_altitude_m = calculatePressureAltitude(pres); + calculated_data_.pressure_altitude_valid = true; + } catch (std::invalid_argument &e) { + calculated_data_.pressure_altitude_valid = false; + } + } + + // Calculate distance traveled and the distance from the launch point + /// @brief The distance that must be traveled for the distance traveled to be + /// updated. + constexpr double MOVEMENT_THRESHOLD_KM = 0.25; + + auto gps_data = shared_data_.blocks.location_data.get(); + + if (!launch_gps_point_set_) { // No launch point set yet + + if (gps_data.last_valid_gps_frame.fix == data::GpsFix::FIX_2D || + gps_data.last_valid_gps_frame.fix == data::GpsFix::FIX_3D) { + try { + launch_gps_point_ = + bst::geo::Point(gps_data.last_valid_gps_frame.latitude, + gps_data.last_valid_gps_frame.longitude); + last_gps_point_ = launch_gps_point_; + launch_gps_point_set_ = true; + info("Launch point set to: " + + std::to_string(launch_gps_point_.latitude()) + ", " + + std::to_string(launch_gps_point_.longitude())); + /// @todo Report the launch position as a data point + } catch (const BoosterSeat::BoosterSeatException &e) { + /// @todo Report this error + } + } + + } else if (gps_data.last_valid_gps_frame.fix == data::GpsFix::FIX_2D || + gps_data.last_valid_gps_frame.fix == data::GpsFix::FIX_3D) { + try { + bst::geo::Point current_point(gps_data.last_valid_gps_frame.latitude, + gps_data.last_valid_gps_frame.longitude); + double new_distance = bst::geo::distance(last_gps_point_, current_point); + if (new_distance >= MOVEMENT_THRESHOLD_KM) { + distance_traveled_ += new_distance; + last_gps_point_ = current_point; + + calculated_data_.distance_traveled_m = distance_traveled_ * 1000; + calculated_data_.distance_traveled_valid = true; + } + + // distance from launch point + calculated_data_.distance_from_launch_m = + bst::geo::distance(launch_gps_point_, current_point) * + 1000; // convert to meters + calculated_data_.distance_from_launch_valid = true; + } catch (const BoosterSeat::BoosterSeatException &e) { + /// @todo Report this error + } + + // Maximum speeds + if (gps_data.last_valid_gps_frame.horizontal_speed > + calculated_data_.max_horizontal_speed_mps) { + calculated_data_.max_horizontal_speed_mps = + gps_data.last_valid_gps_frame.horizontal_speed; + calculated_data_.max_speed_valid = true; + } + + if (gps_data.last_valid_gps_frame.vertical_speed > + calculated_data_.max_vertical_speed_mps) { + calculated_data_.max_vertical_speed_mps = + gps_data.last_valid_gps_frame.vertical_speed; + calculated_data_.max_speed_valid = true; + } + + // Average speed + average_horizontal_speed_.count( + gps_data.last_valid_gps_frame.horizontal_speed); + average_vertical_speed_.count(gps_data.last_valid_gps_frame.vertical_speed); + + calculated_data_.average_horiz_speed_mps_5min = + average_horizontal_speed_.getAverage(); + calculated_data_.average_vert_speed_mps_5min = + average_vertical_speed_.getAverage(); + } else { + /// @todo put this on a timer instead. Otherwise it will be reported as + /// invalid if there is a single invalid gps frame. Reset the timer if + /// there is a valid frame. + + calculated_data_.distance_traveled_valid = false; + calculated_data_.distance_from_launch_valid = false; + calculated_data_.average_speed_valid = false; + + if (average_speed_timer_.isDone()) { + calculated_data_.average_speed_valid = false; + } + } + + shared_data_.blocks.calculated_data.set(calculated_data_); +} \ No newline at end of file diff --git a/src/flight_system/modules/data/data_module.hpp b/src/flight_system/modules/data/data_module.hpp index 763b8f715..58ff11c88 100644 --- a/src/flight_system/modules/data/data_module.hpp +++ b/src/flight_system/modules/data/data_module.hpp @@ -19,6 +19,10 @@ #include +#include +#include +#include + #include "data_log.hpp" #include "influxdb.hpp" #include "module.hpp" @@ -172,6 +176,17 @@ class DataModule : public Module { */ void processImuFramePacket(const data::ImuFramePacket &packet); + /** + * @brief Use existing data to calculate the data that can be calculated. + * @todo This function is not implemented yet. + */ + void calculateCalculatedData(); + /** + * @brief Buffer for the calculated data. Used by the calculateCalculatedData + * method. + */ + data::blocks::CalculatedData calculated_data_{}; + /** * @brief The data log object, used to log data and errors to files. */ @@ -221,6 +236,43 @@ class DataModule : public Module { */ cfg::gEnum::ErrorLogStrategy error_file_logging_strategy_ = cfg::gEnum::ErrorLogStrategy::ALL; + + /** + * @brief This timer is used to determine when to update the gps path for the + * purpose of calculating distance traveled. + * @see calculateCalculatedData + */ + bst::Timer gps_distance_update_timer_{}; + + /** + * @brief The last gps point. Used to calculate distance traveled. + * @see calculateCalculatedData + */ + bst::geo::Point last_gps_point_{}; + + /** + * @brief The initial gps point. This is the "launch point" + */ + bst::geo::Point launch_gps_point_{}; + + /** + * @brief True if the initial gps point has been set. + */ + bool launch_gps_point_set_ = false; + + /** + * @brief The distance traveled in km. + */ + double distance_traveled_ = 0.0; + + /** + * @brief Rolling average of the horizontal speed. Once every 15 seconds (20 + * in a 5 minute span) + */ + BoosterSeat::RollingAverage average_horizontal_speed_{20}; + BoosterSeat::RollingAverage average_vertical_speed_{20}; + + bst::Timer average_speed_timer_{15 * 1000}; }; } // namespace modules diff --git a/src/flight_system/modules/data/influxdb.hpp b/src/flight_system/modules/data/influxdb.hpp index 20af6571c..64e7fd9fd 100644 --- a/src/flight_system/modules/data/influxdb.hpp +++ b/src/flight_system/modules/data/influxdb.hpp @@ -60,7 +60,7 @@ class InfluxDb { private: bool testConnection(); - BoosterSeat::Timer frame_timer_{}; + bst::Timer frame_timer_{}; std::string url_{}; std::string org_{}; diff --git a/src/flight_system/modules/extension/extension_module.cpp b/src/flight_system/modules/extension/extension_module.cpp index a2d4726db..e5724696a 100644 --- a/src/flight_system/modules/extension/extension_module.cpp +++ b/src/flight_system/modules/extension/extension_module.cpp @@ -20,6 +20,20 @@ #include +inline constexpr bool LOAD_SIMULATED_EXTENSIONS = true; +static const std::vector SIMULATED_EXTENSIONS = { + cfg::ExtensionMetadata{ + "sim_temp", true, cfg::gEnum::ExtensionType::SIM_TEMP, 1000, false, ""}, + cfg::ExtensionMetadata{ + "sim_pres", true, cfg::gEnum::ExtensionType::SIM_PRES, 1000, false, ""}, + cfg::ExtensionMetadata{"sim_hum", true, cfg::gEnum::ExtensionType::SIM_HUM, + 1000, false, ""}, + cfg::ExtensionMetadata{"sim_gps", true, cfg::gEnum::ExtensionType::SIM_GPS, + 1000, false, ""}, + cfg::ExtensionMetadata{"sim_imu", true, cfg::gEnum::ExtensionType::SIM_IMU, + 1000, false, ""}, +}; + namespace modules { static MetaData metadata("extension_module", @@ -35,6 +49,21 @@ ExtensionModule::ExtensionModule(data::SharedData &shared_data, void ExtensionModule::startup() { updateLocalConfig(); // Load in the config for the extension. + // Load in the simulated extensions. + if (LOAD_SIMULATED_EXTENSIONS) { + for (auto &ext_meta : SIMULATED_EXTENSIONS) { + // Create the extension. + auto extension = createExtension(ext_meta); + if (!extension.has_value()) { + error(DiagnosticId::EXTENSION_MODULE_failedToCreate, ext_meta.name); + continue; + } + info("Loaded simulated extension: " + ext_meta.name); + // Add the extension to the list of extensions. + extensions_.push_back(extension.value()); + } + } + // Load in the extensions. for (auto &ext_meta : configuration_.extensions.getExtensions()) { // Create the extension. @@ -43,7 +72,7 @@ void ExtensionModule::startup() { error(DiagnosticId::EXTENSION_MODULE_failedToCreate, ext_meta.name); continue; } - + info("Loaded extension: " + ext_meta.name); // Add the extension to the list of extensions. extensions_.push_back(extension.value()); } diff --git a/src/flight_system/modules/extension/extension_module.hpp b/src/flight_system/modules/extension/extension_module.hpp index 33dd32cba..623c666a4 100644 --- a/src/flight_system/modules/extension/extension_module.hpp +++ b/src/flight_system/modules/extension/extension_module.hpp @@ -90,8 +90,8 @@ class ExtensionModule : public Module { * @brief The timer used to determine if the extension has started up * in the allotted time. */ - BoosterSeat::Timer startup_shutdown_timer; - BoosterSeat::Timer restart_timer; + bst::Timer startup_shutdown_timer; + bst::Timer restart_timer; }; void startup() override; @@ -121,7 +121,7 @@ class ExtensionModule : public Module { std::vector extension_metadata_{}; - BoosterSeat::Timer status_polling_timer_{}; + bst::Timer status_polling_timer_{}; data::blocks::ExtensionModuleStats stats_{}; diff --git a/src/flight_system/modules/server/server_module.hpp b/src/flight_system/modules/server/server_module.hpp index 9ee947d2a..a6866663f 100644 --- a/src/flight_system/modules/server/server_module.hpp +++ b/src/flight_system/modules/server/server_module.hpp @@ -86,12 +86,12 @@ class ServerModule : public Module { * @brief Timer for the rolling average. * Used to call 'server_socket_.oneSecondTick()' every second. */ - BoosterSeat::Timer rolling_average_timer_ = {1000}; + bst::Timer rolling_average_timer_ = {1000}; /** * @brief Used to update the 'connected' status of the server. */ - BoosterSeat::Timer connected_timeout_ = {2000}; + bst::Timer connected_timeout_ = {2000}; }; } // namespace modules diff --git a/src/flight_system/shared_data/blocks.hpp b/src/flight_system/shared_data/blocks.hpp index f648ac87c..d9dcbbb1a 100644 --- a/src/flight_system/shared_data/blocks.hpp +++ b/src/flight_system/shared_data/blocks.hpp @@ -345,6 +345,45 @@ struct TelemetryModuleStats { } }; +/** + * @brief Data that is calculated from other data. + */ +struct CalculatedData { + int32_t pressure_altitude_m = 0; + bool pressure_altitude_valid = false; + + int32_t distance_traveled_m = 0; + bool distance_traveled_valid = false; + + int32_t distance_from_launch_m = 0; + bool distance_from_launch_valid = false; + + int32_t average_horiz_speed_mps_5min = 0; + int32_t average_vert_speed_mps_5min = 0; + bool average_speed_valid = false; + + int32_t max_horizontal_speed_mps = 0; + int32_t max_vertical_speed_mps = 0; + bool max_speed_valid = false; + + Json toJson() { + Json json_data; + json_data["pressure_altitude_m"] = pressure_altitude_m; + json_data["pressure_altitude_valid"] = pressure_altitude_valid; + json_data["distance_traveled_m"] = distance_traveled_m; + json_data["distance_traveled_valid"] = distance_traveled_valid; + json_data["distance_from_launch_m"] = distance_from_launch_m; + json_data["distance_from_launch_valid"] = distance_from_launch_valid; + json_data["average_speed_horiz_mps_5min"] = average_horiz_speed_mps_5min; + json_data["average_speed_vert_mps_5min"] = average_vert_speed_mps_5min; + json_data["average_speed_valid"] = average_speed_valid; + json_data["max_horiz_speed_mps"] = max_horizontal_speed_mps; + json_data["max_vert_speed_mps"] = max_vertical_speed_mps; + json_data["max_speed_valid"] = max_speed_valid; + return json_data; + } +}; + } // namespace blocks } // namespace data diff --git a/src/flight_system/shared_data/shared_data.hpp b/src/flight_system/shared_data/shared_data.hpp index 54a1a4e1a..0ac992e43 100644 --- a/src/flight_system/shared_data/shared_data.hpp +++ b/src/flight_system/shared_data/shared_data.hpp @@ -52,6 +52,7 @@ struct SharedBlocks { blocks::Block imu_data{}; blocks::Block camera{}; blocks::Block telemetry_module_stats{}; + blocks::Block calculated_data{}; }; struct Frames {