# Direct EtherCAT Control & Mode Switching (Omron Servo / LinuxCNC `lcec`) ## Overview This cheat sheet demonstrates direct, low-level control of an Omron EtherCAT servo drive using LinuxCNC's `lcec` driver without the intermediate `cia402` HAL component (by Dominik). All CiA 402 state machine transitions (Controlword `0x6040`), operation mode changes (`0x6060`), and setpoints are mapped directly to raw PDOs and controlled manually via `halcmd`. ## Key Features & Safety Notes * **Modes Covered:** Cyclic Synchronous Position (**CSP**, mode `8`) and Cyclic Synchronous Velocity (**CSV**, mode `9`). * **Bumpless Mode Switching:** Before switching back from Velocity (`CSV`) to Position (`CSP`), `target-pos` (`0x607A`) **must** be synchronized with `actual-pos` (`0x6064`) to prevent sudden, high-speed position jumps. * **State Machine Sequence:** Drive enable requires sequential Controlword (`cw`) transitions: `6` (Shutdown) → `7` (Switch On) → `15` (Enable Operation). ## Prerequisites * `ethercat` master service running (`sudo systemctl start ethercat`). * Configuration files `omron_direct.xml` and `direct_test.hal` placed in the working directory (note: adjust the path `/omron_direct.xml` in the `.hal` file if needed). ***Terminal log (halrun -I -f ~/direct_test.hal):********* Note: Using POSIX realtime halcmd: setp lcec.0.0.cw 6 halcmd: setp lcec.0.0.cw 7 halcmd: setp lcec.0.0.cw 15 halcmd: setp lcec.0.0.target-pos 2097152 halcmd: setp lcec.0.0.target-pos 0 halcmd: setp lcec.0.0.target-vel 0 halcmd: setp lcec.0.0.opmode 9 halcmd: setp lcec.0.0.target-vel 4194303 halcmd: setp lcec.0.0.target-vel 0 halcmd: show pin lcec.0.0.actual-pos Component Pins: Owner Type Dir Value Name 12 s32 OUT 111696867 lcec.0.0.actual-pos halcmd: setp lcec.0.0.target-pos 111696867 halcmd: setp lcec.0.0.opmode 8 halcmd: setp lcec.0.0.cw 6 halcmd: setp lcec.0.0.cw 7 halcmd: setp lcec.0.0.cw 15 halcmd: *********************direct_test.hal********************** loadrt threads name1=servo-thread period1=1000000 loadusr -W lcec_conf /omron_direct.xml loadrt lcec addf lcec.read-all servo-thread addf lcec.write-all servo-thread # 8 = CSP setp lcec.0.0.opmode 8 start ******************************************************** ******************omron_direct.xml********************** omron_direct.xml ***************************************************