84 for (
unsigned int i = 0; i < 4096; i++) {
131 unsigned int slaveNo = 0;
172 for (
unsigned int i = 0; i < ethercatSlaveInfos.size(); i++) {
173 ethercatSlaveInfos[i].inputs = NULL;
174 ethercatSlaveInfos[i].outputs = NULL;
183 throw std::runtime_error(
"When using the EthercatMaster with thread there is not need to send process data manual.");
192 throw std::runtime_error(
"When using the EthercatMaster with thread there is not need to receive process data manual");
212 throw std::runtime_error(
"A joint trajectory controller is already register for this joint!");
214 throw std::out_of_range(
"Invalid joint number");
218 LOG(
debug) <<
"register joint trajectory controller for joint: " << JointNumber;
227 throw std::out_of_range(
"Invalid joint number");
231 LOG(
debug) <<
"delete joint trajectory controller registration for joint: " << JointNumber;
253 LOG(
warning) <<
"A joint limit monitor is already register for this joint!";
255 throw std::out_of_range(
"Invalid joint number");
259 LOG(
debug) <<
"register a joint limit monitor for joint: " << JointNumber;
267 if (this->
dataTraces[JointNumber - 1] != NULL)
268 throw std::runtime_error(
"A data trace is already register for this joint!");
269 if ((JointNumber - 1) >= this->
dataTraces.size())
270 throw std::out_of_range(
"Invalid joint number");
274 LOG(
debug) <<
"register a data trace for joint: " << JointNumber;
282 if ((JointNumber - 1) >= this->
dataTraces.size())
283 throw std::out_of_range(
"Invalid joint number");
288 LOG(
debug) <<
"removed data trace for joint: " << JointNumber;
302 LOG(
trace) << ec_slavecount <<
" EtherCAT slaves found and configured.";
337 LOG(
warning) <<
"Not all EtherCAT slaves reached safe operational state.";
340 for (
int i = 1; i <= ec_slavecount; i++) {
342 LOG(
info) <<
"Slave " << i <<
" State=" << ec_slave[i].state <<
" StatusCode=" << ec_slave[i].ALstatuscode <<
" : " <<
ec_ALstatuscode2string(ec_slave[i].ALstatuscode);
352 LOG(
trace) <<
"Request operational state for all EtherCAT slaves";
357 ec_send_processdata();
365 LOG(
trace) <<
"Operational state reached for all EtherCAT slaves.";
367 throw std::runtime_error(
"Not all EtherCAT slaves reached operational state.");
372 throw std::runtime_error(
"No EtherCAT slaves found!");
376 throw std::runtime_error(
"No socket connection on " +
ethernetDevice +
"\nExcecute as root");
381 std::string baseJointControllerName =
"TMCM-174";
382 std::string baseJointControllerNameAlternative =
"TMCM-1632";
383 std::string manipulatorJointControllerName =
"TMCM-174";
384 std::string ManipulatorJointControllerNameAlternative =
"TMCM-1610";
385 std::string actualSlaveName;
391 configfile->
readInto(baseJointControllerNameAlternative,
"BaseJointControllerNameAlternative");
392 configfile->
readInto(manipulatorJointControllerName,
"ManipulatorJointControllerName");
393 configfile->
readInto(ManipulatorJointControllerNameAlternative,
"ManipulatorJointControllerNameAlternative");
396 for (
int cnt = 1; cnt <= ec_slavecount; cnt++) {
397 LOG(
trace) <<
"Slave: " << cnt <<
" Name: " << ec_slave[cnt].name <<
" Output size: " << ec_slave[cnt].Obits
398 <<
"bits Input size: " << ec_slave[cnt].Ibits <<
"bits State: " << ec_slave[cnt].state
399 <<
" delay: " << ec_slave[cnt].pdelay;
403 actualSlaveName = ec_slave[cnt].name;
404 if ((actualSlaveName == baseJointControllerName || actualSlaveName == baseJointControllerNameAlternative ||
405 actualSlaveName == manipulatorJointControllerName || actualSlaveName == ManipulatorJointControllerNameAlternative
406 ) && ec_slave[cnt].Obits > 0 && ec_slave[cnt].Ibits > 0) {
426 throw std::runtime_error(
"No EtherCAT slave could be found");
563 boost::posix_time::ptime startTime = boost::posix_time::microsec_clock::local_time();
564 boost::posix_time::time_duration pastTime;
566 boost::posix_time::time_duration realperiode;
573 pastTime = boost::posix_time::microsec_clock::local_time() - startTime;
579 boost::this_thread::sleep(boost::posix_time::microseconds(timeToWait));
583 startTime = boost::posix_time::microsec_clock::local_time();
602 if (ec_send_processdata() == 0) {
603 LOG(
warning) <<
"Sending process data failed";
616 LOG(
error) <<
"Lost EtherCAT connection";
623 LOG(
warning) <<
"there is an error in the soem driver";
626 for (
unsigned int i = 0; i <
nrOfSlaves; i++) {
666 for (
unsigned int i = 0; i <
nrOfSlaves; i++) {
679 for (
unsigned int i = 0; i <
nrOfSlaves; i++) {
693 std::stringstream errorMessageStream;
694 errorMessageStream <<
" ";
695 std::string errorMessage;
696 errorMessage = errorMessageStream.str();
700 LOG(
error) << errorMessage <<
"got over current";
705 LOG(
error) << errorMessage <<
"got under voltage";
710 LOG(
error) << errorMessage <<
"got over voltage";
715 LOG(
error) << errorMessage <<
"got over temperature";
725 LOG(
error) << errorMessage <<
"got hall sensor problem";
780 LOG(
error) << errorMessage <<
"has a timeout";
785 LOG(
error) << errorMessage <<
"exceeded I2t";
boost::mutex jointLimitMonitorVectorMutex
void AutomaticReceiveOn(const bool enableAutomaticReceive)
unsigned int ethercatTimeout
void setMailboxMsgBuffer(const YouBotSlaveMailboxMsg &msgBuffer, const unsigned int jointNumber)
Headerfile for ethercatdc.c.
ec_mbxbuft mailboxBufferReceive
void setMsgBuffer(const YouBotSlaveMsg &msgBuffer, const unsigned int jointNumber)
void updateSensorActorValues()
bool isEtherCATConnectionEstablished()
std::vector< SlaveMessageInput * > ethercatInputBufferVector
Output part from the EtherCat message of the youBot EtherCat slaves.
boost::mutex trajectoryControllerVectorMutex
bool getMailboxMsgBuffer(YouBotSlaveMailboxMsg &mailboxMsg, const unsigned int jointNumber)
std::vector< YouBotSlaveMailboxMsgThreadSafe > mailboxMessages
Reads and writes a configuration file.
std::vector< bool > outstandingMailboxMsgFlag
mailboxInputBuffer stctInput
void deleteJointTrajectoryControllerRegistration(const unsigned int JointNumber)
unsigned int getNumberOfThreadCyclesPerSecond()
unsigned int timeTillNextEthercatUpdate
static std::string configFilepath
void registerJointTrajectoryController(JointTrajectoryController *object, const unsigned int JointNumber)
std::vector< YouBotSlaveMsgThreadSafe > slaveMessages
General typedefs and defines for EtherCAT.
std::vector< JointLimitMonitor * > jointLimitMonitors
Headerfile for ethercatcoe.c.
std::vector< void * > dataTraces
mailboxOutputBuffer stctOutput
std::vector< SlaveMessageOutput * > ethercatOutputBufferVector
void getMsgBuffer(const unsigned int jointNumber, YouBotSlaveMsg &returnMsg)
void deleteDataTraceRegistration(const unsigned int JointNumber)
void initializeEthercat()
establishes the ethercat connection
bool receiveMailboxMessage(YouBotSlaveMailboxMsg &mailboxMsg)
bool receiveProcessData()
EthercatMasterWithThread(const std::string &configFile, const std::string &configFilePath)
bool sendMailboxMessage(const YouBotSlaveMailboxMsg &mailboxMsg)
bool readInto(T &var, const string &key) const
It monitors the joint position and will decelerate and stop the joint if it is close the limits...
Creates a trace of all process data and reads all configuration parameter from one joint...
EtherCAT mailbox message of the youBot slaves (thread safe)
boost::mutex dataTracesMutex
unsigned int mailboxTimeout
void registerDataTrace(void *object, const unsigned int JointNumber)
std::string ethernetDevice
EtherCAT mailbox message of the youBot slaves.
ec_mbxbuft mailboxBufferSend
long int communicationErrors
SlaveMessageInput stctInput
void AutomaticSendOn(const bool enableAutomaticSend)
#define SLEEP_MILLISEC(millisec)
long int maxCommunicationErrors
std::vector< JointTrajectoryController * > trajectoryControllers
Headerfile for ethercatbase.c.
std::vector< YouBotSlaveMsg > automaticReceiveOffBufferVector
void getEthercatDiagnosticInformation(std::vector< ec_slavet > ðercatSlaveInfos)
SlaveMessageOutput stctOutput
Headerfile for ethercatmain.c.
std::vector< ec_slavet > ethercatSlaveInfo
void registerJointLimitMonitor(JointLimitMonitor *object, const unsigned int JointNumber)
EtherCat message of the youBot EtherCat slaves which is thread safe.
static std::string configFileName
Joint Trajectory Controller.
bool isErrorInSoemDriver()
void parseYouBotErrorFlags(const YouBotSlaveMsg &messageBuffer)
std::vector< bool > newInputMailboxMsgFlag
EtherCat message of the youBot EtherCat slaves.
Headerfile for ethercatconfig.c.
std::vector< bool > pendingMailboxMsgsReply
~EthercatMasterWithThread()
bool ethercatConnectionEstablished
boost::thread_group threads
bool closeEthercat()
closes the ethercat connection
std::vector< YouBotSlaveMsg > automaticSendOffBufferVector
unsigned int getNumberOfSlaves() const
return the quantity of ethercat slave which have an input/output buffer
Headerfile for ethercatprint.c.
char * ec_ALstatuscode2string(uint16 ALstatuscode)