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

Get VQF working #206

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
893 changes: 19 additions & 874 deletions Cargo.lock

Large diffs are not rendered by default.

7 changes: 3 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ members = [
"networking/firmware_protocol",
"networking/solarxr",
"networking/tokio_shutdown",
"overlay",
"skeletal_model/rust",
"skeletal_model/napi",
"vqf",
]
exclude = ["da_demo", "nrf_demo", "firmware"]
exclude = ["da_demo", "nrf_demo", "firmware", "overlay",]
default-members = [
"autoupdater",
"networking/firmware_protocol",
Expand All @@ -30,12 +29,12 @@ authors = ["Ryan Butler <[email protected]>"]
repository = "https://github.com/SlimeVR/SlimeVR-Rust"

edition = "2021"
rust-version = "1.65" # GATs and let-else
rust-version = "1.73"


# These may be opted into use by members of the workspace
[workspace.dependencies]
log = "0.4"
eyre = "0.6"
nalgebra = "0.31"
nalgebra = "0.32"
feature_macros = { git = "https://github.com/TheButlah/feature_macros" }
9 changes: 9 additions & 0 deletions firmware/Cargo.lock

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

14 changes: 10 additions & 4 deletions firmware/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ mcu-nrf52832 = [
]

# Wi-fi dependencies
net-wifi = ["esp-wifi?/wifi"] # use wifi
net-wifi = ["esp-wifi?/wifi"] # use wifi
net-ble = ["esp-wifi?/ble"]
net-stubbed = [] # Stubs out network
net-stubbed = [] # Stubs out network

# Supported IMUs
imu-bmi160 = []
Expand All @@ -80,6 +80,7 @@ log-uart = ["defmt_esp_println?/uart"]
# Fusion algorithms for unfused imus
fusion-stubbed = [] # Stubs out fusion so it returns the same pose every time
fusion-dcm = []
fusion-vqf = []

# Enable to flash without needing `espflash`
direct-boot = ["esp32c3-hal?/direct-boot"]
Expand Down Expand Up @@ -171,7 +172,11 @@ esp-wifi = { git = "https://github.com/esp-rs/esp-wifi.git", rev = "76ba312", fe
smoltcp = { version = "0.9", default-features = false, features = [
], optional = true }
embassy-net = { version = "*", optional = true, features = [
"nightly", "tcp", "udp", "dhcpv4", "medium-ethernet"
"nightly",
"tcp",
"udp",
"dhcpv4",
"medium-ethernet",
] }

# Generic BLE
Expand Down Expand Up @@ -205,6 +210,7 @@ bmi160 = "0.1"

# Sensor fusion
dcmimu = "0.2"
vqf = { path = "../vqf" }

# Other crates
static_cell = "1"
Expand Down Expand Up @@ -268,7 +274,7 @@ opt-level = 'z'

[profile.release]
debug = true # Symbols get stripped when flashing anyway
lto = false # LTO doesn't work for esp-wifi
lto = false # LTO doesn't work for esp-wifi


###################
Expand Down
2 changes: 1 addition & 1 deletion firmware/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ fn check_features_compatible() {
mandatory_and_unique!("imu-stubbed", "imu-mpu6050", "imu-bmi160");
mandatory_and_unique!("log-rtt", "log-usb-serial", "log-uart");
mandatory_and_unique!("net-wifi", "net-ble", "net-stubbed");
mandatory_and_unique!("fusion-stubbed", "fusion-dcm");
mandatory_and_unique!("fusion-stubbed", "fusion-dcm", "fusion-vqf");

#[cfg(any(feature = "mcu-nrf52840", feature = "mcu-nrf52832"))]
mandatory_and_unique!(
Expand Down
10 changes: 7 additions & 3 deletions firmware/src/imu/fusion/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
mod dcm;
mod stubbed;
mod vqf;

pub use self::dcm::Dcm;
pub use self::stubbed::Stubbed;
pub use self::vqf::VqfFusion;

use crate::imu::{FusedData, Imu, UnfusedData};

Expand Down Expand Up @@ -36,9 +38,11 @@ impl<I: Imu<Data = UnfusedData>, F: Fuser> Imu for FusedImu<I, F> {
/// Builds a new fuser. The concrete impl is determined by a feature flag.
pub fn new_fuser() -> impl Fuser {
#[cfg(feature = "fusion-stubbed")]
let f = Stubbed::new();
let fusion_algorithm = Stubbed::new();
#[cfg(feature = "fusion-dcm")]
let f = Dcm::new();
let fusion_algorithm = Dcm::new();
#[cfg(feature = "fusion-vqf")]
let fusion_algorithm = VqfFusion::new();

f
fusion_algorithm
}
28 changes: 28 additions & 0 deletions firmware/src/imu/fusion/vqf.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
use vqf::{Vqf, VqfParameters};

use crate::imu::fusion::Fuser;
use crate::imu::{FusedData, UnfusedData};

pub struct VqfFusion {
vqf: Vqf,
}

impl VqfFusion {
#[allow(dead_code)]
pub fn new() -> Self {
let param = VqfParameters::default();
Self {
vqf: Vqf::new(0.01389, 0.01389, 0.01389, param),
}
}
}

impl Fuser for VqfFusion {
fn process(&mut self, unfused: &UnfusedData) -> FusedData {
self.vqf
.update(unfused.gyro.clone(), unfused.accel.clone(), None);

let q = self.vqf.getQuat6D();
FusedData { q }
}
}
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[toolchain]
channel = "1.65" # See workspace Cargo.toml
channel = "1.73" # See workspace Cargo.toml
components = ["rust-src"]
profile = "default"
188 changes: 188 additions & 0 deletions vqf/Cargo.lock

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

8 changes: 7 additions & 1 deletion vqf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ edition = "2021"
license = "MIT"
publish = false

[features]
default = ["single-precision"]
debug-state = []
single-precision = []


[dependencies]
nalgebra = { version = "0.32", default-features = false, features = ["libm"] }
nalgebra = { version = "0.31", default-features = false, features = ["libm"] }
num-traits = { version = "0.2", default-features = false, features = ["libm"] }
Loading
Loading