ANYdrive SDK
The SDK for interfacing ANYdrive.
anydrive_ethercat::AnydriveEthercatBus Class Reference

#include <AnydriveEthercatBus.hpp>

Public Member Functions

 AnydriveEthercatBus (const std::string &name)
 
 ~AnydriveEthercatBus ()=default
 
const std::string & getName () const
 
const any_measurements::Time & getUpdateReadStamp () const
 
const any_measurements::Time & getUpdateWriteStamp () const
 
bool busIsAvailable () const
 
int getNumberOfSlaves () const
 
bool addSlave (const AnydriveEthercatSlavePtr &slave)
 
bool startup ()
 
void updateRead ()
 
void updateWrite ()
 
void shutdown ()
 
void setState (const uint16_t state, const uint16_t slave=0)
 
bool waitForState (const uint16_t state, const uint16_t slave=0, const unsigned int maxRetries=40, const double retrySleep=0.001)
 
std::string getErrorString (ec_errort error)
 
bool checkForSdoErrors (const uint16_t slave, const uint16_t index)
 
template<typename Value >
bool sendSdoWrite (const uint16_t slave, const uint16_t index, const uint8_t subindex, const bool completeAccess, const Value value)
 
template<typename Value >
bool sendSdoRead (const uint16_t slave, const uint16_t index, const uint8_t subindex, const bool completeAccess, Value &value)
 
int getExpectedWorkingCounter (const uint16_t slave=0) const
 
bool workingCounterIsOk () const
 
template<typename TxPdo >
void readTxPdo (const uint16_t slave, TxPdo &txPdo) const
 
template<typename RxPdo >
void writeRxPdo (const uint16_t slave, const RxPdo &rxPdo)
 

Static Public Member Functions

static bool BusIsAvailable (const std::string &name)
 
static void PrintAvailableBusses ()
 

Protected Attributes

std::string name_
 Name of the bus. More...
 
std::vector< anydrive_ethercat::AnydriveEthercatSlavePtrslaves_
 List of slaves. More...
 
bool sentProcessData_ = false
 Bool indicating whether PDO data has been sent and not read yet. More...
 
std::atomic< int > wkc_
 Working counter of the most recent PDO. More...
 
any_measurements::Time updateReadStamp_
 Time of the last successful PDO reading. More...
 
any_measurements::Time updateWriteStamp_
 Time of the last successful PDO writing. More...
 
const unsigned int ecatConfigMaxRetries_ = 5
 Maximal number of retries to configure the EtherCAT bus. More...
 
const double ecatConfigRetrySleep_ = 1.0
 Time to sleep between the retries. More...
 
char ioMap_ [4096]
 
ecx_portt ecatPort_
 
ec_slavet ecatSlavelist_ [EC_MAXSLAVE]
 
int ecatSlavecount_ = 0
 
ec_groupt ecatGrouplist_ [EC_MAXGROUP]
 
uint8 ecatEsiBuf_ [EC_MAXEEPBUF]
 
uint32 ecatEsiMap_ [EC_MAXEEPBITMAP]
 
ec_eringt ecatEList_
 
ec_idxstackT ecatIdxStack_
 
boolean ecatError_ = FALSE
 
int64 ecatDcTime_ = 0
 
ec_SMcommtypet ecatSmCommtype_ [EC_MAX_MAPT]
 
ec_PDOassignt ecatPdoAssign_ [EC_MAX_MAPT]
 
ec_PDOdesct ecatPdoDesc_ [EC_MAX_MAPT]
 
ec_eepromSMt ecatSm_
 
ec_eepromFMMUt ecatFmmu_
 
ecx_contextt ecatContext_
 

Constructor & Destructor Documentation

◆ AnydriveEthercatBus()

anydrive_ethercat::AnydriveEthercatBus::AnydriveEthercatBus ( const std::string &  name)

Constructor.

Parameters
nameName of the bus, e.g. "eth0".

◆ ~AnydriveEthercatBus()

anydrive_ethercat::AnydriveEthercatBus::~AnydriveEthercatBus ( )
default

Destructor.

Member Function Documentation

◆ addSlave()

bool anydrive_ethercat::AnydriveEthercatBus::addSlave ( const AnydriveEthercatSlavePtr slave)

Add an ANYdrive EtherCAT slave. ANYdrive EtherCAT slave.

Returns
True if successful.

◆ BusIsAvailable()

bool anydrive_ethercat::AnydriveEthercatBus::BusIsAvailable ( const std::string &  name)
static

Check if a bus is available.

Parameters
nameName of the bus.
Returns
True if available.

◆ busIsAvailable()

bool anydrive_ethercat::AnydriveEthercatBus::busIsAvailable ( ) const

