Skip to content

Commit

Permalink
add autd3-core crate (#192)
Browse files Browse the repository at this point in the history
* rm num-integer

* add `autd3-core` crate

* update autd3-core

* update autd3-link-twincat

* update autd3-core

* update autd3-driver

* update autd3-derive

* update autd3-firmware-emulator

* update autd3-gain-holo

* update autd3-link-simulator

* update autd3-protobuf

* update autd3-modulation-audio-file

* update autd3

* update examples

* update github workflows

* update deps

* excl infallible error test from cov

* update doc

* update autd3-core doc

* fix autd3-gain-holo deps
  • Loading branch information
s5suzuki authored Jan 15, 2025
1 parent e7a4f43 commit ebd4330
Show file tree
Hide file tree
Showing 252 changed files with 2,298 additions and 1,830 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ jobs:
- uses: dtolnay/install@cargo-docs-rs
- run: |
cargo +nightly docs-rs -pautd3
cargo +nightly docs-rs -pautd3-core
cargo +nightly docs-rs -pautd3-derive
cargo +nightly docs-rs -pautd3-driver
cargo +nightly docs-rs -pautd3-firmware-emulator
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ jobs:
- uses: dtolnay/install@cargo-docs-rs
- run: |
cargo +nightly docs-rs -pautd3
cargo +nightly docs-rs -pautd3-core
cargo +nightly docs-rs -pautd3-derive
cargo +nightly docs-rs -pautd3-driver
cargo +nightly docs-rs -pautd3-firmware-emulator
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ jobs:
with:
feature-group: default-features
- run: |
cd autd3-core
cargo publish --no-verify --token ${{ secrets.CRATEIO_TOKEN }}
cd .. && sleep 15
cd autd3-driver
cargo publish --no-verify --token ${{ secrets.CRATEIO_TOKEN }}
cd .. && sleep 15
Expand Down
66 changes: 34 additions & 32 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

members = [
"autd3",
"autd3-core",
"autd3-driver",
"autd3-derive",
"autd3-gain-holo",
Expand All @@ -11,6 +12,7 @@ members = [
"autd3-firmware-emulator",
"autd3-protobuf",
"examples",
"autd3-core",
]
resolver = "2"

Expand All @@ -23,57 +25,57 @@ repository = "https://github.com/shinolab/autd3-rs"
keywords = ["autd"]

[workspace.dependencies]
zerocopy = { version = "0.8.14", default-features = false }
anyhow = { version = "1.0.95", default-features = false }
async-trait = "0.1.85"
bitfield-struct = "0.10.0"
bitflags = "2.7.0"
async-trait = { version = "0.1.85", default-features = false }
bitfield-struct = { version = "0.10.0", default-features = false }
bitflags = { version = "2.7.0", default-features = false }
bit-vec = { version = "0.8.0", default-features = false }
bvh = { version = "0.10.0", default-features = false }
cc = "1.2.7"
color-print = "0.3.7"
cc = { version = "1.2.9", default-features = false }
color-print = { version = "0.3.7", default-features = false }
criterion = { version = "0.5.1", default-features = false }
derive-new = { version = "0.7.0", default-features = false }
glob = "0.3.2"
hound = "3.5.1"
itertools = { version = "0.14.0", features = ["use_alloc"], default-features = false }
libloading = "0.8.6"
glob = { version = "0.3.2", default-features = false }
hound = { version = "3.5.1", default-features = false }
itertools = { version = "0.14.0", default-features = false }
libloading = { version = "0.8.6", default-features = false }
nalgebra = { version = "0.33.2", default-features = false }
num = { version = "0.4.3", default-features = false }
num-integer = { version = "0.1.46", default-features = false }
paste = "1.0.15"
proc-macro2 = { version = "1.0.89", default-features = false }
prost = { version = "0.13.4", features = ["derive"], default-features = false }
paste = { version = "1.0.15", default-features = false }
proc-macro2 = { version = "1.0.93", default-features = false }
prost = { version = "0.13.4", default-features = false }
quote = { version = "1.0.38", default-features = false }
rand = { version = "0.8.5", default-features = false }
rstest = { version = "0.24.0", default-features = false }
serde = { version = "1.0.217", default-features = false }
serde_json = "1.0.135"
serde_json = { version = "1.0.135", default-features = false }
syn = { version = "2.0.96", default-features = false }
tempfile = "3.15.0"
tempfile = { version = "3.15.0", default-features = false }
thiserror = { version = "2.0.10", default-features = false }
time = { version = "0.3.37", default-features = false }
tokio = "1.43.0"
tokio-test = "0.4.4"
tokio = { version = "1.43.0", default-features = false }
tokio-test = { version = "0.4.4", default-features = false }
tonic = { version = "0.12.3", default-features = false }
tonic-build = { version = "0.12.3", default-features = false }
rayon = "1.10.0"
rayon = { version = "1.10.0", default-features = false }
derive_more = { version = "1.0.0", default-features = false }
tracing-subscriber = { version = "0.3.19", features = ["fmt"], default-features = false }
tracing-subscriber = { version = "0.3.19", default-features = false }
tracing = { version = "0.1.41", default-features = false }
regex = "1.11.1"
tynm = "0.1.10"
regex = { version = "1.11.1", default-features = false }
tynm = { version = "0.1.10", default-features = false }
approx = { version = "0.5.1", default-features = false }
csv = "1.3.1"
seq-macro = "0.3.5"
spin_sleep = "1.3.0"
csv = { version = "1.3.1", default-features = false }
seq-macro = { version = "0.3.5", default-features = false }
spin_sleep = { version = "1.3.0", default-features = false }
windows = { version = "0.59.0", default-features = false }
zerocopy = { version = "0.8.14", features = ["derive"] }
autd3 = { path = "./autd3", version = "29.0.0-rc.14" }
autd3 = { path = "./autd3", version = "29.0.0-rc.14", default-features = false }
autd3-core = { path = "./autd3-core", version = "29.0.0-rc.14", default-features = false }
autd3-driver = { path = "./autd3-driver", version = "29.0.0-rc.14", default-features = false }
autd3-derive = { path = "./autd3-derive", version = "29.0.0-rc.14" }
autd3-gain-holo = { path = "./autd3-gain-holo", version = "29.0.0-rc.14" }
autd3-link-simulator = { path = "./autd3-link-simulator", version = "29.0.0-rc.14" }
autd3-derive = { path = "./autd3-derive", version = "29.0.0-rc.14", default-features = false }
autd3-gain-holo = { path = "./autd3-gain-holo", version = "29.0.0-rc.14", default-features = false }
autd3-link-simulator = { path = "./autd3-link-simulator", version = "29.0.0-rc.14", default-features = false }
autd3-link-twincat = { path = "./autd3-link-twincat", version = "29.0.0-rc.14", default-features = false }
autd3-modulation-audio-file = { path = "./autd3-modulation-audio-file", version = "29.0.0-rc.14" }
autd3-firmware-emulator = { path = "./autd3-firmware-emulator", version = "29.0.0-rc.14" }
autd3-protobuf = { path = "./autd3-protobuf", version = "29.0.0-rc.14" }
autd3-modulation-audio-file = { path = "./autd3-modulation-audio-file", version = "29.0.0-rc.14", default-features = false }
autd3-firmware-emulator = { path = "./autd3-firmware-emulator", version = "29.0.0-rc.14", default-features = false }
autd3-protobuf = { path = "./autd3-protobuf", version = "29.0.0-rc.14", default-features = false }
66 changes: 66 additions & 0 deletions autd3-core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
[package]
name = "autd3-core"
description = "AUTD3 core traits and types"
readme = "README.md"
keywords = { workspace = true }
version = { workspace = true }
authors = { workspace = true }
edition = { workspace = true }
license = { workspace = true }
repository = { workspace = true }

[dependencies]
async-trait = { workspace = true, default-features = false, optional = true }
autd3-derive = { workspace = true, default-features = false, optional = true }
bit-vec = { workspace = true, default-features = false, optional = true }
bvh = { workspace = true, default-features = false, optional = true }
derive_more = { workspace = true, default-features = false, optional = true }
derive-new = { workspace = true, default-features = false, optional = true }
nalgebra = { workspace = true, default-features = false, optional = true }
paste = { workspace = true, default-features = false, optional = true }
time = { workspace = true, default-features = false, features = ["macros", "std"], optional = true }
thiserror = { workspace = true, default-features = false, optional = true }
tracing = { workspace = true, default-features = false, optional = true }
zerocopy = { workspace = true, default-features = false, features = ["derive"], optional = true }

[dev-dependencies]
anyhow = { workspace = true }
approx = { workspace = true }
itertools = { workspace = true }
rand = { workspace = true }
rstest = { workspace = true }

[features]
acoustics = ["defined", "geometry"]
async = []
async-trait = ["async", "dep:async-trait"]
datagram = ["defined", "geometry", "ethercat"]
defined = ["derive_more", "derive_more/add", "derive_more/mul", "derive_more/debug"]
derive = ["datagram", "autd3-derive", "tracing"]
dynamic_freq = []
ethercat = ["time", "thiserror"]
gain = ["defined", "datagram", "geometry", "thiserror", "bit-vec", "zerocopy", "derive_more", "derive_more/display"]
geometry = [
"nalgebra",
"bvh",
"paste",
"autd3-derive",
"defined",
"derive-new",
"derive_more",
"derive_more/add",
"derive_more/mul",
"derive_more/into_iterator",
"derive_more/deref",
"derive_more/debug",
]
left_handed = []
link = ["zerocopy", "autd3-derive", "ethercat", "geometry", "derive_more", "derive_more/display"]
modulation = ["autd3-derive", "utils", "defined", "datagram", "derive_more", "derive_more/display"]
resampler = ["modulation", "defined", "tracing", "utils"]
use_meter = []
utils = []

[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "docsrs"]
7 changes: 7 additions & 0 deletions autd3-core/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# autd3-core

AUTD3 core traits and types.

# Author

Shun Suzuki, 2025
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
/// directivity module
pub mod directivity;

use std::f32::consts::PI;

use crate::{
defined::{Complex, PI, T4010A1_AMPLITUDE},
geometry::{Point3, Transducer, UnitVector3},
defined::T4010A1_AMPLITUDE,
geometry::{Complex, Point3, Transducer, UnitVector3},
};

use directivity::Directivity;
Expand Down
File renamed without changes.
83 changes: 83 additions & 0 deletions autd3-core/src/datagram/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
mod gpio;
mod operation;
mod segment;
mod transition_mode;
mod tuple;

pub use gpio::{GPIOIn, GPIOOut};
pub use operation::{NullOp, Operation};
pub use segment::Segment;
pub use transition_mode::{TransitionMode, TRANSITION_MODE_NONE};
pub use tuple::{CombinedError, CombinedOperationGenerator};

use std::time::Duration;

use crate::{defined::DEFAULT_TIMEOUT, geometry::Geometry};

/// [`Datagram`] represents the data sent to the device.
pub trait Datagram: std::fmt::Debug {
#[doc(hidden)]
type G;
#[doc(hidden)]
type Error: std::error::Error;

#[doc(hidden)]
fn operation_generator(self, geometry: &Geometry) -> Result<Self::G, Self::Error>;

/// Returns the timeout duration.
fn timeout(&self) -> Option<Duration> {
Some(DEFAULT_TIMEOUT)
}

/// Returns the parallel threshold.
fn parallel_threshold(&self) -> Option<usize> {
Some(usize::MAX)
}
}

/// [`DatagramS`] represents a [`Datagram`] that can specify [`Segment`] to write the data.
pub trait DatagramS: std::fmt::Debug {
#[doc(hidden)]
type G;
#[doc(hidden)]
type Error: std::error::Error;

#[doc(hidden)]
fn operation_generator_with_segment(
self,
geometry: &Geometry,
segment: Segment,
transition_mode: Option<TransitionMode>,
) -> Result<Self::G, Self::Error>;

/// Returns the timeout duration.
fn timeout(&self) -> Option<Duration> {
Some(DEFAULT_TIMEOUT)
}

/// Returns the parallel threshold.
fn parallel_threshold(&self) -> Option<usize> {
Some(usize::MAX)
}
}

impl<D: DatagramS> Datagram for D {
type G = D::G;
type Error = D::Error;

fn operation_generator(self, geometry: &Geometry) -> Result<Self::G, D::Error> {
self.operation_generator_with_segment(
geometry,
Segment::S0,
Some(TransitionMode::Immediate),
)
}

fn timeout(&self) -> Option<Duration> {
<Self as DatagramS>::timeout(self)
}

fn parallel_threshold(&self) -> Option<usize> {
<Self as DatagramS>::parallel_threshold(self)
}
}
35 changes: 35 additions & 0 deletions autd3-core/src/datagram/operation.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
use crate::geometry::Device;

#[doc(hidden)]
pub trait Operation: Send + Sync {
type Error: std::error::Error;

fn required_size(&self, device: &Device) -> usize;
fn pack(&mut self, device: &Device, tx: &mut [u8]) -> Result<usize, Self::Error>;
fn is_done(&self) -> bool;
}

#[doc(hidden)]
pub struct NullOp;

impl Operation for NullOp {
type Error = std::convert::Infallible;

fn required_size(&self, _: &Device) -> usize {
0
}

fn pack(&mut self, _: &Device, _: &mut [u8]) -> Result<usize, Self::Error> {
unreachable!()
}

fn is_done(&self) -> bool {
true
}
}

impl Default for Box<dyn Operation<Error = std::convert::Infallible>> {
fn default() -> Self {
Box::new(NullOp)
}
}
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use crate::ethercat::DcSysTime;

use super::GPIOIn;
use super::gpio::GPIOIn;

pub(crate) const TRANSITION_MODE_SYNC_IDX: u8 = 0x00;
pub(crate) const TRANSITION_MODE_SYS_TIME: u8 = 0x01;
pub(crate) const TRANSITION_MODE_GPIO: u8 = 0x02;
pub(crate) const TRANSITION_MODE_EXT: u8 = 0xF0;
pub(crate) const TRANSITION_MODE_NONE: u8 = 0xFE;
#[doc(hidden)]
pub const TRANSITION_MODE_NONE: u8 = 0xFE;
pub(crate) const TRANSITION_MODE_IMMEDIATE: u8 = 0xFF;

/// Transition mode of segment
Expand All @@ -26,7 +27,8 @@ pub enum TransitionMode {
}

impl TransitionMode {
pub(crate) const fn mode(&self) -> u8 {
#[doc(hidden)]
pub const fn mode(&self) -> u8 {
match self {
TransitionMode::SyncIdx => TRANSITION_MODE_SYNC_IDX,
TransitionMode::SysTime(_) => TRANSITION_MODE_SYS_TIME,
Expand All @@ -36,7 +38,8 @@ impl TransitionMode {
}
}

pub(crate) const fn value(&self) -> u64 {
#[doc(hidden)]
pub const fn value(&self) -> u64 {
match self {
TransitionMode::SyncIdx | TransitionMode::Ext | TransitionMode::Immediate => 0,
TransitionMode::GPIO(gpio) => *gpio as u64,
Expand Down
Loading

0 comments on commit ebd4330

Please sign in to comment.