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

Maintanance + no alloc adjustment. #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
3 changes: 0 additions & 3 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
[build]
target = "aarch64-unknown-linux-gnu"

[alias]
re = "run --example"
rre = "run --release --example"
Expand Down
22 changes: 22 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Rust

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

env:
CARGO_TERM_COLOR: always

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Build
run: cargo build --verbose
- name: Run tests
run: cargo test --verbose
21 changes: 21 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Generated by Cargo
# will have compiled files and executables
debug/
target/

# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
Cargo.lock

# These are backup files generated by rustfmt
**/*.rs.bk

# MSVC Windows builds of rustc generate these, which store debugging information
*.pdb

# RustRover
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"rust-analyzer.cargo.target": "aarch64-unknown-linux-gnu",
"rust-analyzer.cargo.features": ["alloc"],
"editor.bracketPairColorization.enabled": true,
"editor.guides.bracketPairs":"active"
}
17 changes: 11 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,34 @@
authors = ["florian.leon <[email protected]>"]
name = "datafusion_imu"
description = "Performs datafusion for 6 or 9 DOF sensors"
version = "0.1.3"
version = "0.2.0"
edition = "2021"
license = "0BSD"
readme = "README.md"
exclude = ["/.cargo", "/.vscode", "*.code-workspace"]
keywords = ["no-std", "datafusion", "IMU", "Kalman"]
keywords = ["no-std", "datafusion", "IMU", "Kalman", "sensor-fusion"]
categories = ["no-std"]
repository = "https://github.com/SII-Public-Research/Datafusion"

[dependencies]

[dependencies.nalgebra]
version = "0.31.0"
version = "0.33.0"
default-features = false
features = ["libm-force"]

[dependencies.micromath]
version = "2.0.0"

[dev-dependencies.rppal]
version = "0.13.1"
version = "0.18.0"
features = ["hal"]

[dev-dependencies.embedded-hal]
version = "0.2.7"
version = "1.0.0"

[dev-dependencies.adafruit_nxp]
version = "0.1.2"

[features]
default = ["alloc"]
alloc = []
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ use rppal::i2c::I2c;
use embedded_hal::blocking::delay::*;

use adafruit::*;
use datafusion::{self as _, Fusion};
use datafusion::{self as _, filters::Smooth, Fusion};

fn main() -> Result<(), SensorError<rppal::i2c::Error>> {

Expand Down Expand Up @@ -89,7 +89,7 @@ fn main() -> Result<(), SensorError<rppal::i2c::Error>> {
let mag_rz = sensor.mag_sensor.get_scaled_z();

// Create a datafusion object
let mut fusion = Fusion::new(0.05, 20., 50);
let mut fusion = Fusion::new(0.05, 20., Smooth::new(50), Smooth::new(50), Smooth::new(50));
fusion.set_mode(datafusion::Mode::Dof9);

// Set data to the fusion object
Expand Down
21 changes: 9 additions & 12 deletions examples/auto_reset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@ use std::time::Instant;
use rppal::hal::Delay;
use rppal::i2c::I2c;

use embedded_hal::blocking::delay::*;
use embedded_hal::delay::*;

use adafruit_nxp::*;
use datafusion_imu::{self as _, Fusion, Mode};

use datafusion_imu::{self as _, filters::Smooth, Fusion, Mode};

fn main() -> Result<(), SensorError<rppal::i2c::Error>> {

// Init a delay used in certain functions and between each loop.
let mut delay = Delay::new();

Expand Down Expand Up @@ -43,20 +41,20 @@ fn main() -> Result<(), SensorError<rppal::i2c::Error>> {
let gyro_y = sensor.gyro_sensor.get_scaled_y();
let gyro_z = sensor.gyro_sensor.get_scaled_z();

/* Mode DOF9
/* Mode DOF9
let mag_rx = sensor.mag_sensor.get_scaled_x();
let mag_ry = sensor.mag_sensor.get_scaled_y();
let mag_rz = sensor.mag_sensor.get_scaled_z();
*/

// Create a datafusion object
let mut fusion = Fusion::new(0.05, 20., 50);
let mut fusion = Fusion::new(0.05, 20., Smooth::new(50), Smooth::new(50), Smooth::new(50));
fusion.set_mode(Mode::Dof6);