Check if this bus is available.

Returns
True if available.

◆ checkForSdoErrors()

bool anydrive_ethercat::AnydriveEthercatBus::checkForSdoErrors ( const uint16_t  slave,
const uint16_t  index 
)

Check if an error for the SDO index of the slave exists.

Parameters
slaveAddress of the slave.
indexIndex of the SDO.
Returns
True if an error for the index exists.

◆ getErrorString()

std::string anydrive_ethercat::AnydriveEthercatBus::getErrorString ( ec_errort  error)

Generate and return the error string.

Parameters
errorEtherCAT error object.
Returns
The error string.

◆ getExpectedWorkingCounter()

int anydrive_ethercat::AnydriveEthercatBus::getExpectedWorkingCounter ( const uint16_t  slave = 0) const

Get the PDO expected working counter.

Parameters
slaveAddress of the slave, 0 for all slaves.
Returns
Expected working counter.

◆ getName()

const std::string & anydrive_ethercat::AnydriveEthercatBus::getName ( ) const

Get the name of the bus.

Returns
Name of the bus.

◆ getNumberOfSlaves()

int anydrive_ethercat::AnydriveEthercatBus::getNumberOfSlaves ( ) const

Get the number of slaves which were detected on this bus.

Returns
Number of slaves.

◆ getUpdateReadStamp()

const any_measurements::Time & anydrive_ethercat::AnydriveEthercatBus::getUpdateReadStamp ( ) const

Get the time of the last successful PDO reading.

Returns
Stamp.

◆ getUpdateWriteStamp()

const any_measurements::Time & anydrive_ethercat::AnydriveEthercatBus::getUpdateWriteStamp ( ) const

Get the time of the last successful PDO writing.

Returns
Stamp.

◆ PrintAvailableBusses()

void anydrive_ethercat::AnydriveEthercatBus::PrintAvailableBusses ( )
static

Print all available busses.

◆ readTxPdo()

template<typename TxPdo >
void anydrive_ethercat::AnydriveEthercatBus::readTxPdo ( const uint16_t  slave,
TxPdo &  txPdo 
) const
inline

Read a TxPDO from the buffer.

Parameters
slaveAddress of the slave.
txPdoReturn argument, TxPDO container.

◆ sendSdoRead()

template<typename Value >
bool anydrive_ethercat::AnydriveEthercatBus::sendSdoRead ( const uint16_t  slave,
const uint16_t  index,
const uint8_t  subindex,
const bool  completeAccess,
Value &  value 
)
inline

Send a reading SDO.

Parameters
slaveAddress of the slave.
indexIndex of the SDO.
subindexSub-index of the SDO.
completeAccessAccess all sub-indices at once.
valueReturn argument, will contain the value which was read.
Returns
True if successful.

◆ sendSdoWrite()

template<typename Value >
bool anydrive_ethercat::AnydriveEthercatBus::sendSdoWrite ( const uint16_t  slave,
const uint16_t  index,
const uint8_t  subindex,
const bool  completeAccess,
const Value  value 
)
inline

Send a writing SDO.

Parameters
slaveAddress of the slave.
indexIndex of the SDO.
subindexSub-index of the SDO.
completeAccessAccess all sub-indices at once.
valueValue to write.
Returns
True if successful.

◆ setState()

void anydrive_ethercat::AnydriveEthercatBus::setState ( const uint16_t  state,
const uint16_t  slave = 0 
)

Set the desired EtherCAT state machine state.

Parameters
stateDesired state.
slaveAddress of the slave, 0 for all slaves.

◆ shutdown()

void anydrive_ethercat::AnydriveEthercatBus::shutdown ( )

Shutdown the bus communication.

◆ startup()

bool anydrive_ethercat::AnydriveEthercatBus::startup ( )

Startup the bus communication.

Returns
True if successful.

◆ updateRead()

void anydrive_ethercat::AnydriveEthercatBus::updateRead ( )

Update step 1: Read all PDOs.

Receive the EtherCAT data.

Check the working counter.

Each slave attached to this bus reads its data to the buffer.

◆ updateWrite()

void anydrive_ethercat::AnydriveEthercatBus::updateWrite ( )

Update step 2: Write all PDOs.

Each slave attached to this bus write its data to the buffer.

Send the EtherCAT data.

◆ waitForState()

bool anydrive_ethercat::AnydriveEthercatBus::waitForState ( const uint16_t  state,
const uint16_t  slave = 0,
const unsigned int  maxRetries = 40,
const double  retrySleep = 0.001 
)

Wait for an EtherCAT state machine state to be reached.

