ecrt_master_activate function does not work

53 views Asked by At

I'm trying to migrate my robot program based on ethercat system to another computer. I installed rt kernel, xenomai and ethercat master build by etherlab. I connected all the motor drivers with network cables. And I started my communication program. It started and work for a few steps. Initiating master and scan slaves were worked But when it try to activate master it was waiting for something infinitely. I tried to stop it by using ctrl+c and kill commands. But it didn't stop.

And I checked what the program is doing by htop and it said that the process is waiting for disk I/O.

PID   USER   PRI   NI   VIRT   RES   SHR   S   CPU%   MEM%   TIME+   Command
2248  root   20    0    14364  3304  3088  D   0.7    0.0    0:04.23 ./ethercatdaemon

I added some logs to find out where is the problem point, and I found that ecrt_master_activate function doesn't work.

This is where I called the ecrt_master

bool ECRT_Master::Activate()     // ecrt_master_activate
{
    std::cout << "m_pmaster" << m_pMaster << std::endl;
    int check;
    check = ecrt_master_activate(m_pMaster);
    std::cout << "check" << check << std::endl;
    return check ? true : false;
}

And this is the ecrt_master_activate function made by etherlab

int ecrt_master_activate(ec_master_t *master)
{
    printf("function inside");
    ec_ioctl_master_activate_t io;
    printf("io");
    int ret;
    printf("before ioctl");
    ret = ioctl(master->fd, EC_IOCTL_ACTIVATE, &io,20);
    printf("after ioctl");
    if (EC_IOCTL_IS_ERROR(ret)) {
        fprintf(stderr, "Failed to activate master: %s\n",
                strerror(EC_IOCTL_ERRNO(ret)));
        return -EC_IOCTL_ERRNO(ret);
    }

    master->process_data_size = io.process_data_size;

    if (master->process_data_size) {
#ifdef USE_RTDM
        /* memory-mapping was already done in kernel. The user-space addess is
         * provided in the ioctl data.
         */
        master->process_data = io.process_data;
#else
        master->process_data = mmap(0, master->process_data_size,
                PROT_READ | PROT_WRITE, MAP_SHARED, master->fd, 0);
        if (master->process_data == MAP_FAILED) {
            fprintf(stderr, "Failed to map process data: %s\n",
                    strerror(errno));
            master->process_data = NULL;
            master->process_data_size = 0;
            return -errno;
        }
#endif

        // Access the mapped region to cause the initial page fault
        master->process_data[0] = 0x00;
    }

    return 0;
}

And this is my last part of log

Commservo pass1
CommFaultReset pass1
CommTargetCurrent pass1
CommOperationMode pass1
CommPositionSpeed pass1
CSlave.cpp [Initialize] : Slave (6) Initialize.. Status [1]
CSlave.cpp [ConfigPdos] : Slave (6) Set Slave PDO Entry..
CSlave.cpp [ConfigPdos] : Slave (6) ConfigPdos.. pSlave [0x55aa486c8f00] pSyncManager [0x55aa486cb8f0]
CSlave.cpp [Initialize] : Slave (7) Initialize..
Commservo pass1
CommFaultReset pass1
CommTargetCurrent pass1
CommOperationMode pass1
CommPositionSpeed pass1
CSlave.cpp [Initialize] : Slave (7) Initialize.. Status [1]
CSlave.cpp [ConfigPdos] : Slave (7) Set Slave PDO Entry..
CSlave.cpp [ConfigPdos] : Slave (7) ConfigPdos.. pSlave [0x55aa486c9080] pSyncManager [0x55aa486cba90]
CSlaveManager.cpp [Run] : Run Thread...
CMaster.cpp [Activate] : Activate...
m_pmaster0x55aa486c82d0

The m_pmaster value was checked but calling ecrt_master_activate function didn't work. It didn't even go into the function. Function inside didn't call What should I do?

0

There are 0 answers