Unterschiede

Hier werden die Unterschiede zwischen zwei Versionen angezeigt.

Link zu dieser Vergleichsansicht

embedded_systems:ethercat:ethercatinterface:writing_new_ethercatinterface [2019-04-16 10:50] (aktuell)
mgehrig2 angelegt
Zeile 1: Zeile 1:
 +====== Writing a new interface for a new EtherCAT slave ======
 +===== Hints =====
  
 +  * You can use ''​EtherCatInterfaceElmo''​ as an example.
 +  * Your interface has to inherit from ''​EtherCATInterfaceBase''​.
 +  * The most basic implementation only includes the low level functions ('​ll_'​-prefix)
 +  * A method like ''​int64_t getPosition()''​ is recommended to avoid overflow problems (see below)
 +
 +
 +===== int64_t getPosition() =====
 +The position is often sent as a 32 bit signed integer (~4*e+9 different values).
 +With a high-resolution encoder, this value can easily overflow.
 +
 +To avoid this problem use a method implementation like this:
 +<​code>​
 +int64_t EtherCATInterfaceElmo::​getPosition(int driveNumber)
 +{
 + int32_t rawPos = ll_getPositionActualValue(driveNumber);​
 + int32_t diff = rawPos - drives[driveNumber].prevRawPos;​
 + drives[driveNumber].prevRawPos = rawPos;
 + drives[driveNumber].absPos += static_cast<​int64_t>​(diff);​
 + ​ return drives[driveNumber].absPos + static_cast<​int64_t>​(drives[driveNumber].posOffset);​
 +}
 +</​code>​