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

update to navigator-rs version 0.5.0 #80

Open
fnauert opened this issue Dec 2, 2024 · 5 comments
Open

update to navigator-rs version 0.5.0 #80

fnauert opened this issue Dec 2, 2024 · 5 comments

Comments

@fnauert
Copy link

fnauert commented Dec 2, 2024

Hi 🙂
I just wanted to know if there are plans to upgrade this library, so that it uses the new version of the Rust library. I would be interested in that, since I would like to have some features of the new version available in cpp.

@patrickelectric
Copy link
Member

Hi @fnauert, can you be more explicit about which features do you want ? The changes were not that big, just to be sure.

@DRL
Copy link

DRL commented Dec 2, 2024

If we are compiling feature requests, I would be very happy if the Rust errors could be caught somehow in a cleaner way.

This mainly applies to navigator.init() errors due to missing hardware (which happens in our project for complex reasons), and it makes it hard for me to deal with the exceptions.

This is an example:

thread '<unnamed>' panicked at 'Error: Failed to build BMP280 device: I2cError(Io(Os { code: 121, kind: Uncategorized, message: "Remote I/O error" }))', /root/.cargo/registry/src/index.crates.io-6f17d22bba15001f/navigator-rs-0.3.2/src/lib.rs:295:14
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/oceomic/src/bioapnea/bioapnea/apnea.py", line 16, in <module>
    import bioapnea.components as components
  File "/home/oceomic/src/bioapnea/bioapnea/components.py", line 32, in <module>
    navigator.init()
pyo3_runtime.PanicException: Error: Failed to build BMP280 device: I2cError(Io(Os { code: 121, kind: Uncategorized, message: "Remote I/O error" }))

@patrickelectric
Copy link
Member

If we are compiling feature requests, I would be very happy if the Rust errors could be caught somehow in a cleaner way.

This mainly applies to navigator.init() errors due to missing hardware (which happens in our project for complex reasons), and it makes it hard for me to deal with the exceptions.

This is an example:

thread '<unnamed>' panicked at 'Error: Failed to build BMP280 device: I2cError(Io(Os { code: 121, kind: Uncategorized, message: "Remote I/O error" }))', /root/.cargo/registry/src/index.crates.io-6f17d22bba15001f/navigator-rs-0.3.2/src/lib.rs:295:14
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/oceomic/src/bioapnea/bioapnea/apnea.py", line 16, in <module>
    import bioapnea.components as components
  File "/home/oceomic/src/bioapnea/bioapnea/components.py", line 32, in <module>
    navigator.init()
pyo3_runtime.PanicException: Error: Failed to build BMP280 device: I2cError(Io(Os { code: 121, kind: Uncategorized, message: "Remote I/O error" }))

For that, we are working on raspberry pi 5 support that will rework some things and empower the user to create "custom hardware", ignoring some sensors if that's case.

@DRL
Copy link

DRL commented Dec 2, 2024

That's a cool idea.

Re my problem, substituting pyo3_runtime.PanicException for some normal flavour of python exception would be enough ... if this is possible

@fnauert
Copy link
Author

fnauert commented Dec 2, 2024

Hi @fnauert, can you be more explicit about which features do you want ? The changes were not that big, just to be sure.

to reply to your question, I'm mainly interested in the longer delay after gpio pin export, as it was done in this pullrequest. Maybe calling it a feature was a bit misleading 🙂
I tried simply setting the referenced version in the Cargo.toml to 0.5.0 but this results in the errors displayed below, when building the navigator-lib by executing cmake -B build -DCMAKE_BUILD_TYPE=Debug && cmake --build build --config Debug --parallel in the folder navigation-lib/examples/cpp.

Resulting error:

error[E0659]: `bmp280` is ambiguous
  --> /home/auv/.cargo/registry/src/index.crates.io-6f17d22bba15001f/navigator-rs-0.5.0/src/lib.rs:21:5
   |
21 | use bmp280::Bmp280Device;
   |     ^^^^^^ ambiguous name
   |
   = note: ambiguous because of multiple potential import sources
   = note: `bmp280` could refer to a crate passed with `--extern`
   = help: use `::bmp280` to refer to this crate unambiguously
note: `bmp280` could also refer to the module defined here
  --> /home/auv/.cargo/registry/src/index.crates.io-6f17d22bba15001f/navigator-rs-0.5.0/src/lib.rs:9:1
   |
9  | mod bmp280;
   | ^^^^^^^^^^^
   = help: use `crate::bmp280` to refer to this module unambiguously

error[E0659]: `icm20689` is ambiguous
  --> /home/auv/.cargo/registry/src/index.crates.io-6f17d22bba15001f/navigator-rs-0.5.0/src/lib.rs:22:5
   |
