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

WriteFociBuffer

WriteFociBuffer is a low-level command that writes a focal point sequence for Foci STM into a bank.

WriteFociBuffer {
bank,
start_index,
points,
};
Field Type Description
bank PatternBank Destination bank
start_index usize Start index for writing within the bank
points &[ControlPoints] Sequence of focal point samples

ControlPoints is one sample holding a sequence of focal points (ControlPoint) and an amplitude. Every sample must have the same number of foci. For details see FociStm.

WriteFociBuffer writes only what fits in one frame. The limit (in ControlPoints) depends on the number of foci and is given by WriteFociBuffer::max_len(num_foci); exceeding it is an error when sending.

An example of playing a focal point sequence as Foci STM via WriteFociBuffer → ConfigFociStm → ActivatePatternBank (equivalent to the high-level FociStm). The 200 points do not fit in one frame, so they are written in pieces.

use std::f32::consts::PI;
use autd3_rs::commands::{
ActivatePatternBank, Clear, ConfigFociStm, Synchronize, WriteFociBuffer,
};
use autd3_rs::geometry::{Autd3, Geometry, offset};
use autd3_rs::units::{Hz, m, mm, s};
use autd3_rs::value::{ControlPoints, LoopBehavior, PatternBank, SamplingConfig, TransitionMode};
use autd3_rs::Client;
use autd3_rs::udp::TransportOption;
let geometry = Geometry::new(vec![Autd3::default()]);
let option = TransportOption::default();
let mut client = Client::open(&geometry, &option).await?;
client.send(Clear).await?;
client.send(Synchronize).await?;
let center = geometry.center() + offset(0.0 * mm, 0.0 * mm, 150.0 * mm);
let points: Vec<ControlPoints> = (0..200)
.map(|i| {
let theta = 2.0 * PI * i as f32 / 200.0;
ControlPoints::from(center + offset(30.0 * mm * theta.cos(), 30.0 * mm * theta.sin(), 0.0 * mm))
})
.collect();
let bank = PatternBank::B0;
let max_len = WriteFociBuffer::max_len(1);
for (i, chunk) in points.chunks(max_len).enumerate() {
client.send(WriteFociBuffer {
bank,
start_index: i * max_len,
points: chunk,
}).await?;
}
client.send(ConfigFociStm {
bank,
config: SamplingConfig::from_freq(1.0 * Hz * points.len() as f32)?,
size: points.len(),
num_foci: 1,
sound_speed: 340.0 * m / s,
loop_behavior: LoopBehavior::Infinite,
}).await?;
client.send(ActivatePatternBank {
bank,
transition_mode: TransitionMode::Immediate,
}).await?;