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 = "datagram")))]
13#[cfg(feature = "datagram")]
14/// Core traits for Datagram.
15pub mod datagram;
16#[cfg_attr(docsrs, doc(cfg(feature = "defined")))]
17#[cfg(feature = "defined")]
18/// Common constants and types.
19pub mod defined;
20#[cfg_attr(docsrs, doc(cfg(feature = "ethercat")))]
21#[cfg(feature = "ethercat")]
22/// Definitions for EtherCAT.
23pub mod ethercat;
24#[cfg_attr(docsrs, doc(cfg(feature = "gain")))]
25#[cfg(feature = "gain")]
26/// Core traits for Gain.
27pub mod gain;
28#[cfg_attr(docsrs, doc(cfg(feature = "geometry")))]
29#[cfg(feature = "geometry")]
30/// Geometry related modules.
31pub mod geometry;
32#[cfg_attr(docsrs, doc(cfg(feature = "link")))]
33#[cfg(feature = "link")]
34/// A interface to the device.
35pub mod link;
36#[cfg_attr(docsrs, doc(cfg(feature = "modulation")))]
37#[cfg(feature = "modulation")]
38/// Core traits for Modulation.
39pub mod modulation;
40#[cfg_attr(docsrs, doc(cfg(feature = "sampling_config")))]
41#[cfg(feature = "sampling_config")]
42#[doc(hidden)]
43pub mod sampling_config;
44#[cfg_attr(docsrs, doc(cfg(feature = "utils")))]
45#[cfg(feature = "utils")]
46#[doc(hidden)]
47pub mod utils;
48
49#[cfg_attr(docsrs, doc(cfg(feature = "async-trait")))]
50#[cfg(feature = "async-trait")]
51pub use async_trait::async_trait;
52
53/// Utilities for user-defined [`Gain`] and [`Modulation`].
54///
55/// # Example
56///
57/// The following example shows how to define a custom [`Gain`] that generates a single focal point.
58///
59/// ```
60/// use autd3_core::derive::*;
61/// use autd3_core::geometry::Point3;
62/// use autd3_core::defined::rad;
63///
64/// #[derive(Gain, Debug)]
65/// pub struct FocalPoint {
66/// pos: Point3,
67/// }
68///
69/// pub struct Impl {
70/// pos: Point3,
71/// wavenumber: f32,
72/// }
73///
74/// impl GainCalculator for Impl {
75/// fn calc(&self, tr: &Transducer) -> Drive {
76/// Drive {
77/// phase: Phase::from(-(self.pos - tr.position()).norm() * self.wavenumber * rad),
78/// intensity: EmitIntensity::MAX,
79/// }
80/// }
81/// }
82///
83/// impl GainCalculatorGenerator for FocalPoint {
84/// type Calculator = Impl;
85///
86/// fn generate(&mut self, device: &Device) -> Self::Calculator {
87/// Impl {
88/// pos: self.pos,
89/// wavenumber: device.wavenumber(),
90/// }
91/// }
92/// }
93///
94/// impl Gain for FocalPoint {
95/// type G = FocalPoint;
96///
97/// fn init(self) -> Result<Self::G, GainError> {
98/// Ok(self)
99/// }
100/// }
101/// ```
102///
103/// The following example shows how to define a modulation that outputs the maximum value only for a moment.
104///
105/// ```
106/// use autd3_core::defined::kHz;
107/// use autd3_core::derive::*;
108///
109/// #[derive(Modulation, Debug)]
110/// pub struct Burst {
111/// }
112///
113/// impl Burst {
114/// pub fn new() -> Self {
115/// Self {}
116/// }
117/// }
118///
119/// impl Modulation for Burst {
120/// fn calc(self) -> Result<Vec<u8>, ModulationError> {
121/// Ok((0..4000)
122/// .map(|i| if i == 3999 { u8::MAX } else { u8::MIN })
123/// .collect())
124/// }
125///
126/// fn sampling_config(&self) -> SamplingConfig {
127/// SamplingConfig::new(4. * kHz)
128/// }
129/// }
130/// ```
131///
132/// [`Gain`]: crate::gain::Gain
133/// [`Modulation`]: crate::modulation::Modulation
134#[cfg_attr(docsrs, doc(cfg(feature = "derive")))]
135#[cfg(feature = "derive")]
136pub mod derive {
137 #[cfg(any(feature = "gain", feature = "modulation"))]
138 mod common {
139 pub use crate::{
140 datagram::{DatagramOption, Segment, TransitionMode},
141 geometry::Geometry,
142 };
143 pub use tracing;
144 }
145 #[cfg(any(feature = "gain", feature = "modulation"))]
146 pub use common::*;
147
148 #[cfg(feature = "gain")]
149 mod gain {
150 pub use crate::{
151 datagram::DatagramS,
152 gain::{
153 BitVec, Drive, EmitIntensity, Gain, GainCalculator, GainCalculatorGenerator,
154 GainError, GainOperationGenerator, Phase,
155 },
156 geometry::{Device, Transducer},
157 };
158 pub use autd3_derive::Gain;
159 }
160 #[cfg(feature = "gain")]
161 pub use gain::*;
162
163 #[cfg(feature = "modulation")]
164 mod modulation {
165 pub use crate::datagram::{DatagramL, LoopBehavior};
166 pub use crate::modulation::{Modulation, ModulationError, ModulationOperationGenerator};
167 pub use crate::sampling_config::{SamplingConfig, SamplingConfigError};
168 pub use autd3_derive::Modulation;
169 pub use std::{collections::HashMap, sync::Arc};
170 }
171 #[cfg(feature = "modulation")]
172 pub use modulation::*;
173}