22 | use icm20689::Icm20689Device;
   |     ^^^^^^^^ ambiguous name
   |
   = note: ambiguous because of multiple potential import sources
   = note: `icm20689` could refer to a crate passed with `--extern`
   = help: use `::icm20689` to refer to this crate unambiguously
note: `icm20689` could also refer to the module defined here
  --> /home/auv/.cargo/registry/src/index.crates.io-6f17d22bba15001f/navigator-rs-0.5.0/src/lib.rs:10:1
   |
10 | mod icm20689;
   | ^^^^^^^^^^^^^
   = help: use `crate::icm20689` to refer to this module unambiguously

For more information about this error, try `rustc --explain E0659`.
error: could not compile `navigator-rs` (lib) due to 2 previous errors
warning: build failed, waiting for other jobs to finish...
error: failed to run custom build command for `bluerobotics_navigator v0.0.6 (/home/auv/navigator-lib)`

I also tried correcting the ambiguous names in a local copy of navigator-rs, by using crate::bmp280... and crate::icm20689... in line 21 and 22 of lib.rs, which fixed the above mentioned errors. However it led to a whole new set of errors, which I believe are due to an incompatibility between the current implementation of the navigator-lib and the new version of navigator-rs. Below you see the full output when building the navigator-lib with a local navigator-rs.

auv@raspberrypi:~/navigator-lib/examples/cpp$ cmake -B build -DCMAKE_BUILD_TYPE=Debug && cmake --build build --config Debug --parallel
-- Configuring done
-- Generating done
-- Build files have been written to: /home/auv/navigator-lib/examples/cpp/build
[ 20%] C binds generated: /home/auv/navigator-lib/examples/cpp/../../target/debug
   Compiling bluerobotics_navigator v0.0.6 (/home/auv/navigator-lib)
   Compiling navigator-rs v0.5.0 (/home/auv/navigator-rs)
warning: field `info` is never read
  --> /home/auv/navigator-rs/src/ads1115.rs:14:5
   |