Parameters
stateDesired state.
slaveAddress of the slave, 0 for all slaves.
maxRetriesMaximum number of retries.
retrySleepDuration to sleep between the retries.
Returns
True if the state has been reached within the timeout.

◆ workingCounterIsOk()

bool anydrive_ethercat::AnydriveEthercatBus::workingCounterIsOk ( ) const

Check if the current working counter for all slaves is high enough.

Returns
True if the working counter is equal or higher than expected.

◆ writeRxPdo()

template<typename RxPdo >
void anydrive_ethercat::AnydriveEthercatBus::writeRxPdo ( const uint16_t  slave,
const RxPdo rxPdo 
)
inline

Write an RxPDO to the buffer.

Parameters
slaveAddress of the slave.
txPdoRxPDO container.

Member Data Documentation

◆ ecatConfigMaxRetries_

const unsigned int anydrive_ethercat::AnydriveEthercatBus::ecatConfigMaxRetries_ = 5
protected

Maximal number of retries to configure the EtherCAT bus.

◆ ecatConfigRetrySleep_

const double anydrive_ethercat::AnydriveEthercatBus::ecatConfigRetrySleep_ = 1.0
protected

Time to sleep between the retries.

◆ ecatContext_

ecx_contextt anydrive_ethercat::AnydriveEthercatBus::ecatContext_
protected
Initial value:

◆ ecatDcTime_

int64 anydrive_ethercat::AnydriveEthercatBus::ecatDcTime_ = 0
protected

◆ ecatEList_

ec_eringt anydrive_ethercat::AnydriveEthercatBus::ecatEList_
protected

◆ ecatError_

boolean anydrive_ethercat::AnydriveEthercatBus::ecatError_ = FALSE
protected

◆ ecatEsiBuf_

uint8 anydrive_ethercat::AnydriveEthercatBus::ecatEsiBuf_[EC_MAXEEPBUF]
protected

◆ ecatEsiMap_

uint32 anydrive_ethercat::AnydriveEthercatBus::ecatEsiMap_[EC_MAXEEPBITMAP]
protected

◆ ecatFmmu_

ec_eepromFMMUt anydrive_ethercat::AnydriveEthercatBus::ecatFmmu_
protected

◆ ecatGrouplist_

ec_groupt anydrive_ethercat::AnydriveEthercatBus::ecatGrouplist_[EC_MAXGROUP]
protected

◆ ecatIdxStack_

ec_idxstackT anydrive_ethercat::AnydriveEthercatBus::ecatIdxStack_
protected

◆ ecatPdoAssign_

ec_PDOassignt anydrive_ethercat::AnydriveEthercatBus::ecatPdoAssign_[EC_MAX_MAPT]
protected

◆ ecatPdoDesc_

ec_PDOdesct anydrive_ethercat::AnydriveEthercatBus::ecatPdoDesc_[EC_MAX_MAPT]
protected

◆ ecatPort_

ecx_portt anydrive_ethercat::AnydriveEthercatBus::ecatPort_
protected

◆ ecatSlavecount_

int anydrive_ethercat::AnydriveEthercatBus::ecatSlavecount_ = 0
protected

◆ ecatSlavelist_

ec_slavet anydrive_ethercat::AnydriveEthercatBus::ecatSlavelist_[EC_MAXSLAVE]
protected

◆ ecatSm_

ec_eepromSMt anydrive_ethercat::AnydriveEthercatBus::ecatSm_
protected

◆ ecatSmCommtype_

ec_SMcommtypet anydrive_ethercat::AnydriveEthercatBus::ecatSmCommtype_[EC_MAX_MAPT]
protected

◆ ioMap_

char anydrive_ethercat::AnydriveEthercatBus::ioMap_[4096]
protected

◆ name_

std::string anydrive_ethercat::AnydriveEthercatBus::name_
protected

Name of the bus.

◆ sentProcessData_

bool anydrive_ethercat::AnydriveEthercatBus::sentProcessData_ = false
protected

Bool indicating whether PDO data has been sent and not read yet.

◆ slaves_

std::vector<anydrive_ethercat::AnydriveEthercatSlavePtr> anydrive_ethercat::AnydriveEthercatBus::slaves_
protected

List of slaves.

◆ updateReadStamp_

any_measurements::Time anydrive_ethercat::AnydriveEthercatBus::updateReadStamp_
protected

Time of the last successful PDO reading.

◆ updateWriteStamp_

any_measurements::Time anydrive_ethercat::AnydriveEthercatBus::updateWriteStamp_
protected

Time of the last successful PDO writing.

◆ wkc_

std::atomic<int> anydrive_ethercat::AnydriveEthercatBus::wkc_
protected

Working counter of the most recent PDO.


The documentation for this class was generated from the following files: