EtherCrab

NOTE: If TwinCAT is available, we generally recommend using TwinCAT.

This link uses EtherCrab, an open-source EtherCAT master library.

On Windows, install npcap in “WinPcap API compatible mode”. On Linux/macOS, no additional setup is required.

Install

cargo add autd3-link-ethercrab
target_link_libraries(<TARGET> PRIVATE autd3::link::ethercrab)

Included in the main library.

Included in the main library.

Included in the main library.

APIs

Pass the error callback function as the first argument, and options as the second argument.

use autd3_link_ethercrab::{EtherCrab, EtherCrabOption};
use std::time::Duration;

fn main() {
let _ = 
EtherCrab::new(
    |idx, status| {
        eprintln!("Device[{}]: {}", idx, status);
    },
    EtherCrabOption {
        ifname: None,
        state_check_period: Duration::from_millis(100),
        sync0_period: Duration::from_millis(2),
        sync_tolerance: Duration::from_micros(1),
        sync_timeout: Duration::from_secs(10),
        ..Default::default()
    },
);
}
#include <iostream>
#include <autd3/link/ethercrab.hpp>

int main() {
using namespace autd3;
link::EtherCrab(
    [](const uint16_t idx, const link::Status status) {
      std::cout << "Device[" << idx << "]: " << status << std::endl;
    },
    link::EtherCrabOption{
        .ifname = std::nullopt,
        .state_check_period = std::chrono::milliseconds(100),
        .sync0_period = std::chrono::milliseconds(2),
        .sync_tolerance = std::chrono::microseconds(1),
        .sync_timeout = std::chrono::seconds(10),
    });
return 0; }
using AUTD3Sharp;
using AUTD3Sharp.Link;
using AUTD3Sharp.Utils;

new EtherCrab(
    errHandler: (idx, status) =>
    {
        Console.Error.WriteLine($"Device[{idx}]: {status}");
    },
    option: new EtherCrabOption
    {
        Ifname = null,
        StateCheckPeriod = Duration.FromMillis(100),
        Sync0Period = Duration.FromMillis(2),
        SyncTolerance = Duration.FromMicros(1),
        SyncTimeout = Duration.FromSecs(10),
    }
);
from pyautd3 import Duration
from pyautd3.link.ethercrab import (
    EtherCrab,
    EtherCrabOption,
    Status,
)


def err_handler(idx: int, status: Status) -> None:
    print(f"Device[{idx}]: {status}")


EtherCrab(
    err_handler=err_handler,
    option=EtherCrabOption(
        ifname=None,
        state_check_period=Duration.from_millis(100),
        sync0_period=Duration.from_millis(2),
        sync_tolerance=Duration.from_micros(1),
        sync_timeout=Duration.from_secs(10),
    ),
)

The options available for the EtherCrab link are as follows. Default values are as shown above.

  • ifname: Network interface name. If None, the network interface to which the AUTD3 devices are connected is selected automatically.
  • state_check_period: Interval at which to check for errors.
  • sync0_period: Period of the SYNC0 signal.
    • When connecting a large number of devices, behavior may become unstable. In that case, increase sync0_period. These values should be as small as possible without causing errors. The appropriate values depend on the number of connected units.
  • sync_tolerance: Synchronization tolerance. During initialization, the system waits until the difference in system time among devices falls below this value. If synchronization is not achieved within the timeout below, an error occurs. Changing this value is NOT recommended.
  • sync_timeout: Synchronization timeout. Timeout for the system time difference measurement described above.