/* DOF9
// Set data to the fusion object DOF9
//fusion.set_data_dof9(acc_x, acc_y, acc_z, gyro_x, gyro_y, gyro_z, mag_rx, mag_ry, mag_rz);
*/
*/

// Set data to the fusion object DOF6
fusion.set_data_dof6(acc_x, acc_y, acc_z, gyro_x, gyro_y, gyro_z);
Expand All @@ -65,11 +63,11 @@ fn main() -> Result<(), SensorError<rppal::i2c::Error>> {
fusion.init();

// Distance auto reset variables
let mut distance= 0.0;
let mut old_distance:f32;
let mut distance = 0.0;
let mut old_distance: f32;
let mut counter_reset_distance = 0;

// Angle auto reset variables --> DOF6 Only
// Angle auto reset variables --> DOF6 Only
let mut angle_z = 0.0;
let mut old_angle_z: f32;
let mut counter_reset_angle_z = 0;
Expand All @@ -78,7 +76,6 @@ fn main() -> Result<(), SensorError<rppal::i2c::Error>> {
let mut time = Instant::now();

loop {

// Calculate delta time in seconds
let dt = time.elapsed().as_micros() as f32 / 1_000_000.;
time = Instant::now();
Expand Down Expand Up @@ -138,6 +135,6 @@ fn main() -> Result<(), SensorError<rppal::i2c::Error>> {
std::println!("Angle Z: {} °", angle_z);
std::println!("Total distance traveled: {} cm", distance);

delay.delay_ms(5_u8);
delay.delay_ms(5_u32);
}
}
20 changes: 11 additions & 9 deletions examples/rasp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ use std::time::Instant;
use rppal::hal::Delay;
use rppal::i2c::I2c;

use embedded_hal::blocking::delay::*;
use embedded_hal::delay::*;

use adafruit_nxp::*;
use datafusion_imu::{self as _, Fusion};
use datafusion_imu::{self as _, filters::Smooth, Fusion};

fn main() -> Result<(), SensorError<rppal::i2c::Error>> {

// Init a delay used in certain functions and between each loop.
let mut delay = Delay::new();

Expand Down Expand Up @@ -47,11 +46,13 @@ fn main() -> Result<(), SensorError<rppal::i2c::Error>> {
let mag_rz = sensor.mag_sensor.get_scaled_z();

// Create a datafusion object
let mut fusion = Fusion::new(0.05, 20., 50);
let mut fusion = Fusion::new(0.05, 20., Smooth::new(50), Smooth::new(50), Smooth::new(50));
fusion.set_mode(datafusion_imu::Mode::Dof9);

// Set data to the fusion object
fusion.set_data_dof9(acc_x, acc_y, acc_z, gyro_x, gyro_y, gyro_z, mag_rx, mag_ry, mag_rz);
fusion.set_data_dof9(
acc_x, acc_y, acc_z, gyro_x, gyro_y, gyro_z, mag_rx, mag_ry, mag_rz,
);

// Initialize the datafusion object
fusion.init();
Expand All @@ -63,7 +64,6 @@ fn main() -> Result<(), SensorError<rppal::i2c::Error>> {
let mut time = Instant::now();

loop {

// Calculate delta time in seconds
let dt = time.elapsed().as_micros() as f32 / 1_000_000.;
time = Instant::now();
Expand All @@ -86,7 +86,9 @@ fn main() -> Result<(), SensorError<rppal::i2c::Error>> {
let mag_rz = sensor.mag_sensor.get_scaled_z();

// Set data to the fusion object
fusion.set_data_dof9(acc_x, acc_y, acc_z, gyro_x, gyro_y, gyro_z, mag_rx, mag_ry, mag_rz);
fusion.set_data_dof9(
acc_x, acc_y, acc_z, gyro_x, gyro_y, gyro_z, mag_rx, mag_ry, mag_rz,
);

// Perform a step of the algorithm
fusion.step(dt);
Expand All @@ -103,6 +105,6 @@ fn main() -> Result<(), SensorError<rppal::i2c::Error>> {
std::println!(" Angle Z: {} °", angle_z);
std::println!("Total distance traveled: {} cm", distance);

delay.delay_ms(5_u8);
delay.delay_ms(5_u32);
}
}
}
Loading