pcdshub / pytmc

Generate EPICS IOCs and records from TwinCAT projects - along with many TwinCAT project tools
https://pcdshub.github.io/pytmc/
Other
10 stars 11 forks source link

Generate topology diagrams? #301

Closed klauer closed 1 year ago

klauer commented 1 year ago

I'd imagine there is enough information in the TwinCAT project to assemble a diagram similar to the following:

image (screenshot courtesy of Nick)

It'd be nice if pytmc could generate such a diagram for usage in project documentation.

klauer commented 1 year ago

It's at least technically possible - but this needs a bit of work to actually look nice and (more importantly) be useful:

image

Code ```python from pytmc.parser import Box, TcSmItem, parse from pytmc.bin.template import get_boxes proj = parse("lcls-plc-rixs-optics/lcls-plc-rixs-optics.tsproj") boxes = get_boxes(proj) parent_to_children = {} def get_id(box: Box): return box.attributes["Id"] print(""" digraph { rankdir="LR"; node [shape=record]; """) for box in boxes: print(f""" {get_id(box)} [label="{box.name} / {box.EtherCAT[0].attributes["Type"]}"];""") for child in box._children: if isinstance(child, TcSmItem): child_box, = child.Box elif isinstance(child, Box): child_box = child else: continue parent_to_children.setdefault(box, []).append(child_box) for parent, children in parent_to_children.items(): print(f""" {get_id(parent)} -> {get_id(children[0])};""") last_child = children[0] for child in children[1:]: print(f""" {get_id(last_child)} -> {get_id(child)};""") last_child = child print("}") ```

(I didn't verify any details here as it's Friday at 5PM, so this could still be wrong)

klauer commented 1 year ago

I think that's less useful than the following. Let's go with this for the docs:

