autd3/
lib.rs

1#![cfg_attr(docsrs, feature(doc_cfg))]
2#![warn(missing_docs)]
3#![warn(rustdoc::missing_crate_level_docs)]
4#![warn(rustdoc::unescaped_backticks)]
5
6//! # AUTD3: Airborne Ultrasound Tactile Display 3
7//!
8//! Airborne Ultrasound Tactile Display (AUTD) is a midair haptic device that can remotely produce tactile sensation on a human skin surface without wearing devices.
9//! Please see [our laboratory homepage](https://hapislab.org/en/airborne-ultrasound-tactile-display) for more details on AUTD.
10//! This crate is a client library to drive AUTD version 3 devices. This cross-platform library supports Windows, macOS, and Linux (including Single Board Computer such as Raspberry Pi).
11
12/// [`Controller`] module.
13pub mod controller;
14#[cfg_attr(docsrs, doc(cfg(feature = "gain")))]
15#[cfg(feature = "gain")]
16/// Primitive [`Gain`]s
17///
18/// [`Gain`]: autd3_core::gain::Gain
19pub mod gain;
20#[doc(hidden)]
21pub mod link;
22#[cfg_attr(docsrs, doc(cfg(feature = "modulation")))]
23#[cfg(feature = "modulation")]
24/// Primitive [`Modulation`]s
25///
26/// [`Modulation`]: autd3_core::modulation::Modulation
27pub mod modulation;
28/// Prelude module.
29pub mod prelude;
30#[cfg_attr(docsrs, doc(cfg(feature = "stm")))]
31#[cfg(feature = "stm")]
32/// Utilities for [`GainSTM`] and [`FociSTM`]
33///
34/// [`GainSTM`]: autd3_driver::datagram::GainSTM
35/// [`FociSTM`]: autd3_driver::datagram::FociSTM
36pub mod stm;
37
38pub use autd3_core as core;
39pub use autd3_driver as driver;
40pub use controller::Controller;
41
42#[cfg(test)]
43mod tests {
44    use autd3_core::{devices::AUTD3, geometry::UnitQuaternion};
45    use autd3_driver::geometry::{Geometry, Point3, Vector3};
46
47    #[macro_export]
48    #[doc(hidden)]
49    macro_rules! assert_near_vector3 {
50        ($a:expr, $b:expr) => {
51            let aa = $a;
52            let bb = $b;
53            let x = (aa.x - bb.x).abs() > 1e-3;
54            let y = (aa.y - bb.y).abs() > 1e-3;
55            let z = (aa.z - bb.z).abs() > 1e-3;
56            if x || y || z {
57                panic!(
58                    "assertion failed: `(left ≈ right)`\n  left: `{:?}`,\n right: `{:?}`",
59                    aa, bb
60                );
61            }
62        };
63    }
64
65    #[must_use]
66    pub fn random_vector3(
67        range_x: std::ops::Range<f32>,
68        range_y: std::ops::Range<f32>,
69        range_z: std::ops::Range<f32>,
70    ) -> Vector3 {
71        use rand::Rng;
72        let mut rng = rand::rng();
73        Vector3::new(
74            rng.random_range(range_x),
75            rng.random_range(range_y),
76            rng.random_range(range_z),
77        )
78    }
79
80    #[must_use]
81    pub fn random_point3(
82        range_x: std::ops::Range<f32>,
83        range_y: std::ops::Range<f32>,
84        range_z: std::ops::Range<f32>,
85    ) -> Point3 {
86        use rand::Rng;
87        let mut rng = rand::rng();
88        Point3::new(
89            rng.random_range(range_x),
90            rng.random_range(range_y),
91            rng.random_range(range_z),
92        )
93    }
94
95    #[must_use]
96    pub fn create_geometry(n: usize) -> Geometry {
97        Geometry::new(
98            (0..n)
99                .map(|_| AUTD3::new(Point3::origin(), UnitQuaternion::identity()).into())
100                .collect(),
101        )
102    }
103}