Skip to content

Commit

Permalink
Include complete flash logs for native targets for faster simulation
Browse files Browse the repository at this point in the history
  • Loading branch information
KoffeinFlummi committed Nov 26, 2023
1 parent cfc1c4b commit 4d20279
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 25 deletions.
3 changes: 1 addition & 2 deletions src/gui/panels/simulation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,12 @@ impl SimulationPanel {
ui.add_space(20.0);

let changed = data_source.settings != old_settings;
let released = false;
ui.horizontal(|ui| {
if ui.button("Reset").clicked() {
data_source.settings = SimulationSettings::default();
}

if ui.button("↻ Rerun").clicked() || (changed && released) {
if ui.button("↻ Rerun").clicked() || changed {
data_source.reset();
}
});
Expand Down
2 changes: 1 addition & 1 deletion src/gui/simulation_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ impl SimulationSettingsUiExt for SimulationSettings {
.selected_text(self.replication_log_index.map(|i| ARCHIVE[i].0).unwrap_or("None"))
.show_ui(ui, |ui| {
ui.selectable_value(&mut self.replication_log_index, None, "None");
for (i, (name, _, f)) in ARCHIVE.iter().enumerate() {
for (i, (name, _, f, _)) in ARCHIVE.iter().enumerate() {
if f.is_none() {
continue;
}
Expand Down
30 changes: 24 additions & 6 deletions src/gui/windows/archive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,43 @@ use log::*;

use crate::data_source::LogFileDataSource;

#[cfg(all(not(target_os = "wasm"), not(target_os = "android")))]
const FLASH_DARE_A: Option<&[u8]> = Some(include_bytes!("../../../archive/dare_launch_a_flash_filtered.json").as_slice());
#[cfg(any(target_os = "wasm", target_os = "android"))]
const FLASH_DARE_A: Option<&[u8]> = None;

#[cfg(all(not(target_os = "wasm"), not(target_os = "android")))]
const FLASH_DARE_B: Option<&[u8]> = Some(include_bytes!("../../../archive/dare_launch_b_flash_filtered.json").as_slice());
#[cfg(any(target_os = "wasm", target_os = "android"))]
const FLASH_DARE_B: Option<&[u8]> = None;

#[cfg(all(not(target_os = "wasm"), not(target_os = "android")))]
const FLASH_EUROC_2023: Option<&[u8]> = Some(include_bytes!("../../../archive/euroc_2023_flash_filtered.json").as_slice());
#[cfg(any(target_os = "wasm", target_os = "android"))]
const FLASH_EUROC_2023: Option<&[u8]> = None;

// Log files included with the application.
// TODO: migrate old launches
pub const ARCHIVE: [(&str, Option<&'static str>, Option<&'static str>); 5] = [
("Zülpich #1", None, None),
("Zülpich #2", None, None),
pub const ARCHIVE: [(&str, Option<&'static str>, Option<&'static str>, Option<&'static [u8]>); 5] = [
("Zülpich #1", None, None, None),
("Zülpich #2", None, None, None),
(
"DARE (FC A)",
Some("https://raw.githubusercontent.com/tudsat-rocket/sam/main/archive/dare_launch_a_telem_filtered.json"),
Some("https://raw.githubusercontent.com/tudsat-rocket/sam/main/archive/dare_launch_a_flash_filtered.json"),
FLASH_DARE_A,
),
(
"DARE (FC B)",
Some("https://raw.githubusercontent.com/tudsat-rocket/sam/main/archive/dare_launch_b_telem_filtered.json"),
Some("https://raw.githubusercontent.com/tudsat-rocket/sam/main/archive/dare_launch_b_flash_filtered.json"),
FLASH_DARE_B,
),
(
"EuRoC 2023 (ÆSIR Signý)",
Some("https://raw.githubusercontent.com/tudsat-rocket/sam/main/archive/euroc_2023_telem_filtered.json"),
Some("https://raw.githubusercontent.com/tudsat-rocket/sam/main/archive/euroc_2023_flash_filtered.json"),
FLASH_EUROC_2023,
),
];

Expand Down Expand Up @@ -150,16 +168,16 @@ impl ArchiveWindow {
.show(ctx, |ui| {
ui.add_space(10.0);

for (i, (title, telem, flash)) in ARCHIVE.iter().enumerate() {
for (i, (title, telem, flash_url, _flash_bytes)) in ARCHIVE.iter().enumerate() {
if i != 0 {
ui.separator();
}

ui.horizontal(|ui| {
ui.label(*title);
ui.with_layout(Layout::right_to_left(Align::Center), |ui| {
if ui.add_enabled(flash.is_some(), Button::new("🖴 Flash")).clicked() {
self.open_log(ctx, flash.unwrap());
if ui.add_enabled(flash_url.is_some(), Button::new("🖴 Flash")).clicked() {
self.open_log(ctx, flash_url.unwrap());
}

if ui.add_enabled(telem.is_some(), Button::new("📡 Telemetry")).clicked() {
Expand Down
28 changes: 12 additions & 16 deletions src/simulation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,7 @@ pub struct SimulationState {
}

impl SimulationState {
async fn load_archive_log(url: &str) -> Result<Vec<u8>, reqwest::Error> {
let res = reqwest::Client::new().get(url).send().await?;
Ok(res.bytes().await?.to_vec())
}

#[cfg(not(target_arch = "wasm32"))]
fn load_log_states(url: &str) -> Result<VecDeque<VehicleState>, reqwest::Error> {
let rt = tokio::runtime::Builder::new_current_thread().enable_io().enable_time().build().unwrap();
let bytes = rt.block_on(Self::load_archive_log(url))?;
fn load_log_states(bytes: &[u8]) -> Result<VecDeque<VehicleState>, reqwest::Error> {
let msgs = serde_json::from_slice::<Vec<DownlinkMessage>>(&bytes).unwrap();
Ok(msgs.into_iter().map(|x| x.into()).collect())
}
Expand All @@ -147,9 +139,9 @@ impl SimulationState {
.replication_log_index
.map(|i| ARCHIVE.get(i))
.flatten()
.map(|(_, _, flash)| *flash)
.map(|(_, _, _, flash_bytes)| *flash_bytes)
.flatten()
.map(|url| Self::load_log_states(url).unwrap())
.map(|bytes| Self::load_log_states(bytes).unwrap())
.unwrap_or_default();

#[cfg(target_arch = "wasm32")]
Expand Down Expand Up @@ -179,6 +171,7 @@ impl SimulationState {
let mut accelerometer1 = None;
let mut accelerometer2 = None;
let mut magnetometer = None;
let mut pressure_baro = None;
let mut altitude_baro = None;
if let Some(first) = remaining_replication_states.pop_front() {
time = first.time;
Expand All @@ -187,7 +180,8 @@ impl SimulationState {
accelerometer1 = first.accelerometer1;
accelerometer2 = first.accelerometer2;
magnetometer = first.magnetometer;
altitude_baro = first.pressure_baro.map(|p| 44307.694 * (1.0 - (p / 1013.25).powf(0.190284)));
pressure_baro = first.pressure_baro;
altitude_baro = pressure_baro.map(|p| 44307.694 * (1.0 - (p / 1013.25).powf(0.190284)));
state_estimator.altitude_ground = altitude_baro.unwrap();
}

Expand Down Expand Up @@ -215,6 +209,7 @@ impl SimulationState {
accelerometer1,
accelerometer2,
magnetometer,
pressure_baro,
altitude_baro,

remaining_replication_states,
Expand Down Expand Up @@ -332,11 +327,11 @@ impl SimulationState {
self.magnetometer.unwrap()
+ (next.magnetometer.unwrap() - self.magnetometer.unwrap()) / delta_time as f32,
);
let altitude_baro = next.pressure_baro.map(|p| 44307.694 * (1.0 - (p / 1013.25).powf(0.190284)));
self.altitude_baro = Some(
self.altitude_baro.unwrap()
+ (altitude_baro.unwrap() - self.altitude_baro.unwrap()) / delta_time as f32,
self.pressure_baro = Some(
self.pressure_baro.unwrap()
+ (next.pressure_baro.unwrap() - self.pressure_baro.unwrap()) / delta_time as f32,
);
self.altitude_baro = self.pressure_baro.map(|p| 44307.694 * (1.0 - (p / 1013.25).powf(0.190284)));
}

false
Expand Down Expand Up @@ -477,6 +472,7 @@ impl From<&SimulationState> for VehicleState {
accelerometer1: ss.accelerometer1,
accelerometer2: ss.accelerometer2,
magnetometer: ss.magnetometer,
pressure_baro: ss.pressure_baro,
..Default::default()
}
} else {
Expand Down

0 comments on commit 4d20279

Please sign in to comment.