Skip to content

Refactoring nearing completion, pull to close out branch#7

Open
baileyji wants to merge 35 commits intomainfrom
csu-refactor
Open

Refactoring nearing completion, pull to close out branch#7
baileyji wants to merge 35 commits intomainfrom
csu-refactor

Conversation

@baileyji
Copy link
Member

Will re-branch for new design work from this point monday.

Remove addConfigurationFunc as moving to a subclass approach
…cept of slaveConfigFuncs with the EPOS4 bus and instead work them in through subclassing.
Renamed and refined public methods for network interface and EPOS4 motors to align with Python conventions. Introduced private methods for low-level operations, ensuring encapsulation and clarity. Added interface state validation using `netifaces` to improve robustness during interface operations.
Replaced direct access to EtherCAT hardware with a more centralized `_bus` abstraction, ensuring consistent interaction and easier maintenance. Simplified method naming, improved logging, and optimized state change handling. Updated dependent code to align with the new structure.
Replaced `print` statements with `getLogger` for structured logging. Modularized repetitive code by introducing `_block_during_move`. Refactored homing and motion control logic for better readability and maintainability.
Renamed variables for clarity, fixed a string format bug, reordered imports, and removed unused or redundant functions. This improves code readability and eliminates unnecessary functionality.
Simplified PDO send/receive code by consolidating methods. Introduced a threading to prevent timeouts with locks for concurrency control. Improved error handling, debugging, and logging for slave operations. Deprecated older configuration functions and improved style consistency across the codebase.

Testing in progress.
Introduced methods for retrieving slave position, velocity, and error diagnostics, improving diagnostic capabilities. Simplified and cleaned up PDO handling logic by adjusting threading behavior and replacing redundant operations. Commented out unused `_set_controlword` and related methods to streamline functionality.
Introduced a ControlWord enum to define control word commands clearly, improving readability and maintainability. Enhanced the assertStatuswordState function to support both StatuswordStates and general Enums, increasing flexibility.
Revised device and network state management to support Enums and improve transition handling. Added thread safety for PDO operations using threading events for pending messages. Made variable naming more consistent and introduced properties for improved readability and encapsulation.

Had a PEP8 party
Moved the EPOS4Bus class to a new file (epos4bus.py) to improve maintainability by modularizing the code. Updated imports accordingly in related files and removed redundant code in epos4.py.

This is also helping hilight the questionable class model of having both EthercatBus and EPOS4Bus. I'm thinking Ethercat bus should be subsumed into EPOS4Bus
Updated control word commands and object dictionary for better motion control. Introduced fault clearing, status bit waiting, and additional SDO-dependent properties for improved device state handling. Refined motion handling logic, including homing and position setup, ensuring alignment with the EPOS4 device operations.
Refactored EPOS4 object dictionary types with `dataclass` for immutability and better iteration support. Introduced a centralized register file with EPOS4 errors (rest to be moved later) for improved error interpretation and handling in diagnostic messages. Removed redundant and unclear methods, and adapted code to consistently utilize the updated object structure.
Invoke `disable_pdo()` before initializing slaves to ensure clean startup. Fix `position` property access and enforce integer casting for motion parameters to improve type consistency and prevent errors.
…tive positioning. Actually looks like a set of slits.

Introduced thread-safe locking for EtherCAT bus operations using RLock to prevent concurrency issues. Updated configuration in `csu.yaml` (`um_per_count` added) and include positional offsets. Refactored hardware logic to compute bar positions and added motor stop functionality in `epos4bus.py`.
@baileyji baileyji requested a review from prkrtg March 15, 2025 19:12
@baileyji baileyji self-assigned this Mar 15, 2025
baileyji and others added 2 commits March 17, 2025 15:53
Introduced methods to enable homing via SDO operations with various homing sources such as SSI or user-defined positions. Deprecated and replaced outdated homing methods to improve reliability and maintainability. Included error handling and logging for a more robust homing process.
…s are defined to clarify intent. Add a stub for a register class to aid debugging.
…eed to repeat some commands. This is indicative of some sort of larger library issue or misconception on my part. Will investigate more. For now indent to make pretty motions.
…vatories/ether-cat-soft into csu-refactor

* 'csu-refactor' of https://github.com/CaltechOpticalObservatories/ether-cat-soft:
  COO-107 - Refactor ethercat library into pip installable package (#6)
  Updated the readme with more information on how to get started plus background
@thomazach
Copy link
Collaborator

It's great to see the much needed refactor @baileyji. Your commit message about waiting for pdo transmission might be explained indirectly by the buffers on the hardware. If I remember correctly, accurate statusword updates are only published after moving through 3 positions in the buffer during PDO, and I believe pysoem pushes blank telegrams through the buffers during downtime that is shorter than the watchdog timeout. This could be particularly bad for commands that switch the network management states, because I believe those states need to be recognized by both the peripheral and controller.

Added functionality to handle homing operations using SDO with detailed status checks, parameter configuration, and timeout handling. Reintroduced previously removed homing-related object dictionary entries to align with the new implementation.
Consolidated state transition handling by iterating over slaves individually and maintaining node-specific control sequences. Simplified logic to eliminate assumptions of uniform statusword states across devices and added safeguards against KeyError and IndexError during sequence processing.
Renamed `PDOCycleTime` to `_PDO_CYCLE_TIME` for clarity and consistency. Added optional `shutdown_first` argument to `enable_pdo` to safely bring devices to a ready state before operational setup. Enhanced logging to monitor sent/received PDO counters and implemented minor cleanup for better readability and functionality.
Refactored `StatuswordRegister` for more flexibility, including state and bit handling. Updated SDO methods with consistent naming and improved readability. Enhanced homing workflow and added support for profile position moves using better abstractions for Statusword states.
Refactored multiple class methods for better type hinting, readability, and consistency. Added new properties and parameters to improve monitoring, debugging, and control, including `fault_state`, `monitor`, and extended debug info. Removed unused or redundant code to streamline functionality.
Replaced netifaces-based network interface validation with a direct check against the operating state in the /sys/class/net directory. This simplifies dependencies and improves clarity by using native system files for interface status validation. Updated error handling for missing operstate files to ensure more informative exceptions.
…y class structure.

Consolidated slit-related classes to streamline functionality and improve clarity. Removed unused methods and redundant logic. Updated demo and manager code to align with new MaskConfig and Slit implementations, ensuring consistency and reducing code complexity.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants