autd3_core/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//! Core traits and types for AUTD3.
7
8#[cfg_attr(docsrs, doc(cfg(feature = "acoustics")))]
9#[cfg(feature = "acoustics")]
10/// Utilities for acoustics.
11pub mod acoustics;
12#[cfg_attr(docsrs, doc(cfg(feature = "common")))]
13#[cfg(feature = "common")]
14/// Common constants and types.
15pub mod common;
16#[cfg_attr(docsrs, doc(cfg(feature = "datagram")))]
17#[cfg(feature = "datagram")]
18/// Core traits for [`Datagram`].
19///
20/// [`Datagram`]: crate::datagram::Datagram
21pub mod datagram;
22#[cfg_attr(docsrs, doc(cfg(feature = "devices")))]
23#[cfg(feature = "devices")]
24/// Definitions for devices.
25pub mod devices;
26#[cfg_attr(docsrs, doc(cfg(feature = "environment")))]
27#[cfg(feature = "environment")]
28#[doc(hidden)]
29pub mod environment;
30#[cfg_attr(docsrs, doc(cfg(feature = "ethercat")))]
31#[cfg(feature = "ethercat")]
32/// Definitions for EtherCAT.
33pub mod ethercat;
34#[cfg_attr(docsrs, doc(cfg(feature = "firmware")))]
35#[cfg(feature = "firmware")]
36/// Firmware related modules.
37pub mod firmware;
38#[cfg_attr(docsrs, doc(cfg(feature = "gain")))]
39#[cfg(feature = "gain")]
40/// Core traits for [`Gain`].
41///
42/// [`Gain`]: crate::gain::Gain
43pub mod gain;
44#[cfg_attr(docsrs, doc(cfg(feature = "geometry")))]
45#[cfg(feature = "geometry")]
46/// Geometry related modules.
47pub mod geometry;
48#[cfg_attr(docsrs, doc(cfg(feature = "link")))]
49#[cfg(feature = "link")]
50/// A interface to the device.
51pub mod link;
52#[cfg_attr(docsrs, doc(cfg(feature = "modulation")))]
53#[cfg(feature = "modulation")]
54/// Core traits for [`Modulation`].
55///
56/// [`Modulation`]: crate::modulation::Modulation
57pub mod modulation;
58#[cfg_attr(docsrs, doc(cfg(feature = "sleep")))]
59#[cfg(feature = "sleep")]
60#[doc(hidden)]
61pub mod sleep;
62#[cfg_attr(docsrs, doc(cfg(feature = "utils")))]
63#[cfg(feature = "utils")]
64#[doc(hidden)]
65pub mod utils;
66
67/// Utilities for user-defined [`Gain`] and [`Modulation`].
68///
69/// # Example
70///
71/// The following example shows how to define a custom [`Gain`] that generates a single focal point.
72///
73/// ```
74/// use autd3_core::derive::*;
75/// use autd3_core::geometry::Point3;
76/// use autd3_core::common::rad;
77///
78/// #[derive(Gain, Debug)]
79/// pub struct FocalPoint {
80/// pos: Point3,
81/// }
82///
83/// #[derive(Clone, Copy)]
84/// pub struct Impl {
85/// pos: Point3,
86/// wavenumber: f32,
87/// }
88///
89/// impl<'a> GainCalculator<'a> for Impl {
90/// fn calc(&self, tr: &'a Transducer) -> Drive {
91/// Drive {
92/// phase: Phase::from(-(self.pos - tr.position()).norm() * self.wavenumber * rad),
93/// intensity: Intensity::MAX,
94/// }
95/// }
96/// }
97///
98/// impl<'a> GainCalculatorGenerator<'a> for Impl {
99/// type Calculator = Self;
100///
101/// fn generate(&mut self, _: &'a Device) -> Self::Calculator {
102/// *self
103/// }
104/// }
105///
106/// impl<'a> Gain<'a> for FocalPoint {
107/// type G = Impl;
108///
109/// fn init(
110/// self,
111/// _geometry: &'a Geometry,
112/// env: &Environment,
113/// _filter: &TransducerMask ,
114/// ) -> Result<Self::G, GainError> {
115/// Ok(Impl {
116/// pos: self.pos,
117/// wavenumber: env.wavenumber(),
118/// })
119/// }
120/// }
121/// ```
122///
123/// The following example shows how to define a modulation that outputs the maximum value only for a moment.
124///
125/// ```
126/// use autd3_core::common::kHz;
127/// use autd3_core::derive::*;
128///
129/// #[derive(Modulation, Debug)]
130/// pub struct Burst {
131/// }
132///
133/// impl Burst {
134/// pub fn new() -> Self {
135/// Self {}
136/// }
137/// }
138///
139/// impl Modulation for Burst {
140/// fn calc(self) -> Result<Vec<u8>, ModulationError> {
141/// Ok(core::iter::repeat(u8::MIN)
142/// .take(3999)
143/// .chain(core::iter::once(u8::MAX))
144/// .collect())
145/// }
146///
147/// fn sampling_config(&self) -> SamplingConfig {
148/// SamplingConfig::new(4. * kHz)
149/// }
150/// }
151/// ```
152///
153/// [`Gain`]: crate::gain::Gain
154/// [`Modulation`]: crate::modulation::Modulation
155#[cfg_attr(docsrs, doc(cfg(feature = "derive")))]
156#[cfg(feature = "derive")]
157pub mod derive {
158 #[cfg(any(feature = "gain", feature = "modulation"))]
159 mod common {
160 pub use crate::{
161 datagram::{DatagramOption, DeviceMask, Inspectable, InspectionResult, internal},
162 environment::Environment,
163 firmware::{Segment, transition_mode},
164 geometry::Geometry,
165 };
166 }
167 #[cfg(any(feature = "gain", feature = "modulation"))]
168 pub use common::*;
169
170 #[cfg(feature = "gain")]
171 mod gain {
172 pub use crate::{
173 datagram::DatagramS,
174 firmware::{Drive, Intensity, Phase},
175 gain::{
176 DeviceTransducerMask, Gain, GainCalculator, GainCalculatorGenerator, GainError,
177 GainInspectionResult, GainOperationGenerator, TransducerMask,
178 },
179 geometry::{Device, Transducer},
180 };
181 pub use autd3_derive::Gain;
182 }
183 #[cfg(feature = "gain")]
184 pub use gain::*;
185
186 #[cfg(feature = "modulation")]
187 mod modulation {
188 pub use crate::datagram::{Datagram, DatagramL};
189 pub use crate::firmware::{SamplingConfig, SamplingConfigError};
190 pub use crate::modulation::{
191 Modulation, ModulationError, ModulationInspectionResult, ModulationOperationGenerator,
192 };
193 pub use autd3_derive::Modulation;
194 }
195 #[cfg(feature = "modulation")]
196 pub use modulation::*;
197}