-
Notifications
You must be signed in to change notification settings - Fork 25
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
base: master
Are you sure you want to change the base?
Conversation
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"] } |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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"] |
There was a problem hiding this comment.
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.
rust-toolchain.toml
Outdated
@@ -0,0 +1,4 @@ | |||
[toolchain] |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
rust-toolchain.toml
Outdated
@@ -0,0 +1,4 @@ | |||
[toolchain] |
There was a problem hiding this comment.
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.
src/connection.rs
Outdated
pub attitude: UnitQuaternion<f32>, | ||
// just old readings | ||
// prevAcc: (Vector3<f32>, u64), | ||
prev_gyro: (Vector3<f32>, u64), |
There was a problem hiding this comment.
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
0078968
to
4eee7c8
Compare
examples/before.sh
Outdated
# 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* |
There was a problem hiding this comment.
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.
examples/connection_sync.rs
Outdated
@@ -0,0 +1,33 @@ | |||
// Copyright (C) 2023, Alex Badics |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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) -> (); |
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
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), |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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>; |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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
cc26f90
to
5c0199c
Compare
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