Package: libecm
libecm is a library for EtherCAT master ( NEXTW ECM-SK and NEXTW ECM-XF
)Installation# pip3 install libecmor# python3 setup.py build
# python3 setup.py installAfter installation you can run unit tests to make sure that the library
works fine. Execute# python3 -m libecm.test.test_csp           # For ECM-SK
# python3 -m libecm.test.test_ecmxf_elmo    # For ECM-XF elmo 8 servoUsageIn Python 3 ( ECM-SK 12bits )fromlibecmimportsk12asethercatfromlibecm.sk12importWO,WRfromlibecm.sk12importDRIVE,IOfromlibecm.sk12importFREERUN,DCSYNCfromlibecm.sk12importMODE_CSP,MODE_CSV,MODE_CSTfromlibecm.sk12importMAX_SLAVES,MAX_CHANNELS,MAX_BYTESfromlibecm.sk12importSTATE_INIT,STATE_PRE_OP,STATE_SAFE_OP,STATE_OPIn Python 3 ( ECM-SK 16bits )fromlibecmimportsk16asethercatfromlibecm.sk16importWO,WRfromlibecm.sk16importDRIVE,IOfromlibecm.sk16importFREERUN,DCSYNCfromlibecm.sk16importMODE_CSP,MODE_CSV,MODE_CSTfromlibecm.sk16importMAX_SLAVES,MAX_CHANNELS,MAX_BYTESfromlibecm.sk16importSTATE_INIT,STATE_PRE_OP,STATE_SAFE_OP,STATE_OPIn Python 3( ECM-XF )fromlibecm.ecmxfimportecmxf_libraryfromlibecm.ecmxfimportDATA_DEFAULT_SIZEfromlibecm.ecmxfimportMODE_CSP,MODE_CSV,MODE_CSTfromlibecm.ecmxfimportSTATE_INIT,STATE_PRE_OP,STATE_SAFE_OP,STATE_OP# ELMO SERVOfromlibecm.servo.elmo_gold_pdo_mappingimportget_rx_pdo_mappingfromlibecm.servo.elmo_gold_pdo_mappingimportget_tx_pdo_mapping# UNIVERSAL SERVOfromlibecm.servo.universal_pdo_mappingimportget_rx_pdo_mappingfromlibecm.servo.universal_pdo_mappingimportget_tx_pdo_mappingECM-SK ExampleOpen EtherCATethercat.open()EtherCAT initial.ethercat.set_state(STATE_PRE_OP)# Set EtherCAT stateethercat.axis(group=0,topology=[DRIVE]*8)# Return number of slaves.ethercat.set_dc(1000)# Cycle Time Unit : usethercat.set_mode(slaves=[1],modes=[MODE_CSP]*1,types=[DCSYNC]*1)time.sleep(1)ethercat.set_state(STATE_SAFE_OP)time.sleep(1)ethercat.set_state(STATE_OP)Servo ONethercat.servo_on(slaves=[1])CSP, CSV, CST Modeethercat.csp(slaves=[1],values=[int(position)],rw=WR)ethercat.csv(slaves=[1],values=[int(velocity)],rw=WR)ethercat.cst(slaves=[1],values=[int(torque)],rw=WR)ethercat.mixing([dict(slaves=1,modes=MODE_CSV,values=0x55555555),dict(slaves=2,modes=MODE_CSP,values=0xAAAAAAAA)])Close EtherCATresult=ethercat.servo_off(slaves=[1])# Return list    """ [ { 'index':0, 'status':0, 'position':0, 'torque':0 }, ]    """ethercat.set_state(STATE_INIT)ethercat.close()Other Functionsethercat.get_status()ethercat.sdo(1,0x607A,0,size=4,alias='Target Position').value# Read SDOethercat.sdo(1,0x60C2,1,size=1,alias='Interpolation').value=125# Write SDOethercat.clear_alarm(slaves=[1,2,3,4,5,6,7,8])ethercat.go_home([1,2,3,4,5,6,7,8])ethercat.abort_home([1,2,3,4,5,6,7,8])ethercat.set_ex(0,0)# Param1 Disable(Enable) Command CRC Verification# Param2 Disable(Enable) Response CRC Verificationethercat.read_dio(slaves=[1,2,3,4,5,6,7,8])ethercat.write_dio(slaves=[1,2,3,4,5,6,7,8],values=[0x55,0x66,0x77,8,9,10,11,12])ethercat.reset()# Module hardware resetethercat.reboot()# Module software resetethercat.ric_io()# Read ECM IC DIOethercat.wic_io(0x55555555)# Write ECM IC DIOECM-XF ExampleOpen EtherCATfromlibecm.servo.universal_pdo_mappingimportget_rx_pdo_mappingfromlibecm.servo.universal_pdo_mappingimportget_tx_pdo_mappingCOUNT=1SLAVES=[iforiinrange(0,COUNT)]MODES=[MODE_CSV]RX_PDO_MAPPING=get_rx_pdo_mapping(MODES)TX_PDO_MAPPING=get_rx_pdo_mapping(MODES)ethercat=ecmxf_library(SLAVES,RX_PDO_MAPPING,TX_PDO_MAPPING)ethercat.open(dev='/dev/spidev0.0')EtherCAT initialethercat.set_dc(5000000)# nsethercat.firmware()# Get ECMXF firmware versionethercat.axis()# Get slave countethercat.set_state(STATE_PRE_OP)ethercat.reconfig(slaves=SLAVES,rx_mapping=RX_PDO_MAPPING,tx_mapping=TX_PDO_MAPPING)ethercat.set_mode(slaves=SLAVES,modes=MODES)ethercat.set_state(STATE_SAFE_OP)forslaveinSLAVES:ethercat.align_position(slave=slave,homing=True,position=0)ethercat.set_state(STATE_OP)Servo ONethercat.servo_on(slaves=SLAVES)CSP, CSV, CST Modeethercat.mixing(slaves=SLAVES,values=[0]*COUNT,syntax=False)# Not monitor FIFOethercat.mixing(slaves=SLAVES,values=[0]*COUNT,syntax=True)# monitor FIFO# Get ECMXF feedback valuesethercat.feedback(slaves=SLAVES)Close EtherCATethercat.servo_off(slaves=SLAVES)ethercat.close()Other Functionsfromlibecm.ecmxfimportsdoethercat.sdo(1,0x607A,0,size=4,alias='Target Position').value# Read SDOethercat.sdo(1,0x60C2,1,size=1,alias='Interpolation').value=125# Write SDOethercat.reset()# Module hardware resetethercat.reboot()# Module software resetethercat.show_pdo(slaves=SLAVES,index=0x1C12)ethercat.show_pdo(slaves=SLAVES,index=0x1C13)ethercat.show_pdo_size()V1.2 (2021-05-31 dev)New add hardware reset function ( For Raspberry Pi 4B, RESET PIN =
WIRINGPI CODE 3 ).Optimized class hexinSigmoidFixed some bugs.V1.1 (2021-05-13)New add ECMXF library.V0.6 (2020-09-28)Optimized code.