2025-11-23 18:40:48 +00:00
|
|
|
mod engine;
|
|
|
|
|
use engine::*;
|
2025-11-23 23:43:48 +00:00
|
|
|
mod camera;
|
2026-02-05 20:26:30 +00:00
|
|
|
mod config;
|
2025-12-07 00:41:00 +00:00
|
|
|
mod drone;
|
2026-02-05 20:26:30 +00:00
|
|
|
mod helpers;
|
2026-02-06 13:59:27 +00:00
|
|
|
mod logger;
|
2025-11-28 20:39:09 +00:00
|
|
|
mod rendering;
|
2026-02-05 20:26:30 +00:00
|
|
|
mod simulation;
|
2025-11-23 23:43:48 +00:00
|
|
|
|
2025-11-23 18:40:48 +00:00
|
|
|
mod graphics_util;
|
|
|
|
|
|
2026-02-05 20:26:30 +00:00
|
|
|
use crate::drone::input::*;
|
|
|
|
|
use crate::simulation::{SimMode, Simulation};
|
2025-11-28 20:39:09 +00:00
|
|
|
|
2026-02-05 20:26:30 +00:00
|
|
|
use crate::config::SimulationConfig;
|
|
|
|
|
use helpers::list_files;
|
|
|
|
|
use std::fs;
|
|
|
|
|
|
|
|
|
|
const INPUTS_DIR: &str = "inputs/";
|
2026-02-06 17:11:04 +00:00
|
|
|
const CONFIGS_DIR: &str = "configurations/final/";
|
2026-02-05 20:26:30 +00:00
|
|
|
const RESULTS_DIR: &str = "results/";
|
|
|
|
|
|
|
|
|
|
use std::path::PathBuf;
|
|
|
|
|
use std::thread::JoinHandle;
|
|
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
|
run_batch();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn run_batch() {
|
|
|
|
|
let _ = fs::remove_dir_all(RESULTS_DIR);
|
|
|
|
|
let _ = fs::create_dir_all(RESULTS_DIR);
|
|
|
|
|
|
|
|
|
|
let input_files = list_files(INPUTS_DIR);
|
|
|
|
|
let config_files = list_files(CONFIGS_DIR);
|
|
|
|
|
|
|
|
|
|
let mut handles: Vec<JoinHandle<()>> = Default::default();
|
|
|
|
|
|
|
|
|
|
for input_path in input_files {
|
|
|
|
|
for config_path in &config_files {
|
|
|
|
|
let cp = config_path.clone();
|
|
|
|
|
let ip = input_path.clone();
|
|
|
|
|
handles.push(std::thread::spawn(move || {
|
|
|
|
|
run(&ip, &cp);
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
for handle in handles {
|
|
|
|
|
handle.join().unwrap();
|
2025-12-08 22:34:01 +00:00
|
|
|
}
|
2026-02-05 20:26:30 +00:00
|
|
|
|
|
|
|
|
println!("All simulations completed.");
|
2025-12-08 22:34:01 +00:00
|
|
|
}
|
|
|
|
|
|
2026-02-05 20:26:30 +00:00
|
|
|
fn run(input_path: &PathBuf, config_path: &PathBuf) {
|
|
|
|
|
let input_name = input_path.file_stem().unwrap().to_string_lossy();
|
2026-01-06 16:41:14 +00:00
|
|
|
|
2026-02-05 20:26:30 +00:00
|
|
|
let inputs = InputRecording::load_inputs_from_csv(input_path.to_str().unwrap())
|
|
|
|
|
.expect("Failed to load input recording");
|
|
|
|
|
let config_name = config_path.file_stem().unwrap().to_string_lossy();
|
|
|
|
|
|
|
|
|
|
let config: SimulationConfig =
|
|
|
|
|
toml::from_str(&fs::read_to_string(config_path).unwrap()).expect("Invalid config file");
|
|
|
|
|
|
|
|
|
|
println!(
|
|
|
|
|
"Running simulation: input={} config={}",
|
|
|
|
|
input_name, config_name
|
2025-12-15 00:08:10 +00:00
|
|
|
);
|
|
|
|
|
|
2026-02-05 20:26:30 +00:00
|
|
|
let mut world = World::new(config.tickrate);
|
|
|
|
|
|
|
|
|
|
let drone = drone::Drone::new(
|
2025-12-15 00:08:10 +00:00
|
|
|
&mut world,
|
2026-02-05 20:26:30 +00:00
|
|
|
Box::new(drone::stacked::StackedController::new(config.clone())),
|
2025-12-15 00:08:10 +00:00
|
|
|
drone::MotorCharacteristics {
|
2026-02-05 20:26:30 +00:00
|
|
|
max_thrust: config.max_thrust,
|
|
|
|
|
max_torque: config.max_torque,
|
|
|
|
|
time_constant: config.time_constant,
|
2025-12-15 00:08:10 +00:00
|
|
|
..Default::default()
|
|
|
|
|
},
|
2026-02-05 20:26:30 +00:00
|
|
|
config.mass,
|
2025-12-15 00:08:10 +00:00
|
|
|
);
|
|
|
|
|
|
2026-02-05 20:26:30 +00:00
|
|
|
let result_file = format!("{}/{}_{}.csv", RESULTS_DIR, input_name, config_name);
|
2025-12-15 00:08:10 +00:00
|
|
|
|
2026-02-05 20:26:30 +00:00
|
|
|
let mut sim = Simulation::new(
|
|
|
|
|
drone,
|
|
|
|
|
world,
|
|
|
|
|
SimMode::Playback(inputs.clone(), 0.0),
|
|
|
|
|
Some(result_file),
|
|
|
|
|
config.drone_tick_rate,
|
2025-12-15 00:08:10 +00:00
|
|
|
);
|
|
|
|
|
|
2026-02-05 20:26:30 +00:00
|
|
|
sim.run().unwrap();
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-06 17:11:04 +00:00
|
|
|
async fn run_record(output: String, config_path: &PathBuf) {
|
|
|
|
|
println!(
|
|
|
|
|
"Recording inputs to {}, using config {}",
|
|
|
|
|
output,
|
|
|
|
|
config_path.to_str().unwrap_or("<INVALID CONFIG PATH>")
|
|
|
|
|
);
|
2025-12-14 22:04:04 +00:00
|
|
|
|
2026-02-06 17:11:04 +00:00
|
|
|
let config: SimulationConfig =
|
|
|
|
|
toml::from_str(&fs::read_to_string(config_path).unwrap()).expect("Invalid config file");
|
|
|
|
|
|
|
|
|
|
let mut world = World::new(config.tickrate);
|
2025-12-14 22:04:04 +00:00
|
|
|
|
2026-02-05 20:26:30 +00:00
|
|
|
let drone = drone::Drone::new(
|
|
|
|
|
&mut world,
|
2026-02-06 17:11:04 +00:00
|
|
|
Box::new(drone::stacked::StackedController::new(config.clone())),
|
2026-02-05 20:26:30 +00:00
|
|
|
drone::MotorCharacteristics {
|
2026-02-06 17:11:04 +00:00
|
|
|
max_thrust: config.max_thrust,
|
|
|
|
|
max_torque: config.max_torque,
|
|
|
|
|
time_constant: config.time_constant,
|
2026-02-05 20:26:30 +00:00
|
|
|
..Default::default()
|
|
|
|
|
},
|
2026-02-06 17:11:04 +00:00
|
|
|
config.mass,
|
2026-02-05 20:26:30 +00:00
|
|
|
);
|
2025-12-07 00:41:00 +00:00
|
|
|
|
2026-02-05 20:26:30 +00:00
|
|
|
let mut sim = Simulation::new(
|
|
|
|
|
drone,
|
|
|
|
|
world,
|
|
|
|
|
SimMode::Record(InputRecording::default(), output),
|
|
|
|
|
None,
|
2026-02-06 17:11:04 +00:00
|
|
|
config.drone_tick_rate,
|
2026-02-05 20:26:30 +00:00
|
|
|
);
|
2026-01-06 16:41:14 +00:00
|
|
|
|
2026-02-05 20:26:30 +00:00
|
|
|
sim.run_and_render().await.unwrap();
|
2026-01-06 16:41:14 +00:00
|
|
|
}
|