7 #include <unordered_map> 23 namespace soem_interface
33 using PdoSizeMap = std::unordered_map<std::string, PdoSizePair>;
110 bool startup(
const bool sizeCheck =
true);
143 const double retrySleep = 0.001);
176 const double cycleShift);
207 template <
typename Value>
212 const int size =
sizeof(Value);
213 Value value_copy = value;
222 ROS_ERROR_STREAM(
"Slave " << slave <<
": Working counter too low (" << wkc <<
") for writing SDO (ID: 0x" 223 << std::setfill(
'0') << std::setw(4) << std::hex << index <<
", SID 0x" 224 << std::setfill(
'0') << std::setw(2) << std::hex << static_cast<uint16_t>(subindex)
240 template <
typename Value>
245 int size =
sizeof(Value);
254 ROS_ERROR_STREAM(
"Slave " << slave <<
": Working counter too low (" << wkc <<
") for reading SDO (ID: 0x" 255 << std::setfill(
'0') << std::setw(4) << std::hex << index <<
", SID 0x" 256 << std::setfill(
'0') << std::setw(2) << std::hex << static_cast<uint16_t>(subindex)
260 if (size !=
sizeof(Value))
262 ROS_ERROR_STREAM(
"Slave " << slave <<
": Size mismatch (expected " <<
sizeof(Value) <<
" bytes, read " << size
263 <<
" bytes) for reading SDO (ID: 0x" << std::setfill(
'0') << std::setw(4) << std::hex
264 << index <<
", SID 0x" << std::setfill(
'0') << std::setw(2) << std::hex
265 << static_cast<uint16_t>(subindex) <<
").");
289 template <
typename TxPdo>
303 template <
typename RxPdo>
int ecx_SDOread(ecx_contextt *context, uint16 slave, uint16 index, uint8 subindex, boolean CA, int *psize, void *p, int timeout)
bool checkForSdoErrors(const uint16_t slave, const uint16_t index)
const std::string & getName() const
void readTxPdo(const uint16_t slave, TxPdo &txPdo) const
void syncDistributedClock0(const uint16_t slave, const bool activate, const double cycleTime, const double cycleShift)
bool addSlave(const EthercatSlaveBasePtr &slave)
std::pair< uint16_t, uint16_t > PdoSizePair
std::unordered_map< std::string, PdoSizePair > PdoSizeMap
PACKED_BEGIN struct PACKED ec_SMcommtype ec_SMcommtypet
bool isRunning()
Returns if the instance is running.
bool writeFirmware(const uint16_t slave, const std::string &fileName, const uint32_t &password, const int fileSize, char *fileBuffer)
std::shared_ptr< EthercatBusBase > EthercatBusBasePtr
bool startup(const bool sizeCheck=true)
const ros::Time & getUpdateWriteStamp() const
bool sendSdoWrite(const uint16_t slave, const uint16_t index, const uint8_t subindex, const bool completeAccess, const Value value)
ec_PDOdesct ecatPdoDesc_[EC_MAX_MAPT]
PACKED_END struct ec_idxstack ec_idxstackT
std::atomic< int > wkc_
Working counter of the most recent PDO.
int ecx_SDOwrite(ecx_contextt *context, uint16 Slave, uint16 Index, uint8 SubIndex, boolean CA, int psize, void *p, int Timeout)
int writeFile(const uint16_t slave, const std::string &fileName, const uint32_t &password, const int fileSize, char *fileBuffer, int timeout=EC_TIMEOUTSTATE *10)
ec_slavet ecatSlavelist_[EC_MAXSLAVE]
void setState(const uint16_t state, const uint16_t slave=0)
PACKED_END PACKED_BEGIN struct PACKED ec_PDOassign ec_PDOassignt
std::shared_ptr< EthercatSlaveBase > EthercatSlaveBasePtr
std::string getErrorString(ec_errort error)
bool sentProcessData_
Bool indicating whether PDO data has been sent and not read yet.
std::vector< EthercatSlaveBasePtr > slaves_
List of slaves.
bool workingCounterIsOk() const
const ros::Time & getUpdateReadStamp() const
std::atomic< bool > isRunning_
Internal flag to indicate if the instance is running.
ecx_contextt ecatContext_
std::recursive_mutex contextMutex_
bool sendSdoRead(const uint16_t slave, const uint16_t index, const uint8_t subindex, const bool completeAccess, Value &value)
PACKED_END PACKED_BEGIN struct PACKED ec_PDOdesc ec_PDOdesct
int getNumberOfSlaves() const
int getExpectedWorkingCounter(const uint16_t slave=0) const
bool waitForState(const uint16_t state, const uint16_t slave=0, const unsigned int maxRetries=40, const double retrySleep=0.001)
ec_idxstackT ecatIdxStack_
ec_groupt ecatGrouplist_[EC_MAXGROUP]
bool busIsAvailable() const
ros::Time updateReadStamp_
Time of the last successful PDO reading.
ros::Time updateWriteStamp_
Time of the last successful PDO writing.
~EthercatBusBase()=default
Class for managing an ethercat bus containing one or multiple slaves.
PdoSizeMap getHardwarePdoSizes()
void printALStatus(const uint16_t slave=0)
Prints application layer status.
uint8 ecatEsiBuf_[EC_MAXEEPBUF]
uint32 ecatEsiMap_[EC_MAXEEPBITMAP]
#define ROS_ERROR_STREAM(args)
const double ecatConfigRetrySleep_
Time to sleep between the retries.
const unsigned int ecatConfigMaxRetries_
Maximal number of retries to configure the EtherCAT bus.
ec_SMcommtypet ecatSmCommtype_[EC_MAX_MAPT]
std::string name_
Name of the bus.
void writeRxPdo(const uint16_t slave, const RxPdo &rxPdo)
ec_PDOassignt ecatPdoAssign_[EC_MAX_MAPT]
static void printAvailableBusses()