| Beide Seiten der vorigen RevisionVorhergehende ÜberarbeitungNächste Überarbeitung | Vorhergehende Überarbeitung |
| embedded_systems:ethercat:ecmasterlib [2021-09-30 16:14] – Urs Graf | embedded_systems:ethercat:ecmasterlib [2021-11-22 15:34] (aktuell) – Urs Graf |
|---|
| ===== Overview ===== | ===== Overview ===== |
| |
| The //"ecmasterlib"// offer an easy way to use EtherCAT with [[http://eeros.org/|EEROS]] or in a standalone project. | The //"ecmasterlib"// offers an easy way to use EtherCAT with [[http://eeros.org/|EEROS]] or in a standalone project. |
| |
| * **EEROS**: The robotic framework | |
| * **EtherCAT stack**: The EtherCAT stack from Acontis, see [[embedded_systems:ethercat:understanding_acontis|The Acontis EtherCAT Stack]]. | * **EtherCAT stack**: The EtherCAT stack from Acontis, see [[embedded_systems:ethercat:understanding_acontis|The Acontis EtherCAT Stack]]. |
| * **ecmasterlib**: This library provides an easy interface to the EtherCAT stack. The library initializes the stack and takes over the periodic sending and receiving of the bus data. It provides the following basic interface: **[[embedded_systems:ethercat:ethercatinterface:EtherCATInterfaceBase]]** | * **ecmasterlib**: This library provides an easy interface to the EtherCAT stack. The library initializes the stack and takes over the periodic sending and receiving of the data on the bus. It provides the following basic interfaces |
| * **EtherCATInterfaceElmo**: An interface based on //EtherCATInterfaceBase// designed for Elmo drives. See **[[embedded_systems:ethercat:ethercatinterface:EtherCATInterfaceElmo]]** for details. You may need to implement your own interface for different drives. the interface further includes to EEROS blocks for the control system: | * **Elmo.hpp**: An interface for Elmo drives |
| * **getDrivesBlock**: It has a signal output for every PDO input value (i.e. encoder values). You may need to modify this block in your application. | * **Beckhoff/EL1008.hpp**: An interface for digital input terminal |
| * **setDrivesBlock**: It has a signal input for every PDO output value (i.e. setTorque). You may need to modify this block in your application. | * **Beckhoff/EL2008.hpp**: An interface for digital output terminal |
| | * **Beckhoff/EL3004.hpp**: An interface for analog input terminal |
| | * **Beckhoff/EL4004.hpp**: An interface for analog output terminal |
| | |
| | You may need to implement your own interfaces for other drives and terminals. |
| |
| ===== Installation ===== | ===== Installation ===== |
| |
| ===== Functionality ===== | ===== Functionality ===== |
| The //"ecmasterlib"// provides a callback function (''void callbackFct(...)'') which is called by the Acontis stack once per EtherCAT cycle. | The examples show how to use the interfaces, e.g. |
| This method: | <code cpp> |
| * Copies the received data from the stack into the receive buffer of //"ecmasterlib"// | ecmasterlib::device::beckhoff::EL1008 inputs{}; |
| * Copies the data to be sent from the send buffer of //"ecmasterlib"// to the stack. | auto &stack = ecmasterlib::EcMasterlibMain::createInstance(argc, argv, inputs); |
| |
| The receive and send buffers of //"ecmasterlib"// are byte arrays (''uint8_t* inBuffer; uint8_t* outBuffer;'') which are the same size as the PDOs. | std::cout << inputs[0] << std::endl; // reads first digital input channel |
| | </code> |
| The //"ecmasterlib"// also provides a condition variable (''std::condition_variable cv;'') to synchronize the user application (i.e. EEROS). | You create an interface instance which must be passed to the EtherCAT stack. See the examples within [[https://gitlab.ost.ch/tech/inf/public/ecmasterlib|ecmasterlib]]. Elmo drives could be used as follows |
| | <code cpp> |
| When an //"ecmasterlib"// object is created, an instance (monotonic) is created. | ecmasterlib::device::Elmo drive{}; |
| The stack is started in the same way as in the //"EcMasterDemoDC"// of Acontis. | auto &stack = ecmasterlib::EcMasterlibMain::createInstance(argc, argv, drive); |
| | sleep(10); |
| | std::cout << "init start\n"; |
| | drive.init([&stack]() { stack.sync(); }); |
| ===== Adaptions ===== | drive.setMode(ecmasterlib::device::Elmo::Mode::PROFILE_VELOCITY); |
| ==== Overview ==== | drive.setTargetVelocity(1000); |
| The components //EtherCATInterfaceElmo_config//, //getDrivesBlock// and //setDrivesBlock// need to be adjusted whenever you change the variables, which are transmitted via PDOs (periodic sent/received messages by the EtherCAT bus). | drive.setMaximumTorque(300); |
| These components must also be adapted when creating a new EEROS application. | |
| | |
| ==== Steps ==== | |
| - Study produced ENI file carefully (use XML viewer). Under <config><processimage><inputs> and <outputs> you find bitsize and offset of all transmitted values. | |
| - Adjust headerfile accordingly, negative offset values indicate that the entry is not going to be used. | |
| - Make necessary adaptions in //getDrivesBlock// and //setDrivesBlock//. | |
| |
| | std::cout << "loop start\n"; |
| | while(stack.isRunning()) { |
| | std::cout << "Current Position: " << drive.getPosition() << '\n'; |
| | sleep(1); |
| | } |
| | </code> |
| |
| | See [[embedded_systems:ethercat:teststand#run_test_program|EtherCat Teststand]] |
| | ===== Modifications ===== |
| | If you switch to other drives or terminals or if you want to transmit a different set of PDOs, you have to undertake the following steps |
| | - Create or modify ENI-Files |
| | - Create or modify interface files accordingly |
| |