How shkwon98/epos4-soem works
Project Type and Purpose
• The application is a real-time EtherCAT master used to control EtherCAT slave devices (such as epos4 and elmo). It runs on a Raspberry Pi 4 with a Preempt-rt Linux kernel and integrates with external GUIs on a remote PC.
• The README and file tree indicate that this is a full-fledged, real-time control system with distinct modules managing real-time scheduling, EtherCAT communication (via the SOEM dependency), control logic, and socket communication.
Analyzing the File Structure
• Top-Level Modules:
• ansur_control: Contains files like CControlThread.cpp and tcpCommand.cpp, which likely implement the control loops and TCP-based commands used for system control.
• ansur_ethercat: Implements the EtherCAT-related functionality with modules such as CPdoMapping.cpp and SOEM.cpp. This module is responsible for interacting with the EtherCAT slaves.
• ansur_socket: Handles networking, incorporating both TCP and UDP packet implementations. This module is key for interfacing with external components, for example when a remote GUI is used.
• ansur_thread: Contains functionality for thread looping and scheduling. In a real-time environment, proper thread management is crucial.
• Supporting Files:
• main.cpp serves as the entry point which likely initializes and coordinates these modules.
• Multiple CMakeLists.txt files indicate that each component is somewhat independent, hinting at a modular architecture.
Diagramming the System – Main Components and Relationships
a. Main Components:
• Real-Time Control Engine (ansur_control): Implements control threads and command handling.
• EtherCAT Communication Module (ansur_ethercat): Manages EtherCAT communications with slave devices via SOEM.
• Socket Communication Module (ansur_socket): Facilitates network communication (TCP/UDP) for external interfacing.
• Thread Management and Scheduling Module (ansur_thread): Ensures real-time task scheduling and looping.
• Main Application (main.cpp): Acts as the orchestrator integrating all these components.
• External Interfaces:
• EtherCAT Slave Devices: The physical devices controlled over the EtherCAT bus.
• Remote GUI (epos4-soem-gui): Running on a remote PC for visualization and interaction.
• Underlying RTOS & Hardware: Raspberry Pi with Preempt-rt Linux ensuring deterministic behavior.
b. Relationships and Interactions:
• The Main Application initializes and coordinates the overall system.
• The Control Engine interacts with the EtherCAT Communication Module to send commands and receive status from the EtherCAT slaves.
• It also uses the Socket Communication Module to exchange data with remote systems (like the GUI).
• The Thread Management module underpins both control and communication modules to ensure that real-time scheduling is enforced.
• Data flows from the main control loops (in ansur_control) to update the EtherCAT states (via ansur_ethercat) and to package/send/receive network data (via ansur_socket).
c. Architectural Patterns and Design Principles:
• Modularity: The project is divided into clear, cohesive modules (control, EtherCAT, socket, thread management).
• Real-Time Systems Design: Special emphasis on thread scheduling and deterministic data flows, given the use of Preempt-rt.
• Separation of Concerns: Each module focuses on a specific functionality (e.g., control logic vs. EtherCAT communication).
• Integration via a central coordinating point (main.cpp) ensuring that these modules interact correctly.
d. Relevant Technologies, Frameworks, or Libraries:
• SOEM (Simple Open EtherCAT Master) is a key dependency used in the EtherCAT module.
• CMake is used as the build system, suggesting that modules can be built and maintained independently.
• Standard C++ libraries and possibly custom threading constructs for real-time scheduling are involved.
• Networking libraries for TCP/UDP communication in the socket module.
• Real-Time Linux (Preempt-rt patched kernel) on Raspberry Pi, which influences the design of thread scheduling and control loops.
Final Checklist
• Main Application (main.cpp)
• Control Engine (ansur_control)
• EtherCAT Communication (ansur_ethercat)
• Socket Communication (ansur_socket)
• Thread Management (ansur_thread)
• External Interfaces (EtherCAT Slaves, Remote GUI, RTOS/Hardware)
• Initialization/control flows from main.cpp to other modules.
• Data flows from the control engine to the EtherCAT module and to the socket module.
• External communications between the system and remote devices.
• Detail the architectural patterns like modularity, real-time scheduling, and separation of concerns.