Skip to content

Commit c2d4a0e

Browse files
TheButlahNoxime
andauthored
Add DCM fusion (#173)
A DCM Based Attitude Estimation Algorithm for Low-Cost MEMS IMUs Heikki Hyyti & Arto Visala, 2015 Co-authored-by: Aaro Perämaa <[email protected]>
1 parent 1819afa commit c2d4a0e

File tree

4 files changed

+62
-3
lines changed

4 files changed

+62
-3
lines changed

firmware/Cargo.lock

Lines changed: 18 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

firmware/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,9 @@ defmt-bbq = { version = "0.1", optional = true }
194194
mpu6050-dmp = "0.3"
195195
bmi160 = "0.1"
196196

197+
# Sensor fusion
198+
dcmimu = "0.2"
199+
197200
# Other crates
198201
static_cell = "1"
199202
nb = "1"

firmware/src/imu/fusion/dcm.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
use dcmimu::DCMIMU;
2+
use embassy_time::Instant;
3+
use firmware_protocol::ImuType;
4+
5+
use crate::imu::{FusedData, Fuser, Imu, Quat, UnfusedData};
6+
7+
/// Extended Kalman filtering in direction cosine matrix formation
8+
pub struct Dcm {
9+
dcm: DCMIMU,
10+
last: Instant,
11+
}
12+
13+
impl Dcm {
14+
pub fn new() -> Self {
15+
Self {
16+
dcm: DCMIMU::new(),
17+
last: Instant::now(),
18+
}
19+
}
20+
}
21+
22+
impl Fuser for Dcm {
23+
fn process(&mut self, unfused: &UnfusedData) -> FusedData {
24+
let last = self.last;
25+
self.last = Instant::now();
26+
let elapsed = self.last - last;
27+
28+
let UnfusedData { accel, gyro } = unfused;
29+
30+
// TODO: Check that these euler angle convention matches
31+
let (euler, _) = self.dcm.update(
32+
(gyro.x, gyro.y, gyro.z),
33+
(accel.x, accel.y, accel.z),
34+
elapsed.as_micros() as f32 / 1_000_000.0,
35+
);
36+
37+
let q = Quat::from_euler_angles(euler.roll, euler.pitch, euler.roll);
38+
FusedData { q }
39+
}
40+
}

firmware/src/imu/fusion/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
//! TODO: Add fusion
1+
pub mod dcm;

0 commit comments

Comments
 (0)