12 | pub struct Ads1115Device {
   |            ------------- field in this struct
13 |     adc: Ads1x1x<I2cInterface<I2cdev>, Ads1115, Resolution16Bit, ads1x1x::mode::OneShot>,
14 |     info: PeripheralInfo,
   |     ^^^^
   |
   = note: `#[warn(dead_code)]` on by default

warning: method `get_peripheral_info` is never used
  --> /home/auv/navigator-rs/src/ads1115.rs:22:12
   |
17 | impl Ads1115Device {
   | ------------------ method in this implementation
...
22 |     pub fn get_peripheral_info(&self) -> &PeripheralInfo {
   |            ^^^^^^^^^^^^^^^^^^^

warning: methods `with_i2c_bus`, `with_address`, and `with_peripheral_info` are never used
  --> /home/auv/navigator-rs/src/ads1115.rs:56:12
   |
39 | impl Ads1115DeviceBuilder {
   | ------------------------- methods in this implementation
...
56 |     pub fn with_i2c_bus(mut self, bus: &str) -> Self {
   |            ^^^^^^^^^^^^
...
66 |     pub fn with_address(mut self, address: SlaveAddr) -> Self {
   |            ^^^^^^^^^^^^
...
71 |     pub fn with_peripheral_info(mut self, info: PeripheralInfo) -> Self {
   |            ^^^^^^^^^^^^^^^^^^^^

warning: field `info` is never read
  --> /home/auv/navigator-rs/src/ak09915.rs:12:5
   |
10 | pub struct Ak09915Device {
   |            ------------- field in this struct
11 |     mag: Ak<I2cdev>,
12 |     info: PeripheralInfo,
   |     ^^^^

warning: method `get_peripheral_info` is never used
  --> /home/auv/navigator-rs/src/ak09915.rs:20:12
   |
15 | impl Ak09915Device {
   | ------------------ method in this implementation
...
20 |     pub fn get_peripheral_info(&self) -> &PeripheralInfo {
   |            ^^^^^^^^^^^^^^^^^^^

warning: methods `with_i2c_bus` and `with_peripheral_info` are never used
  --> /home/auv/navigator-rs/src/ak09915.rs:52:12
   |
36 | impl Ak09915Builder {
   | ------------------- methods in this implementation
...
52 |     pub fn with_i2c_bus(mut self, bus: &str) -> Self {
   |            ^^^^^^^^^^^^
...
57 |     pub fn with_peripheral_info(mut self, info: PeripheralInfo) -> Self {
   |            ^^^^^^^^^^^^^^^^^^^^

warning: field `info` is never read
  --> /home/auv/navigator-rs/src/bmp280.rs:11:5
   |
9  | pub struct Bmp280Device {
   |            ------------ field in this struct
10 |     bmp280: Bmp280,
11 |     info: PeripheralInfo,
   |     ^^^^

warning: method `get_peripheral_info` is never used
  --> /home/auv/navigator-rs/src/bmp280.rs:19:12
   |
14 | impl Bmp280Device {
   | ----------------- method in this implementation
...
19 |     pub fn get_peripheral_info(&self) -> &PeripheralInfo {
   |            ^^^^^^^^^^^^^^^^^^^

warning: methods `with_i2c_bus`, `with_address`, and `with_peripheral_info` are never used
  --> /home/auv/navigator-rs/src/bmp280.rs:57:12
   |
40 | impl BarometerBuilder {
   | --------------------- methods in this implementation
...
57 |     pub fn with_i2c_bus(mut self, bus: &str) -> Self {
   |            ^^^^^^^^^^^^
...
67 |     pub fn with_address(mut self, address: u8) -> Self {
   |            ^^^^^^^^^^^^
...
72 |     pub fn with_peripheral_info(mut self, info: PeripheralInfo) -> Self {
   |            ^^^^^^^^^^^^^^^^^^^^

warning: field `info` is never read
  --> /home/auv/navigator-rs/src/icm20689.rs:14:5
   |
12 | pub struct Icm20689Device {
   |            -------------- field in this struct
13 |     imu: ICM20689<SpiInterface<Spidev, Pin>>,
14 |     info: PeripheralInfo,
   |     ^^^^

warning: method `get_peripheral_info` is never used
  --> /home/auv/navigator-rs/src/icm20689.rs:22:12
   |
17 | impl Icm20689Device {
   | ------------------- method in this implementation
...
22 |     pub fn get_peripheral_info(&self) -> &PeripheralInfo {
   |            ^^^^^^^^^^^^^^^^^^^

warning: methods `with_spi_device`, `with_cs_pin`, and `with_peripheral_info` are never used
  --> /home/auv/navigator-rs/src/icm20689.rs:60:12
   |
43 | impl Icm20689Builder {
   | -------------------- methods in this implementation
...
60 |     pub fn with_spi_device(mut self, device: &str) -> Self {
   |            ^^^^^^^^^^^^^^^
...
70 |     pub fn with_cs_pin(mut self, pin_number: u64) -> Self {
   |            ^^^^^^^^^^^
...
75 |     pub fn with_peripheral_info(mut self, info: PeripheralInfo) -> Self {
   |            ^^^^^^^^^^^^^^^^^^^^

warning: field `info` is never read
 --> /home/auv/navigator-rs/src/leak.rs:9:5
  |
7 | pub struct LeakDetector {
  |            ------------ field in this struct
8 |     pin: Pin,
9 |     info: PeripheralInfo,
  |     ^^^^

warning: method `get_peripheral_info` is never used
  --> /home/auv/navigator-rs/src/leak.rs:17:12
   |
12 | impl LeakDetector {
   | ----------------- method in this implementation
...
17 |     pub fn get_peripheral_info(&self) -> &PeripheralInfo {
   |            ^^^^^^^^^^^^^^^^^^^

warning: methods `with_pin` and `with_peripheral_info` are never used
  --> /home/auv/navigator-rs/src/leak.rs:49:12
   |
33 | impl LeakBuilder {
   | ---------------- methods in this implementation
...
49 |     pub fn with_pin(mut self, pin_number: u64) -> Self {
   |            ^^^^^^^^
...
54 |     pub fn with_peripheral_info(mut self, info: PeripheralInfo) -> Self {
   |            ^^^^^^^^^^^^^^^^^^^^

warning: method `get_peripheral_info` is never used
  --> /home/auv/navigator-rs/src/led.rs:17:12
   |
12 | impl LedController {
   | ------------------ method in this implementation
...
17 |     pub fn get_peripheral_info(&self) -> &PeripheralInfo {
   |            ^^^^^^^^^^^^^^^^^^^

warning: method `with_peripheral_info` is never used
  --> /home/auv/navigator-rs/src/led.rs:50:12
   |
33 | impl LedControllerBuilder {
   | ------------------------- method in this implementation
...
50 |     pub fn with_peripheral_info(mut self, info: PeripheralInfo) -> Self {
   |            ^^^^^^^^^^^^^^^^^^^^

warning: field `info` is never read
  --> /home/auv/navigator-rs/src/pca9685.rs:11:5
   |
8  | pub struct Pca9685Device {
   |            ------------- field in this struct
...
11 |     info: PeripheralInfo,
   |     ^^^^

warning: method `get_peripheral_info` is never used
  --> /home/auv/navigator-rs/src/pca9685.rs:19:12
   |
14 | impl Pca9685Device {
   | ------------------ method in this implementation
...
19 |     pub fn get_peripheral_info(&self) -> &PeripheralInfo {
   |            ^^^^^^^^^^^^^^^^^^^

warning: methods `with_i2c_bus`, `with_address`, `with_oe_pin`, and `with_peripheral_info` are never used
  --> /home/auv/navigator-rs/src/pca9685.rs:55:12
   |
37 | impl Pca9685DeviceBuilder {
   | ------------------------- methods in this implementation
...
55 |     pub fn with_i2c_bus(mut self, bus: &str) -> Self {
   |            ^^^^^^^^^^^^
...
65 |     pub fn with_address(mut self, address: u8) -> Self {
   |            ^^^^^^^^^^^^
...
75 |     pub fn with_oe_pin(mut self, pin_number: u64) -> Self {
   |            ^^^^^^^^^^^
...
81 |     pub fn with_peripheral_info(mut self, info: PeripheralInfo) -> Self {
   |            ^^^^^^^^^^^^^^^^^^^^

warning: variant `DigitalOutput` is never constructed
  --> /home/auv/navigator-rs/src/peripherals.rs:18:5
   |
14 | pub enum PeripheralClass {
   |          --------------- variant in this enum
...
18 |     DigitalOutput,
   |     ^^^^^^^^^^^^^

warning: field `info` is never read
  --> /home/auv/navigator-rs/src/rgb.rs:12:5
   |
10 | pub struct RgbController {
   |            ------------- field in this struct
11 |     strip: Strip,
12 |     info: PeripheralInfo,
   |     ^^^^

warning: method `get_peripheral_info` is never used
  --> /home/auv/navigator-rs/src/rgb.rs:21:12
   |
15 | impl RgbController {
   | ------------------ method in this implementation
...
21 |     pub fn get_peripheral_info(&self) -> &PeripheralInfo {
   |            ^^^^^^^^^^^^^^^^^^^

warning: methods `with_bus` and `with_peripheral_info` are never used
  --> /home/auv/navigator-rs/src/rgb.rs:49:12
   |
32 | impl RgbBuilder {
   | --------------- methods in this implementation
...
49 |     pub fn with_bus(mut self, bus: Bus) -> Self {
   |            ^^^^^^^^
...
64 |     pub fn with_peripheral_info(mut self, info: PeripheralInfo) -> Self {
   |            ^^^^^^^^^^^^^^^^^^^^

warning: `navigator-rs` (lib) generated 24 warnings
error[E0412]: cannot find type `PwmChannel` in crate `navigator_rs`
  --> src/lib.rs:84:19
   |
84 |     navigator_rs::PwmChannel,
   |                   ^^^^^^^^^^ help: an enum with a similar name exists: `AdcChannel`
   |
  ::: /home/auv/navigator-rs/src/lib.rs:30:1
   |
30 | pub enum AdcChannel {
   | ------------------- similarly named enum `AdcChannel` defined here

error[E0412]: cannot find type `ADCData` in crate `navigator_rs`
   --> src/lib.rs:115:25
    |
115 | impl From<navigator_rs::ADCData> for ADCData {
    |                         ^^^^^^^ not found in `navigator_rs`

error[E0412]: cannot find type `ADCData` in crate `navigator_rs`
   --> src/lib.rs:116:37
    |
116 |     fn from(read_adc: navigator_rs::ADCData) -> Self {
    |                                     ^^^^^^^ not found in `navigator_rs`

error[E0599]: no method named `build` found for struct `NavigatorBuilder` in the current scope
  --> src/lib.rs:48:22
   |
46 |                   navigator: navigator_rs::Navigator::create()
   |  ____________________________-
47 | |                     .with_rgb_led_strip_size(with_navigator_builder!().rgb_led_strip_size)
48 | |                     .build(),
   | |                     -^^^^^ method not found in `NavigatorBuilder`
   | |_____________________|
   | 

error[E0599]: no method named `init` found for struct `Navigator` in the current scope
   --> src/lib.rs:188:23
    |
188 |     with_navigator!().init();
    |                       ^^^^ method not found in `Navigator`

error[E0599]: no method named `self_test` found for struct `Navigator` in the current scope
   --> src/lib.rs:200:23
    |
200 |     with_navigator!().self_test()
    |                       ^^^^^^^^^ method not found in `Navigator`

error[E0599]: no method named `set_led_all` found for struct `Navigator` in the current scope
   --> src/lib.rs:254:23
    |
254 |     with_navigator!().set_led_all(state)
    |                       ^^^^^^^^^^^ help: there is a method with a similar name: `set_led`

error[E0599]: no method named `set_neopixel_rgbw` found for struct `Navigator` in the current scope
   --> src/lib.rs:286:23
    |
286 |     with_navigator!().set_neopixel_rgbw(array);
    |                       ^^^^^^^^^^^^^^^^^ help: there is a method with a similar name: `set_neopixel`

error[E0277]: the trait bound `ADCData: From<Vec<f32>>` is not satisfied
   --> src/lib.rs:311:38
    |
311 |     with_navigator!().read_adc_all().into()
    |                                      ^^^^ the trait `From<Vec<f32>>` is not implemented for `ADCData`
    |
    = help: the trait `From<[type error]>` is implemented for `ADCData`
    = note: required for `Vec<f32>` to implement `Into<ADCData>`

error[E0599]: no method named `get_pwm_enable` found for struct `Navigator` in the current scope
   --> src/lib.rs:426:23
    |
426 |     with_navigator!().get_pwm_enable()
    |                       ^^^^^^^^^^^^^^ help: there is a method with a similar name: `set_pwm_enable`

error[E0599]: no method named `set_pwm_freq_prescale` found for struct `Navigator` in the current scope
   --> src/lib.rs:454:23
    |
454 |     with_navigator!().set_pwm_freq_prescale(value)
    |                       ^^^^^^^^^^^^^^^^^^^^^ help: there is a method with a similar name: `set_pwm_frequency`

error[E0599]: no method named `set_pwm_freq_hz` found for struct `Navigator` in the current scope
   --> src/lib.rs:474:23
    |
474 |     with_navigator!().set_pwm_freq_hz(freq)
    |                       ^^^^^^^^^^^^^^^ help: there is a method with a similar name: `set_pwm_frequency`

error[E0599]: no method named `set_pwm_channel_value` found for struct `Navigator` in the current scope
   --> src/lib.rs:502:23
    |
502 |     with_navigator!().set_pwm_channel_value(channel.into(), value)
    |                       ^^^^^^^^^^^^^^^^^^^^^ help: there is a method with a similar name: `set_pwm_enable`

error[E0599]: no method named `set_pwm_channel_duty_cycle` found for struct `Navigator` in the current scope
   --> src/lib.rs:524:23
    |
524 |     with_navigator!().set_pwm_channel_duty_cycle(channel.into(), duty_cycle)
    |                       ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: there is a method with a similar name: `set_pwm_duty_cycle`

error[E0599]: no method named `set_pwm_channel_value` found for struct `Navigator` in the current scope
   --> src/lib.rs:535:27
    |
535 |         with_navigator!().set_pwm_channel_value(channel.clone().into(), value);
    |                           ^^^^^^^^^^^^^^^^^^^^^ help: there is a method with a similar name: `set_pwm_enable`

error[E0599]: no method named `set_pwm_channel_duty_cycle` found for struct `Navigator` in the current scope
   --> src/lib.rs:547:27
    |
547 |         with_navigator!().set_pwm_channel_duty_cycle(channel.clone().into(), duty_cycle);
    |                           ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: there is a method with a similar name: `set_pwm_duty_cycle`

error[E0599]: no method named `set_pwm_channel_value` found for struct `Navigator` in the current scope
   --> src/lib.rs:591:27
    |
591 |         with_navigator!().set_pwm_channel_value(array_channels[i].clone().into(), array_values[i]);
    |                           ^^^^^^^^^^^^^^^^^^^^^ help: there is a method with a similar name: `set_pwm_enable`

error[E0599]: no method named `set_pwm_channel_duty_cycle` found for struct `Navigator` in the current scope
   --> src/lib.rs:612:14
    |
611 | /         with_navigator!()
612 | |             .set_pwm_channel_duty_cycle(array_channels[i].clone().into(), array_values[i]);
    | |             -^^^^^^^^^^^^^^^^^^^^^^^^^^ help: there is a method with a similar name: `set_pwm_duty_cycle`
    | |_____________|
    | 

Some errors have detailed explanations: E0277, E0412, E0599.
For more information about an error, try `rustc --explain E0277`.
error: could not compile `bluerobotics_navigator` (lib) due to 18 previous errors
make[2]: *** [CMakeFiles/navigator.dir/build.make:58: CMakeFiles/navigator] Error 101
make[1]: *** [CMakeFiles/Makefile2:133: CMakeFiles/navigator.dir/all] Error 2
make: *** [Makefile:84: all] Error 2

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

No branches or pull requests

3 participants