Separating CiA402 Logic from EtherCAT (lcec): Modular Adapter + Drive Stub Valid

  • Marcos DC
  • Marcos DC's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
04 Mar 2026 23:18 - 04 Mar 2026 23:39 #343873 by Marcos DC
Thanks for the feedback. Just to clarify an important point that I may not have emphasized clearly:

All components in the current tests run in the same servo-thread at 1 kHz, with a fixed execution order using addf. For example:

safety → pds_manager → procedure (UT) → controlword composer → driver interface

Because of this, execution is deterministic. In HAL this effectively becomes a sequential call chain within the same realtime cycle.

Also, there is only one writer for the final 6040 controlword, produced by the controlword composer, which avoids the typical “multiple writers” problem that often causes ambiguous state transitions.

In HAL, race conditions are caused by multiple threads or multiple writers, not by the number of components.

Regarding gantry and coupling: I agree that final squaring and coordinated homing logic belongs in the motion/kinematics layer. If a coupler is introduced on the HAL side it would only serve a limited purpose — handling safe decouple/recouple situations when the drive performs internal motion (for example CiA402 homing) to avoid command/feedback jumps. It would not replace motion’s gantry or homing logic.

Interestingly, the recent HOME_ABSOLUTE_ENCODER fix in motion (PR #3774) also highlights a similar concern about maintaining internal consistency when offsets are applied during homing. In that patch the motion code re-normalizes pos_cmd, pos_fb, free_tp.curr_pos, and motor_offset to avoid accumulated offsets during re-homing. Conceptually this looks similar to a recoupling step inside the motion layer to keep controller and physical states aligned.

The goal here is not to duplicate motion functionality, but simply to keep CiA402 semantics independent from the transport layer (LCEC/EtherCAT) while maintaining a deterministic controlword path.
Last edit: 04 Mar 2026 23:39 by Marcos DC.

Please Log in or Create an account to join the conversation.

  • Marcos DC
  • Marcos DC's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
04 Mar 2026 23:48 #343874 by Marcos DC
Small clarification regarding the README

After reading the feedback I realized that one part of the README may have been ambiguous, especially the section mentioning “Gantry Support” and gantry_manager.comp.

To clarify the intent of the project:

The goal of this repository is not to introduce a new motion or gantry control layer in HAL. Final gantry squaring, coordinated homing and axis relationships are expected to remain in the motion / kinematics layer (e.g. trivkins) as usual.

The purpose of the HAL components in this project is limited to:

separating CiA402 semantics from the transport layer (LCEC / EtherCAT)

providing a deterministic controlword composition path

adding safety gating

optionally handling decouple/recouple situations when a drive performs internal motion (for example CiA402 homing), to avoid command/feedback discontinuities

So any future “coupler” component would only handle safe transition and coupling of drive states, not replace motion-level gantry logic.

I will update the README to make this clearer.

Please Log in or Create an account to join the conversation.

More
05 Mar 2026 05:17 #343880 by NWE

To prepare proper adapter templates for your two drives (the Lichuan OL57E-4A and the Stepperonline A6-750EC), I just need a few details from your setup so I can map the HAL pins correctly.

If possible, could you share:
1. Your LCEC configuration
• lcec.conf (or equivalent configuration file)
• The EtherCAT XML/ENI if you have it
• Or a snippet of the HAL where the lcec.* pins for the drives appear
2. PDO mapping
I mainly need to confirm the HAL pins for the standard CiA402 objects:
• 6040 Controlword
• 6041 Statusword
• 6060 Modes of Operation (command)
• 6061 Modes of Operation Display
If available in PDO as well:
• 6064 Position Actual Value
• 607A Target Position
3. Homing
• Which homing method (object 6098) you plan to use
• Whether the homing/limit switches are connected to the drive inputs
• The HAL pin names for those inputs (for example lcec.*.din-*)
4. Quick Stop
• Is Quick Stop (Controlword 0x0002) configured and usable on these drives?
• Or do they require a different shutdown sequence?
5. Anything unusual
• Any known quirks with enable, fault reset, or homing behavior.

 

Later tomorrow I should be able to gather some of the info you requested. I know I will have hal pins, lcec.conf, PDO/SDO, and a terminal log from test driving these servos.

I have not looked at CiA402 homing at all yet, I will take a quick look at the manual to check whether I have a preference which homing method I'd use.

One potential quirk I noticed with the Lichuan OL57E-4A was if I test drive it in velocity mode (I was typing hal commands at the terminal) I then can momentarily disconnect the servo amplifier power, shutting down the servo amplifier and resulting in a flood of ethercat error logs in dmesg, in a second or two the drive recovers and ethercat reconnects, and the motors resume rotating at the velocity I had previously set in lcec.

This is hardly a problem, as we will be running in position control mode. I expect a servo drop-out like that would at least trigger a following error in a standard linuxcnc config. It did not do that here as I was just running simple hal commands in the terminal directly to lcec without using CiA402.

Please Log in or Create an account to join the conversation.

  • Marcos DC
  • Marcos DC's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
07 Mar 2026 11:24 #343985 by Marcos DC
Hi @NWE,

Sorry for the late reply — I was a bit busy the last days.

The CiA402 semantic layer is now running in simulation using a HAL drive stub and the core parts are behaving as expected (PDS state machine, controlword ownership, homing supervision, etc.).

The next step is integrating it with real hardware via lcec.

I don't currently have EtherCAT hardware locally, so the plan is to prepare a configuration for your two drives and let you try it when convenient.

I also made the repository public so you can see the current architecture. It is still experimental and not finished yet, but the simulation layer is already working.

Repo:
github.com/MarcosDuqueCesar/linuxcnc-cia402-layer
The following user(s) said Thank You: NWE

Please Log in or Create an account to join the conversation.

More
10 Mar 2026 02:16 #344074 by NWE

Sorry for the late reply — I was a bit busy the last days.


 

Same here. It'll be several more days till I get back to this project.

Please Log in or Create an account to join the conversation.

  • Marcos DC
  • Marcos DC's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
10 Mar 2026 04:30 #344078 by Marcos DC
Hi @NWE,

No worries — things have been a bit busy on my side too

Over the last days I focused on validating the CiA402 logic layer in simulation using a HAL drive stub. The main pieces are behaving as expected now (PDS state machine, controlword composition, homing supervision, etc.).

I also added a small gantry supervisor component on top of the CiA402 layer to experiment with safe decouple/recouple behaviour when drives perform internal motion like CiA402 homing.

At the moment everything is running inside HAL with two simulated drives.
Next step is reconnecting this to the EtherCAT side through an adapter layer.

I'm also planning to write a small Python CLI diagnostic tool to read the HAL signals and print a quick snapshot of the CiA402 state to help with testing.

Your Lichuan drive with 4 axes in one unit is quite interesting — that could be a very good test case once the EtherCAT adapter is wired.

I might also open a separate thread later describing the small framework this is turning into and include your two drives as example adapters.

No rush at all
The following user(s) said Thank You: NWE

Please Log in or Create an account to join the conversation.

  • Marcos DC
  • Marcos DC's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
15 Mar 2026 15:47 #344317 by Marcos DC
Small progress update: the stub has basically turned into a virtual drive backend for validation.
I’m already exercising a fair amount of the core CiA402 runtime behavior in AXIS SIM with it.
Still a lot left to test before going back to real EtherCAT hardware, but the direction looks good.
The following user(s) said Thank You: NWE

Please Log in or Create an account to join the conversation.

Time to create page: 0.089 seconds
Powered by Kunena Forum