Skip to content
This is the development version of the documentation. It may change before the next release. See 0.6.x for the latest release.

Single Device

This section explains how to drive a single device.

This tutorial uses echocat. If you are on Windows, install Npcap in “WinPcap API-compatible Mode”.

The following is an example that generates a focal point 150 mm directly above the center of the array with a single AUTD3 device and applies a 200 Hz sine-wave AM.

First, create an appropriate project and add the autd3-rs library as a dependency. For focus computation and AM modulation, also add autd3-rs-pattern and autd3-rs-modulation. Also add the autd3-rs-link-echocat library, which handles communication with the device. An asynchronous runtime is also required, so add tokio as well.

cargo new --bin autd3-sample && cd autd3-sample
cargo add autd3-rs
cargo add autd3-rs-pattern
cargo add autd3-rs-modulation
cargo add autd3-rs-link-echocat
cargo add tokio --features full

Next, edit the src/main.rs file to look like the following.

use autd3_rs::commands::{Modulation, Pattern, SetSilencer};
use autd3_rs::geometry::{Autd3, Geometry, offset};
use autd3_rs::units::{Hz, m, mm, s};
use autd3_rs::value::SamplingConfig;
use autd3_rs::{Client, ClientConfig};
use autd3_rs_link_echocat::EchocatLinkOption;
#[tokio::main(flavor = "multi_thread")]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Define a geometry consisting of a single AUTD3 device.
let geometry = Geometry::new(vec![Autd3::default()]);
// Open the client over an echocat link.
let client = Client::open(
&geometry,
EchocatLinkOption::default(),
ClientConfig::default(),
)
.await?;
// Generate a focus 150 mm above the array center.
let target = geometry.center() + offset(0.0 * mm, 0.0 * mm, 150.0 * mm);
let wavelength = autd3_rs_pattern::wavelength(340.0 * m / s);
let mut patterns = geometry.pattern_buffer();
autd3_rs_pattern::focus(
&geometry,
target,
wavelength,
&autd3_rs_pattern::FocusOption::default(),
&mut patterns,
);
// Apply a 200 Hz sine-wave AM.
let mut modulation = autd3_rs_modulation::modulation_buffer();
autd3_rs_modulation::sine(
200 * Hz,
&autd3_rs_modulation::SineOption {
sampling_config: SamplingConfig::FREQ_4K,
..Default::default()
},
&mut modulation,
)?;
let mut builder = client.datagram_builder();
builder
.push(SetSilencer::default())
.push(Pattern::new(&patterns))
.push(Modulation::new(SamplingConfig::FREQ_4K, &modulation));
let frames = builder.build()?;
for frame in &frames {
client.send_checked(frame).await?;
}
tokio::signal::ctrl_c().await?;
client.stop().await?;
client.close().await?;
Ok(())
}

Then, run it.

cargo run --release

On Linux and macOS, administrator privileges may be required to use echocat. In that case, use:

cargo build --release && sudo ./target/release/autd3_sample