Moving the Focal Point
Software control
Section titled “Software control”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 phases = geometry.phase_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, &mut phases, ); client.send(Pattern::new(&phases, Intensity::MAX)).await?; tokio::time::sleep(Duration::from_secs(1)).await; }}phases = geometry.phase_buffer()while True: for sign in (1.0, -1.0): target = center + offset((sign * 20.0) * mm, 0.0 * mm, 0.0 * mm) pattern.focus( geometry, target, wavelength, phases, ) await client.send(Pattern(phases, Intensity.MAX)) await asyncio.sleep(1.0)var phases = geometry.PhaseBuffer();while (true){ foreach (var sign in new[] { 1.0f, -1.0f }) { var target = center + Offset(sign * 20.0f * mm, 0.0f * mm, 0.0f * mm); Pattern.Focus( geometry, target, wavelength, phases ); await client.SendAsync(new Pattern(phases, Intensity.Max)); await Task.Delay(TimeSpan.FromSeconds(1)); }}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.
Hardware control with FociStm
Section titled “Hardware control with FociStm”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 config = SamplingConfig::from_freq(1.0 * Hz)?;client.send(FociStm::new(config, &points, FociStmOption::default())).await?;points = [ ControlPoints(center + offset(20.0 * mm, 0.0 * mm, 0.0 * mm)), ControlPoints(center + offset(-20.0 * mm, 0.0 * mm, 0.0 * mm)),]config = SamplingConfig(1.0 * Hz)await client.send(FociStm(config, points, FociStmOption()))var points = new[]{ (ControlPoints)(center + Offset(20.0f * mm, 0.0f * mm, 0.0f * mm)), (ControlPoints)(center + Offset(-20.0f * mm, 0.0f * mm, 0.0f * mm)),};var config = new SamplingConfig(1.0f * Hz);await client.SendAsync(new FociStm(config, points, new FociStmOption()));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 SamplingConfig.
To switch an arbitrary Pattern rather than just a focal point, use PatternStm instead of FociStm.