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.

Moving the Focal Point

In AUTD3, a Pattern is overwritten each time it is sent. Therefore, running code like the following moves the focal position roughly once per second.

let mut patterns = geometry.pattern_buffer();
loop {
for sign in [1.0_f32, -1.0] {
let target = center + offset((sign * 20.0) * mm, 0.0 * mm, 0.0 * mm);
autd3_rs_pattern::focus(
&geometry,
target,
wavelength,
&autd3_rs_pattern::FocusOption::default(),
&mut patterns,
);
let mut builder = client.datagram_builder();
builder.push(Pattern::new(&patterns));
for frame in &builder.build()? {
client.send_checked(frame).await?;
}
tokio::time::sleep(Duration::from_secs(1)).await;
}
}

The code above controls the timing in software. Its accuracy depends on the OS and the execution environment, so if higher-precision control is needed, using FociStm / PatternStm is recommended.

The code that achieves behavior equivalent to the above using FociStm is as follows.

let points = [
ControlPoints::from(center + offset(20.0 * mm, 0.0 * mm, 0.0 * mm)),
ControlPoints::from(center + offset(-20.0 * mm, 0.0 * mm, 0.0 * mm)),
];
let mut builder = client.datagram_builder();
builder.push(FociStm::new(0.5 * Hz, &points, FociStmOption::default()));
for frame in &builder.build()? {
client.send_checked(frame).await?;
}

Because FociStm / PatternStm loops inside the AUTD3 device, no software loop is needed, and it automatically loops infinitely after being sent. In addition, the timing is controlled by the timer built into the AUTD3 device, so it is highly accurate and can be specified with a resolution as fine as 25 µs. However, due to constraints of this timer, there are frequencies that cannot be output.

The switching timing of FociStm / PatternStm is specified by the frequency or period of one loop. That is, in this case two focal points make 0.5 Hz (2 s), so each focal point is output for 1 s. Note that by using SamplingConfig, the frequency or period can be specified as the sampling frequency, that is per focal point, rather than per loop.

To switch an arbitrary Pattern rather than just a focal point, use PatternStm instead of FociStm.