Skip to content

Commit

Permalink
Reduce binary size, enable optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
KoffeinFlummi committed Nov 24, 2023
1 parent d487ff9 commit 14ba460
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 75 deletions.
23 changes: 0 additions & 23 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

62 changes: 21 additions & 41 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ harness = false
harness = false

[dependencies]
static_cell = { version = "1.1", features = ["nightly"]}
static_cell = { version = "1.1", features = ["nightly"] }
num-traits = { version = "0.2.15", default-features = false }
nb = "1"
serde = { version = "1", default-features = false, features = ["derive", "alloc"] }
postcard = "1.0"
crc = "3"
Expand All @@ -28,10 +27,9 @@ siphasher = { version = "0.3", default-features = false }
rand = { version = "0.8", default-features = false }
rand_chacha = { version = "0.3", default-features = false }

# Only load dependencies for embedded for the STM32 target, to avoid loading them when
# importing this crate from the groundstation on x86
# TODO: what about android?
[target.'cfg(target_arch = "arm")'.dependencies]
# Only load dependencies for embedded when we are compiling for the flight computer,
# to avoid loading them when importing this crate from the groundstation on x86/wasm/Android
[target.'cfg(target_os = "none")'.dependencies]
embedded-hal = { version = "=1.0.0-rc.1" }
embedded-hal-async = { version = "=1.0.0-rc.1" }

Expand All @@ -41,17 +39,17 @@ alloc-cortex-m = "0.4"

# TODO: move USB fix to here, create issue
# TODO: pin embassy version
embassy-stm32 = { git = "https://github.com/KoffeinFlummi/embassy", branch="usb_fix", features = ["defmt", "nightly", "unstable-traits", "stm32f401rc", "unstable-pac", "memory-x", "time-driver-any", "exti"] }
embassy-executor = { git = "https://github.com/KoffeinFlummi/embassy", branch="usb_fix", features = ["defmt", "nightly", "arch-cortex-m", "executor-thread", "executor-interrupt", "integrated-timers"] }
embassy-time = { git = "https://github.com/KoffeinFlummi/embassy", branch="usb_fix", features = ["defmt", "defmt-timestamp-uptime", "unstable-traits", "tick-hz-1_000_000"] }
embassy-stm32 = { git = "https://github.com/KoffeinFlummi/embassy", branch="usb_fix", features = ["nightly", "unstable-traits", "stm32f401rc", "unstable-pac", "memory-x", "time-driver-any", "exti"] }
embassy-executor = { git = "https://github.com/KoffeinFlummi/embassy", branch="usb_fix", features = ["nightly", "arch-cortex-m", "executor-thread", "executor-interrupt", "integrated-timers"] }
embassy-time = { git = "https://github.com/KoffeinFlummi/embassy", branch="usb_fix", features = ["unstable-traits", "tick-hz-1_000_000"] }
embassy-embedded-hal = { git = "https://github.com/KoffeinFlummi/embassy", branch="usb_fix" }
embassy-sync = { git = "https://github.com/KoffeinFlummi/embassy", branch="usb_fix", features = ["defmt"] }
embassy-usb = { git = "https://github.com/KoffeinFlummi/embassy", branch="usb_fix", features = ["defmt"] }
embassy-futures = { git = "https://github.com/KoffeinFlummi/embassy", branch="usb_fix", features = ["defmt"] }
embassy-sync = { git = "https://github.com/KoffeinFlummi/embassy", branch="usb_fix", features = [] }
embassy-usb = { git = "https://github.com/KoffeinFlummi/embassy", branch="usb_fix", features = [] }
embassy-futures = { git = "https://github.com/KoffeinFlummi/embassy", branch="usb_fix", features = [] }

defmt = "0.3"
defmt-rtt = "0.4"
panic-probe = { version = "0.3", features = ["print-defmt"] }
panic-probe = { version = "0.3", features = [] }

[dev-dependencies]
defmt-test = "0.3"
Expand All @@ -65,37 +63,19 @@ gcs = []
# cargo build/run
[profile.dev]
codegen-units = 1
debug = 2
debug-assertions = true # <-
debug = "full"
debug-assertions = false
incremental = false
opt-level = 'z' # <-
overflow-checks = true # <-

# cargo test
[profile.test]
codegen-units = 1
debug = 2
debug-assertions = true # <-
incremental = false
opt-level = 'z' # <-
overflow-checks = true # <-
lto = "fat"
opt-level = 3
overflow-checks = false

# cargo build/run --release
[profile.release]
codegen-units = 1
debug = 2
debug-assertions = false # <-
incremental = false
lto = 'fat'
opt-level = 'z' # <-
overflow-checks = false # <-

# cargo test --release
[profile.bench]
codegen-units = 1
debug = 2
debug-assertions = false # <-
debug = "full"
debug-assertions = false
incremental = false
lto = 'fat'
opt-level = 'z' # <-
overflow-checks = false # <-
lto = "fat"
opt-level = 3
overflow-checks = false
4 changes: 2 additions & 2 deletions src/drivers/sensors/imu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,11 @@ impl<SPI: SpiDevice<u8>> LSM6<SPI> {
self.write_u8(LSM6RRegister::Ctrl2G, reg).await
}

pub async fn tick(&mut self) where <SPI as embedded_hal::spi::ErrorType>::Error: defmt::Format {
pub async fn tick(&mut self) {
if let Err(e) = self.read_sensor_data().await {
self.gyro = None;
self.accel = None;
error!("{:?}", e);
error!("{:?}", Debug2Format(&e));
}
}

Expand Down
17 changes: 8 additions & 9 deletions src/state_estimation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use core::num::Wrapping;
use std::num::Wrapping;

use nalgebra::*;
use num_traits::Pow;
use ahrs::Ahrs;
use filter::kalman::kalman_filter::KalmanFilter;

Expand Down Expand Up @@ -61,19 +60,19 @@ impl StateEstimator {
0.0, 0.0, 1.0
);
kalman.P = Matrix3::new(
settings.std_dev_barometer.pow(2), 0.0, 0.0,
settings.std_dev_barometer.powi(2), 0.0, 0.0,
0.0, 1.0, 0.0,
0.0, 0.0, settings.std_dev_accelerometer.pow(2),
0.0, 0.0, settings.std_dev_accelerometer.powi(2),
);
kalman.Q = Matrix3::new(
0.25f32 * dt.pow(4), 0.5f32 * dt.pow(3), 0.5f32 * dt.pow(2),
0.5f32 * dt.pow(3), dt.pow(2), dt,
0.5f32 * dt.pow(2), dt, 1.0f32,
) * settings.std_dev_process.pow(2);
0.25f32 * dt.powi(4), 0.5f32 * dt.powi(3), 0.5f32 * dt.powi(2),
0.5f32 * dt.powi(3), dt.powi(2), dt,
0.5f32 * dt.powi(2), dt, 1.0f32,
) * settings.std_dev_process.powi(2);

kalman.R *= Matrix2::new(
settings.std_dev_barometer.pow(2), 0.0,
0.0, settings.std_dev_accelerometer.pow(2)
settings.std_dev_barometer.powi(2), 0.0,
0.0, settings.std_dev_accelerometer.powi(2)
);

Self {
Expand Down

0 comments on commit 14ba460

Please sign in to comment.