Python tutorial
First, install pyautd3
library.
pip install pyautd3==29.0.0rc16
pip install pyautd3_link_soem==29.0.0rc16
Next, make main.py
file as follows.
This is the source code for generating a focus with AM modulation.
import os
import numpy as np
from pyautd3 import AUTD3, Controller, Focus, Hz, Silencer, Sine
from pyautd3_link_soem import SOEM, Status
def err_handler(slave: int, status: Status) -> None:
print(f"slave [{slave}]: {status}")
if status == Status.Lost():
# You can also wait for the link to recover, without exiting the process
os._exit(-1)
if __name__ == "__main__":
with Controller.builder([AUTD3([0.0, 0.0, 0.0])]).open(
SOEM.builder().with_err_handler(err_handler),
) as autd:
firmware_version = autd.firmware_version()
print(
"\n".join(
[f"[{i}]: {firm}" for i, firm in enumerate(firmware_version)],
),
)
autd.send(Silencer())
g = Focus(autd.center + np.array([0.0, 0.0, 150.0]))
m = Sine(150 * Hz)
autd.send((m, g))
_ = input()
autd.close()
Then, run the program.
python main.py
For linux users
You may need to run with administrator privileges when using SOEM on Linux.
sudo setcap cap_net_raw,cap_net_admin=eip <your python path>
python main.py
For macOS users
You may need to run with administrator privileges when using SOEM on macOS.
sudo chmod +r /dev/bpf*
python main.py