Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calculated data #164

Merged
merged 5 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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 <!-- omit from toc -->
### A Unified Flight Command and Control System <!-- omit from toc -->
Expand Down
2 changes: 1 addition & 1 deletion src/data_link/include/gdl_transport_layer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ class TransportLayer {

GdlConfig config_;

BoosterSeat::Timer timer_;
bst::Timer timer_;

Message current_message_{};

Expand Down
2 changes: 1 addition & 1 deletion src/flight_system/extensions/adc_extension_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ template <uint32_t AdcResolution> class AdcExtensionBase : public Extension {
const uint32_t adc_resolution_ = AdcResolution;

AdcConfig adc_config_{};
BoosterSeat::Timer adc_watchdog_;
bst::Timer adc_watchdog_;
};

} // namespace extension
Expand Down
2 changes: 1 addition & 1 deletion src/flight_system/extensions/bme280.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/flight_system/extensions/bme280.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/flight_system/extensions/ds18b20.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/flight_system/extensions/extension_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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()) {
Expand Down
2 changes: 1 addition & 1 deletion src/flight_system/extensions/i2c_extension_adapter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class I2cExtensionAdapter {
I2cInterface i2c_;

private:
BoosterSeat::Timer handshake_timer_;
bst::Timer handshake_timer_;
uint32_t retry_delay_ms_;
};

Expand Down
2 changes: 1 addition & 1 deletion src/flight_system/extensions/samm8q.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions src/flight_system/extensions/samm8q.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
37 changes: 21 additions & 16 deletions src/flight_system/extensions/simulated_extensions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions src/flight_system/interface/ubx/ubx_protocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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.
Expand Down
17 changes: 16 additions & 1 deletion src/flight_system/modules/console/console_pages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 -- ",
Expand All @@ -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
}
Expand Down
4 changes: 4 additions & 0 deletions src/flight_system/modules/data/data_formatting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down Expand Up @@ -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();
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/flight_system/modules/data/data_formatting.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ enum class DataFrameComponent {
SERVER_STATS,
SYSTEM_INFO,
ENVIRONMENTAL_DATA,
TELEMETRY_DATA
TELEMETRY_DATA,
CALCULATED_DATA
};

class DataFormatter {
Expand Down
Loading