Hi @rodw, @Hakan and everyone,
Thanks a lot for the input — this is really helpful.
@rodw, your barebone CiA402 state handler is exactly what I needed to properly structure the lower layer. The statusword & 0x006F decoding and the minimal enable sequence up to
Operation Enabled fit perfectly as a clean
PDS manager.
@Hakan, yes — I’m now looking at splitting things one step further, exactly as you suggest.
The structure I’m converging to is:
- PDS manager (CiA402 FSA layer)
- Based on rodw’s barebone logic
- Responsible only for bringing the drive from Switch On Disabled to Operation Enabled
- No homing, no CSP logic inside
- Exposes something like op_enabled
- Op-mode layer (separate modules)
- CSP
- CSV
- Homing
- PP / PV
- Probing, etc.
Each module only runs when op_enabled == true and after 6060/6061 handshake is confirmed.
- Application layer (drive-agnostic)
- Homing bit4 pulse generation
- done_mask / done_value evaluation
- Error mask/value
- All configurable via parameters (no hardcoded drive values)
The goal is to keep this fully drive-agnostic at the application level, using mask/value instead of fixed statusword comparisons.About the concern Hakan mentioned — “maybe switching op-modes and restoring position kills it” — I agree that’s the main trap.My current idea is:
- On mode entry: temporarily slave pos_cmd := pos_fb (freeze target) until the drive confirms the new mode via 6061
- Only then release control to avoid position jumps
- Same approach on exit back to CSP
So mode switching becomes edge-triggered and gated, not a live swap.
To make sure I’m not inventing behavior, I’m using these two documents as formal references for the machine state and execution semantics:
- CiA 402 – Part 2 (Operation Modes & PDS Finite State Automaton)
- PLCopen Motion Control – Part 1 (FB Model & State Diagram)
Right now I’m validating all of this in a pure SIM environment (drive stub + HAL components), before integrating back into real EtherCAT hardware.
Also, just a small note: during the week I mostly work on this code at my job — evenings are usually family time (kids at home), so progress sometimes comes in structured blocks rather than daily updates. But I’m moving forward steadily.
If anyone has suggestions on best practices for mode handover (especially CSP ⇄ Homing) or additional references worth reading, I’d really appreciate it.
Code:
[i][b][b][i][i][code][b][code][b][code][code][code][b][b] [/b][/b]
[/code][/code][/b][/code][/b][/code][/i][/i][/b][/b][/i][/code]