- Term 1 (EK1200): EK1200-5000 EtherCAT Power supply (2A E-Bus) [ID=1]
    - PMPS_FFO: EL2202 2Ch. Dig. Output 24V, 0.5A [ID=2]
    - Term 3 (EL6070): EL6070 1Ch. Licensing-Terminal [ID=3]
    - EVR: EL1252-0050 2Ch. Fast Dig. Input 5V, 1µs, DC Latch [ID=77]
    - PMPS_PRE: EL6695 EtherCAT Bridge terminal (Primary) [ID=4]
    - Term 5 (EK1122): EK1122 2 port EtherCAT junction [ID=5]
        - EK1100_M1K2: EK1100 EtherCAT Coupler (2A E-Bus) [ID=6]
            - Term 7 (EL9410): EL9410 E-Bus Power Supplier  (Diagnostics) [ID=7]
            - EL7047_M1K2_Yleft: EL7047 1Ch. Stepper motor output stage (50V, 5A) [ID=8]
            - EL7047_M1K2_Yright: EL7047 1Ch. Stepper motor output stage (50V, 5A) [ID=9]
            - EL7047_M1K2_Xup: EL7047 1Ch. Stepper motor output stage (50V, 5A) [ID=10]
            - EL7047_M1K2_Xdwn: EL7047 1Ch. Stepper motor output stage (50V, 5A) [ID=11]
            - EL7047_M1K2_PitchCoarse: EL7047 1Ch. Stepper motor output stage (50V, 5A) [ID=12]
            - EL5042_M1K2_Yleftright: EL5042 2Ch. BiSS-C Encoder [ID=13]
            - EL5042_M1K2_Xupdwn: EL5042 2Ch. BiSS-C Encoder [ID=14]
            - EL5042_M1K2_Pitch: EL5042 2Ch. BiSS-C Encoder [ID=15]
            - EL6001_M1K2_PitchFine: EL6001 Interface (RS232) [ID=16]
            - EL3054_M1K2_FWM_PRSM: EL3054 4Ch. Ana. Input 4-20mA [ID=17]
            - Term 18 (EL3202-0010): EL3202-0010 2Ch. Ana. Input PT100 (RTD), High Precision [ID=18]
            - Term 19 (EL3202-0010): EL3202-0010 2Ch. Ana. Input PT100 (RTD), High Precision [ID=19]
            - Term 20 (EL3202-0010): EL3202-0010 2Ch. Ana. Input PT100 (RTD), High Precision [ID=20]
            - EL1004_M1K2_STO: EL1004 4Ch. Dig. Input 24V, 3ms [ID=44]
            - Term 22 (EL9011): EL9011 End Terminal [ID=22]
        - EK1100_ST1K2_ZOS: EK1100 EtherCAT Coupler (2A E-Bus) [ID=58]
            - ST1K1-EL7041: EL7041 1Ch. Stepper motor output stage (50V, 5A) [ID=59 SyncUnit="ST1K1"]
            - ST1K1-EL5042: EL5042 2Ch. BiSS-C Encoder [ID=60 SyncUnit="ST1K1"]
            - ST1K1-EL2008: EL2008 8Ch. Dig. Output 24V, 0.5A [ID=61 SyncUnit="ST1K1"]
            - ST1K1-EL9011: EL9011 End Terminal [ID=62]
        - EK1100_MR1K1: EK1100 EtherCAT Coupler (2A E-Bus) [ID=63]
            - Term 64 (EL9410): EL9410 E-Bus Power Supplier  (Diagnostics) [ID=64]
            - EL7047_M1K1_Yup: EL7047 1Ch. Stepper motor output stage (50V, 5A) [ID=65]
            - EL7047_M1K1_Ydwn: EL7047 1Ch. Stepper motor output stage (50V, 5A) [ID=66]
            - EL7047_M1K1_Xup: EL7047 1Ch. Stepper motor output stage (50V, 5A) [ID=67]
            - EL7047_M1K1_Xdwn: EL7047 1Ch. Stepper motor output stage (50V, 5A) [ID=68]
            - EL7047_M1K1_PitchCoarse: EL7047 1Ch. Stepper motor output stage (50V, 5A) [ID=69]
            - EL5042_M1K1_Yupdwn: EL5042 2Ch. BiSS-C Encoder [ID=70]
            - EL5042_M1K1_Xupdwn: EL5042 2Ch. BiSS-C Encoder [ID=71]
            - EL5042_M1K1_Pitch: EL5042 2Ch. BiSS-C Encoder [ID=72]
            - EL6001_M1K1_PitchFine: EL6001 Interface (RS232) [ID=73]
            - EL3054_M1K1_FWM_PRSM: EL3054 4Ch. Ana. Input 4-20mA [ID=74]
            - Term 75 (EL3202-0010): EL3202-0010 2Ch. Ana. Input PT100 (RTD), High Precision [ID=75]
            - Term 76 (EL3202-0010): EL3202-0010 2Ch. Ana. Input PT100 (RTD), High Precision [ID=76]
            - EL1004_M1K1_STO: EL1004 4Ch. Dig. Input 24V, 3ms [ID=78]
            - Term 101 (EL9011): EL9011 End Terminal [ID=101]
        - EK1100_MR1K1_BEND: EK1100 EtherCAT Coupler (2A E-Bus) [ID=23]
            - EL5042_M1K1_BEND_USDS: EL5042 2Ch. BiSS-C Encoder [ID=43]
            - EL9576_M1K1_BEND_US_PWR: EL9576 Brake chopper terminal [ID=45]
            - EL7041_M1K1_BEND_US: EL7041 1Ch. Stepper motor output stage (50V, 5A) [ID=46]
            - EL9576_M1K1_BEND_DS_PWR: EL9576 Brake chopper terminal [ID=47]
            - EL7041_M1K1_BEND_DS: EL7041 1Ch. Stepper motor output stage (50V, 5A) [ID=48]
            - EL3202-0010_M1K1US1_M1K1US2: EL3202-0010 2Ch. Ana. Input PT100 (RTD), High Precision [ID=49]
            - EL3202-0010_M1K1US3_M1K1DS1: EL3202-0010 2Ch. Ana. Input PT100 (RTD), High Precision [ID=50]
            - EL3202-0010_M1K1DS2_M1K1DS3: EL3202-0010 2Ch. Ana. Input PT100 (RTD), High Precision [ID=51]
            - EL1004_M1K1_BENDER_STO: EL1004 4Ch. Dig. Input 24V, 3ms [ID=53]
            - Term 54 (EL9512): EL9512 Power supply terminal 12V [ID=54]
            - EL2024-0010_M1K1_BEND_LED1: EL2024-0010 4Ch. Dig. Output 12V, 2A [ID=55]
            - EL2024-0010_M1K1_BEND_LED2: EL2024-0010 4Ch. Dig. Output 12V, 2A [ID=56]
            - Term 161 (EL9011): EL9011 End Terminal [ID=161]
    - E5 (EK1122): EK1122 2 port EtherCAT junction [ID=21]
        - SL1K2-EXIT (EK1100): EK1100 EtherCAT Coupler (2A E-Bus) [ID=125]
            - EL7047_SL1K2_PITCH: EL7047 1Ch. Stepper motor output stage (50V, 5A) [ID=126]
            - EL7047_SL1K2_VERT: EL7047 1Ch. Stepper motor output stage (50V, 5A) [ID=127]
            - EL7047_SL1K2_ROLL: EL7047 1Ch. Stepper motor output stage (50V, 5A) [ID=128]
            - EL7047_SL1K2_GAP: EL7047 1Ch. Stepper motor output stage (50V, 5A) [ID=129]
            - EL7047_SL1K2_YAG: EL7047 1Ch. Stepper motor output stage (50V, 5A) [ID=130]
            - EL5042_SL1K2_PITCH_VERT: EL5042 2Ch. BiSS-C Encoder [ID=131]
            - EL5042_SL1K2_ROLL_GAP: EL5042 2Ch. BiSS-C Encoder [ID=132]
            - EL5042_SL1K2_YAG: EL5042 2Ch. BiSS-C Encoder [ID=133]
            - EL3201_SL1K2_1: EL3201 1Ch. Ana. Input PT100 (RTD) [ID=134]
            - EL3201_SL1K2_2: EL3201 1Ch. Ana. Input PT100 (RTD) [ID=135]
            - EL3201_SL1K2_3: EL3201 1Ch. Ana. Input PT100 (RTD) [ID=136]
            - EL3201_SL1K2_4: EL3201 1Ch. Ana. Input PT100 (RTD) [ID=137]
            - EL2004_SL1K2: EL2004 4Ch. Dig. Output 24V, 0.5A [ID=138]
            - EL4004_SL1K2: EL4004 4Ch. Ana. Output 0-10V, 12bit [ID=57]
            - EL9011_SL1K2: EL9011 End Terminal [ID=162]
        - X1 SP1K1-MONO(EK1100): EK1100 EtherCAT Coupler (2A E-Bus) [ID=34]
            - SP1K1-EL9410-E1: EL9410 E-Bus Power Supplier  (Diagnostics) [ID=24]
            - m_pi_m: EL7047 1Ch. Stepper motor output stage (50V, 5A) [ID=25]
            - g_pi_m: EL7047 1Ch. Stepper motor output stage (50V, 5A) [ID=26]
            - m_h_m: EL7047 1Ch. Stepper motor output stage (50V, 5A) [ID=27]
            - g_h_m: EL7047 1Ch. Stepper motor output stage (50V, 5A) [ID=28]
            - s_io_m: EL7047 1Ch. Stepper motor output stage (50V, 5A) [ID=29]
            - s_r: EL7047 1Ch. Stepper motor output stage (50V, 5A) [ID=30]
            - m_pi_up_dwn_e: EL5042 2Ch. BiSS-C Encoder [ID=31]
            - g_pi_up_dwn_e: EL5042 2Ch. BiSS-C Encoder [ID=32]
            - m_h_e-g_h_e: EL5042 2Ch. BiSS-C Encoder [ID=33]
            - s_io_e: EL5042 2Ch. BiSS-C Encoder [ID=35]
            - EL3054_SP1K1_FWM_PRSM: EL3054 4Ch. Ana. Input 4-20mA [ID=36]
            - SP1K1-EL3202-E13: EL3202-0010 2Ch. Ana. Input PT100 (RTD), High Precision [ID=37]
            - SP1K1-EL3202-E14: EL3202-0010 2Ch. Ana. Input PT100 (RTD), High Precision [ID=38]
            - SP1K1-EL3204-E15: EL3204 4Ch. Ana. Input PT100 (RTD) [ID=39]
            - SP1K1-EL3204-E16: EL3204 4Ch. Ana. Input PT100 (RTD) [ID=40]
            - SP1K1-EL1004-E17: EL1004 4Ch. Dig. Input 24V, 3ms [ID=41]
            - SP1K1-EL9011: EL9011 End Terminal [ID=42]
        - Box 84 (EP2338-0002): EP2338-0002 8 Ch. Dig. Input/Output 24V, 0,5A, M12 [ID=84]
    - Term 79 (EK1521-0010): EK1521-0010 1 port EtherCAT junction (FX-SingleMode) [ID=79]
        - Term 306 (EK1501-0010): EK1501-0010 EtherCAT Coupler (2A E-Bus, FX-SingleMode, ID switch) [ID=306]
            - Term 307 (EL2202): EL2202 2Ch. Dig. Output 24V, 0.5A [ID=307]
            - Term 308 (EL6070): EL6070 1Ch. Licensing-Terminal [ID=308]
            - Term 309 (EL6695): EL6695 EtherCAT Bridge terminal (Primary) [ID=309]
            - Term 310 (EK1122): EK1122 2 port EtherCAT junction [ID=310]
                - EK1100_MR2K2: EK1100 EtherCAT Coupler (2A E-Bus) [ID=80 **DISABLED**]
                    - EL5042_M2K2X_M2K2Y: EL5042 2Ch. BiSS-C Encoder [ID=81]
                    - EL5042_M2K2rX: EL5042 2Ch. BiSS-C Encoder [ID=82]
                    - Term 83 (EL9221-5000): EL9221-5000 Overcurrent protection 24V DC, 1Ch., max. 10A, adjustable [ID=83 SyncUnit="Term 4 (EL9221-5000)"]
                    - EL7041_M2K2X: EL7041-0052 1Ch. Stepper motor output stage (50V, 5A) [ID=85]
                    - EL7041_M2K2Y: EL7041-0052 1Ch. Stepper motor output stage (50V, 5A) [ID=86]
                    - EL7041_M2K2rX: EL7041-0052 1Ch. Stepper motor output stage (50V, 5A) [ID=87]
                    - EL1004_M2K2_STO: EL1004 4Ch. Dig. Input 24V, 3ms [ID=88]
                    - Term 92 (EL9011): EL9011 End Terminal [ID=92]
                - EK1100_MR3K2: EK1100 EtherCAT Coupler (2A E-Bus) [ID=121 **DISABLED**]
                    - EL5042_M3K2X_M3K2Y: EL5042 2Ch. BiSS-C Encoder [ID=122]
                    - EL5042_M3K2rY: EL5042 2Ch. BiSS-C Encoder [ID=123]
                    - Term 124 (EL9221-5000): EL9221-5000 Overcurrent protection 24V DC, 1Ch., max. 10A, adjustable [ID=124 SyncUnit="Term 4 (EL9221-5000)"]
                    - EL7041_M3K2X: EL7041-0052 1Ch. Stepper motor output stage (50V, 5A) [ID=139]
                    - EL7041_M3K2Y: EL7041-0052 1Ch. Stepper motor output stage (50V, 5A) [ID=140]
                    - EL7041_M3K2rY: EL7041-0052 1Ch. Stepper motor output stage (50V, 5A) [ID=141]
                    - Term 142 (EL9410): EL9410 E-Bus Power Supplier  (Diagnostics) [ID=142]
                    - Term 143 (EL3204)_RTDs: EL3204 4Ch. Ana. Input PT100 (RTD) [ID=143]
                    - Term 144 (EL3202-0010)_RTDs: EL3202-0010 2Ch. Ana. Input PT100 (RTD), High Precision [ID=144]
                    - EL3054_M3K2_FWM_PRSM: EL3054 4Ch. Ana. Input 4-20mA [ID=145]
                    - Term 147 (EL9011): EL9011 End Terminal [ID=147]
                - EK1100_MR3K2_BENDER: EK1100 EtherCAT Coupler (2A E-Bus) [ID=146 **DISABLED**]
                    - EL5042_M3K2_BEND_USDS: EL5042 2Ch. BiSS-C Encoder [ID=148]
                    - EL9576_M3K2_BEND_US_PWR: EL9576 Brake chopper terminal [ID=149]
                    - EL7041_M3K2_BEND_US: EL7041 1Ch. Stepper motor output stage (50V, 5A) [ID=150]
                    - EL9576_M3K2_BEND_DS_PWR: EL9576 Brake chopper terminal [ID=151]
                    - EL7041_M3K2_BEND_DS: EL7041 1Ch. Stepper motor output stage (50V, 5A) [ID=152]
                    - EL3202-0010_M3K2US1_M3K2US2: EL3202-0010 2Ch. Ana. Input PT100 (RTD), High Precision [ID=153]
                    - EL3202-0010_M3K2US3_M3K2DS1: EL3202-0010 2Ch. Ana. Input PT100 (RTD), High Precision [ID=154]
                    - EL3202-0010_M3K2DS2_M3K2DS3: EL3202-0010 2Ch. Ana. Input PT100 (RTD), High Precision [ID=155]
                    - Term 156 (EL3054): EL3054 4Ch. Ana. Input 4-20mA [ID=156]
                    - EL1004_M3K2_STO: EL1004 4Ch. Dig. Input 24V, 3ms [ID=157]
                    - Term 158 (EL9512): EL9512 Power supply terminal 12V [ID=158]
                    - EL2024-0010_M3K2_BEND_LED1: EL2024-0010 4Ch. Dig. Output 12V, 2A [ID=159]
                    - EL2024-0010_M3K2_BEND_LED2: EL2024-0010 4Ch. Dig. Output 12V, 2A [ID=160]
                    - Term 163 (EL9011): EL9011 End Terminal [ID=163]
            - Term 322 (EK1122): EK1122 2 port EtherCAT junction [ID=322]
                - EK1100_MR4K2: EK1100 EtherCAT Coupler (2A E-Bus) [ID=93 **DISABLED**]
                    - EL5042_M4K2X_M4K2Y: EL5042 2Ch. BiSS-C Encoder [ID=94]
                    - EL5042_M4K2rX: EL5042 2Ch. BiSS-C Encoder [ID=95]
                    - Term 96 (EL9221-5000): EL9221-5000 Overcurrent protection 24V DC, 1Ch., max. 10A, adjustable [ID=96 SyncUnit="Term 4 (EL9221-5000)"]
                    - EL7041_M4K2X: EL7041-0052 1Ch. Stepper motor output stage (50V, 5A) [ID=97]
                    - EL7041_M4K2Y: EL7041-0052 1Ch. Stepper motor output stage (50V, 5A) [ID=98]
                    - EL7041_M4K2rX: EL7041-0052 1Ch. Stepper motor output stage (50V, 5A) [ID=99]
                    - Term 100 (EL9410): EL9410 E-Bus Power Supplier  (Diagnostics) [ID=100]
                    - Term 102 (EL3204)_RTDs: EL3204 4Ch. Ana. Input PT100 (RTD) [ID=102]
                    - Term 103 (EL3202-0010)_RTDs: EL3202-0010 2Ch. Ana. Input PT100 (RTD), High Precision [ID=103]
                    - EL3054_M4K2_FWM_PRSM: EL3054 4Ch. Ana. Input 4-20mA [ID=104]
                    - Term 105 (EL9011): EL9011 End Terminal [ID=105]
                - EK1100_MR4K2_BENDER: EK1100 EtherCAT Coupler (2A E-Bus) [ID=106 **DISABLED**]
                    - EL5042_M4K2_BEND_USDS: EL5042 2Ch. BiSS-C Encoder [ID=107]
                    - EL9576_M4K2_BEND_US_PWR: EL9576 Brake chopper terminal [ID=108]
                    - EL7041_M4K2_BEND_US: EL7041 1Ch. Stepper motor output stage (50V, 5A) [ID=109]
                    - EL9576_M4K2_BEND_DS_PWR: EL9576 Brake chopper terminal [ID=110]
                    - EL7041_M4K2_BEND_DS: EL7041 1Ch. Stepper motor output stage (50V, 5A) [ID=111]
                    - EL3202-0010_M4K2US1_M4K2US2: EL3202-0010 2Ch. Ana. Input PT100 (RTD), High Precision [ID=112]
                    - EL3202-0010_M4K2US3_M4K2DS1: EL3202-0010 2Ch. Ana. Input PT100 (RTD), High Precision [ID=113]
                    - EL3202-0010_M4K2DS2_M4K2DS3: EL3202-0010 2Ch. Ana. Input PT100 (RTD), High Precision [ID=114]
                    - Term 115 (EL3054): EL3054 4Ch. Ana. Input 4-20mA [ID=115]
                    - EL1004_M4K2_STO: EL1004 4Ch. Dig. Input 24V, 3ms [ID=116]
                    - Term 117 (EL9512): EL9512 Power supply terminal 12V [ID=117]
                    - EL2024-0010_M4K2_BEND_LED1: EL2024-0010 4Ch. Dig. Output 12V, 2A [ID=118]
                    - EL2024-0010_M4K2_BEND_LED2: EL2024-0010 4Ch. Dig. Output 12V, 2A [ID=119]
                    - Term 120 (EL9011): EL9011 End Terminal [ID=120]

Note also the SyncUnit annotation on relevant items. This isn't very obvious from the project files, so it could be a nice addition. We could easily add the ethercat address information as in the tooltip on the original graph, but it isn't so relevant for our purposes.

klauer commented 1 year ago

Excerpt from Sphinx docs:

image

(clipped)

image

(clipped)

Mostly readable, I think

klauer commented 1 year ago

PLC summary now has this information (and is setup for a cron job): https://pcdshub.github.io/plc-summary/ethercat.html#pcdshub-lcls-plc-sxr-satt

klauer commented 1 year ago
  1. Facility-wide summary above works
  2. Per-repository listing also works: https://pcdshub.github.io/lcls-plc-xrt-optics/master/HOMS_XRT_ethercat.html (Maybe should rename it to EtherCAT topology at some point...)