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

#10 (stage 1) implement complementary filter to fuse acc/gyro #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

tribbloid
Copy link

first draft, external API mimicking AirAPI_Windows

if you think the code convention looks good, I'll gradually add more sensors & algorithm

ESKF may take some time tho

Cargo.toml Outdated

[target.'cfg(not(target_os = "android"))'.dependencies]
hidapi = { version = "2.4.1", optional = true }


[dev-dependencies]
clap = { version = "4.3", features = ["derive"] }
opencv = { version = "0.84.2", default-features = false, features = ["highgui", "imgproc", "calib3d"] }
#opencv = { version = "0.84.2", default-features = false, features = ["highgui", "imgproc", "calib3d"] }
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that opencv should actually be removed and the relevant example moved into a different crate, but don't just leave it commented.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry that was interference between branches, will add back ASAP

Cargo.toml Outdated
#opencv = { version = "0.84.2", default-features = false, features = ["highgui", "imgproc", "calib3d"] }

[lib]
crate-type = ["cdylib", "rlib"]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I said below, C bindings should not be part of this crate.

It could be an optional feature somehow, or you should create a glue crate for your project.

@@ -0,0 +1,4 @@
[toolchain]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a specific reason to have this file? Especially with musl.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm using RustRover/ClionNova, they can't find the installed toolchain automatically

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should find an alternative way to fix your IDE, because this is basically a global override on the project. Most people wouldn't want to build for this target.

@@ -0,0 +1,10 @@
format_code_in_doc_comments = true
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to use rustfmt at factory setting always, so please don't.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will remove

src/lib.rs Outdated
@@ -186,6 +247,17 @@ pub trait ARGlasses: Send {
fn serial(&mut self) -> Result<String>;
/// Get a single sensor event. Blocks.
fn read_event(&mut self) -> Result<GlassesEvent>;
/// read until next valid event. Blocks.
fn next_event(&mut self) -> GlassesEvent {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not really useful on the public interface. Instead this should be folded into the Fusion code.

src/lib.rs Outdated
@@ -266,7 +338,7 @@ pub fn any_glasses() -> Result<Box<dyn ARGlasses>> {
if let Ok(glasses) = mad_gaze::MadGazeGlow::new() {
return Ok(Box::new(glasses));
};
Err(Error::NotFound)
Err(Error::NotFound) // TODO: this may hide some errors in reporting, need to aggregate them as cause
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably, but this should be a github Issue instead.

src/lib.rs Outdated

#[no_mangle]
pub extern "C" fn StopConnection() -> i32 {
0 // TODO: need impl in ARGlasses
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: existing.lock().unwrap() = None would do the trick.

Cargo.lock Outdated
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This stayed in the commit accidentally I think.

@@ -0,0 +1,4 @@
[toolchain]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should find an alternative way to fix your IDE, because this is basically a global override on the project. Most people wouldn't want to build for this target.

pub attitude: UnitQuaternion<f32>,
// just old readings
// prevAcc: (Vector3<f32>, u64),
prev_gyro: (Vector3<f32>, u64),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please split this up into two fields: prev_gyro and prev_gyro_timestamp

@tribbloid tribbloid force-pushed the complementary-filter/dev1 branch 2 times, most recently from 0078968 to 4eee7c8 Compare March 5, 2024 20:52
# to run applications without sudo privileges, connect the glasses,
# make sure that permission to device files are set to 777 (it will be reverted after next login):

sudo chmod 777 /dev/hidraw*
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't be needed if you use the udev rules in the udev directory of this repo.

@@ -0,0 +1,33 @@
// Copyright (C) 2023, Alex Badics
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can write your own name on your own code :)

*/
pub trait Fusion: Send {
fn glasses(&mut self) -> &mut Box<dyn ARGlasses>;
// TODO: only declared mutable as many API of ARGlasses are also mutable
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could have two APIs: glasses and glasses_mut


fn attitude_euler(&self) -> Vector3<f32>;

fn update(&mut self) -> ();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should most probably be Result<()> because it can definitely fail.

src/fusion.rs Outdated
/// read until next valid event. Blocks.
fn next_event(&mut self) -> GlassesEvent {
loop {
match self.glasses.read_event() {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will create a 100% CPU usage infinite loop if the glasses are disconnected.

src/fusion.rs Outdated
gyroscope,
timestamp,
} => {
if gyroscope != Vector3::zeros() {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this check needed?

src/fusion.rs Outdated
pub attitude: UnitQuaternion<f32>,
// just old readings
// prevAcc: (Vector3<f32>, u64),
pub prev_gyro: (Vector3<f32>, u64),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still think this should be split up into two fields.

src/fusion.rs Outdated
}

fn update_gyro(&mut self, gyro: Vector3<f32>, t: u64) -> () {
let d_t1 = ((t - self.prev_gyro.1) as f32) / 1000.0;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1000.0 is incorrect. Timestamps are in microseconds.

src/lib.rs Outdated

fn attitude_quaternion(&self) -> UnitQuaternion<f32>;

fn attitude_euler(&self) -> Vector3<f32>;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this is useful on the public interface. It's basically equivalent to attitude_quaternion.euler_angles()

And then you can just call it attitude

src/lib.rs Outdated
// static i1: OnceLock<Box<u64>> = OnceLock::new();
// static i2: OnceLock<Box<dyn T1>> = OnceLock::new();

pub struct Connection {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This whole Connection thing should go into a separate module (or preferably crate)

add NaiveCF as the default Fusion impl, demonstrated by an example

glasses discovery process has more verbose logging

add rustfmt
@tribbloid tribbloid force-pushed the complementary-filter/dev1 branch from cc26f90 to 5c0199c Compare May 8, 2024 21:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants