7 #include <boost/ref.hpp> 8 #include <boost/interprocess/sync/scoped_lock.hpp> 11 #include <soem/nicdrv.h> 24 static const unsigned THREAD_SLEEP_TIME = 10000;
34 if ((
ec_slave[slave].group == 0) && (
ec_slave[slave].state != EC_STATE_OPERATIONAL))
37 if (
ec_slave[slave].state == (EC_STATE_SAFE_OP + EC_STATE_ERROR))
39 ROS_ERROR(
"ERROR : slave %d is in SAFE_OP + ERROR, attempting ack.\n", slave);
43 else if(
ec_slave[slave].state == EC_STATE_SAFE_OP)
45 ROS_WARN(
"WARNING : slave %d is in SAFE_OP, change to OPERATIONAL.\n", slave);
54 ROS_INFO(
"MESSAGE : slave %d reconfigured\n",slave);
64 ROS_ERROR(
"ERROR : slave %d lost\n",slave);
75 ROS_INFO(
"MESSAGE : slave %d recovered\n",slave);
81 ROS_INFO(
"MESSAGE : slave %d found\n",slave);
87 void cycleWorker(boost::mutex& mutex,
bool& stop_flag)
94 boost::mutex::scoped_lock lock(mutex);
99 if (wkc < expected_wkc)
104 usleep(THREAD_SLEEP_TIME);
157 const static unsigned MAX_BUFF_SIZE = 1024;
158 char buffer[MAX_BUFF_SIZE];
159 size_t name_size =
ifname_.size();
160 if (name_size >
sizeof(buffer) - 1)
162 ROS_ERROR(
"Ifname %s exceeds maximum size of %u bytes", ifname.c_str(), MAX_BUFF_SIZE);
165 std::strncpy(buffer,
ifname_.c_str(), MAX_BUFF_SIZE);
167 ROS_INFO(
"Initializing etherCAT master");
171 ROS_ERROR(
"Could not initialize ethercat driver");
182 ROS_INFO(
"SOEM found and configured %d slaves",
ec_slavecount);
188 ROS_INFO(
"SOEM IOMap size: %d", iomap_size);
196 ROS_ERROR(
"Could not set EC_STATE_SAFE_OP");
224 ROS_INFO(
"Finished configuration successfully");
boost::mutex iomap_mutex_
int ec_reconfig_slave(uint16 slave, int timeout)
bool initSoem(const std::string &ifname)
const std::string ifname_
EtherCAT exception. Currently this is only thrown in the event of a failure to construct an EtherCat ...
int ec_send_processdata(void)
int ec_recover_slave(uint16 slave, int timeout)
int ec_receive_processdata(int timeout)
int ec_init(const char *ifname)
EtherCatManager(const std::string &ifname)
Constructs and initializes the ethercat slaves on a given network interface.
int ec_config_map(void *pIOmap)
uint8_t readOutput(int slave_no, uint8_t channel) const
Reads the "channel-th" output-register of the given slave no.
boost::scoped_array< uint8_t > iomap_
int ec_writestate(uint16 slave)
void write(int slave_no, uint8_t channel, uint8_t value)
writes 'value' to the 'channel-th' output-register of the given 'slave'
boolean ec_configdc(void)
uint8_t readInput(int slave_no, uint8_t channel) const
Reads the "channel-th" input-register of the given slave no.
boost::thread cycle_thread_
#define ROS_ERROR_STREAM(args)
uint16 ec_statecheck(uint16 slave, uint16 reqstate, int timeout)
int ec_config_init(uint8 usetable)