/* slave information interface */ void init_sii(ecat_slave *esv) { int pdoe_idx = 0; memset(&esv->categories,0,sizeof(struct __sii_categories__)); init_si_info(&esv->categories.sii); init_strings(&esv->categories.strings, &esv->categories.strings_hdr); init_fmmu(&esv->categories.fmmu, &esv->categories.fmmu_hdr); init_syncm(esv, &esv->categories.syncm0, 0 ,&esv->categories.syncm_hdr0); init_syncm(esv, &esv->categories.syncm1, 1 ,&esv->categories.syncm_hdr1); init_general(esv, &esv->categories.general, &esv->categories.general_hdr); init_end_hdr(&esv->categories.endhdr); // pdos esv->categories.rxpdo_hdr.type = CAT_TYPE_RXPDO; esv->categories.rxpdo_hdr.size = sizeof(esv->categories.rxpdo)/2; esv->categories.rxpdo.entries = 2; esv->categories.rxpdo.flags = 0; esv->categories.rxpdo.name_idx = RXPDO_CAT_NAME_IDX + 1; esv->categories.rxpdo.synchronization = 0; esv->categories.rxpdo.syncm = 0; esv->categories.rxpdo.pdo_index = 0x1600; init_pdo(&esv->categories.rxpdo.pdo[0], 0x1600, 0X02, RX_PDO1_NAME_IDX + 1, 0, 8, 0); esv->pdoe_sizes[pdoe_idx++] = 8; init_pdo(&esv->categories.rxpdo.pdo[1], 0x1600, 0X01, RX_PDO2_NAME_IDX + 1, 0, 32, 0); esv->pdoe_sizes[pdoe_idx++] = 32; esv->categories.txpdo_hdr.type = CAT_TYPE_TXPDO; esv->categories.txpdo.entries = 2; esv->categories.txpdo.flags = 0; esv->categories.txpdo.name_idx = TXPDO_CAT_NAME_IDX +1; esv->categories.txpdo.synchronization = 0; esv->categories.txpdo.syncm = 1; esv->categories.txpdo.pdo_index = 0x1a00; esv->categories.txpdo_hdr.size = sizeof(esv->categories.txpdo)/2; init_pdo(&esv->categories.txpdo.pdo[0], 0x1a00, 0X02, TX_PDO1_NAME_IDX + 1, 0, 32, 0); esv->pdoe_sizes[pdoe_idx++] = 32; init_pdo(&esv->categories.txpdo.pdo[1], 0x1a00, 0X01, TX_PDO2_NAME_IDX + 1, 0, 16, 0); esv->pdoe_sizes[pdoe_idx++] = 16; }
bool Device::init(std::string deviceFile) { if(canopen::atFirstInit) { canopen::atFirstInit = false; if(std::find(canopen::openDeviceFiles.begin(), canopen::openDeviceFiles.end(), deviceFile) == canopen::openDeviceFiles.end()) { CAN_Close(canopen::h); if (!canopen::openConnection(deviceFile, canopen::baudRate)) // check if connection was successful { ROS_ERROR_STREAM("Cannot open CAN device " << deviceFile << "... aborting."); exit(EXIT_FAILURE); } canopen::initListenerThread(canopen::defaultListener); canopen::openDeviceFiles.push_back(deviceFile); } sendNMT(NMT_RESET_COMMUNICATION, true); } ros::Time start = ros::Time::now(); while(!nmt_init) { if((ros::Time::now() - start).toSec() > 5.0) { ROS_ERROR_STREAM("Node: " << (int)CANid_ << " is not ready for operation. Please check for potential problems."); return false; } ros::Duration(0.01).sleep(); } // Configure PDO channels ROS_DEBUG_STREAM("mapping PDOs of device " << name); init_pdo(); ros::Duration(0.01).sleep(); sendNMT(NMT_START_REMOTE_NODE); // std::cout << std::hex << "Initialized the PDO mapping for Node: " << (int)CANid << std::endl; initialized = true; set_objects(); return true; }