[etherlab-users] IgH Ethercat Master and EPOS3

Muhammad Nabeel hafiz_nabeel91 at hotmail.com
Sat Nov 23 14:38:20 CET 2013


Dear All,

When I run my sample code it is giving following status, I think EPOS3 is in operational stat, am I right? But when I connect motor it is not running, please guide me, where I am doing wrong.


ecrt_request_master is called 
Configuring PDOs...
configureing PDO is completed!
Activating master...
Starting timer...
Started.
1 slave(s).
AL states: 0x02.
Link is up.
EPOS3 slave 0 State 0x02.
EPOS3 slave 0: online.
Domain: WC 3.
Domain: State 2.
AL states: 0x08.
EPOS3 slave 0 State 0x08.
EPOS3 slave 0: operational.


here is my sample code, I modify code a little bit,



#include <errno.h>
#include <signal.h>
#include <stdio.h>
#include <string.h>
#include <sys/resource.h>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>

/****************************************************************************/

#include "ecrt.h"

/****************************************************************************/

// Application parameters
#define FREQUENCY 100
#define PRIORITY 1

// Optional features
#define CONFIGURE_PDOS  1
#define SDO_ACCESS      0

/****************************************************************************/

// EtherCAT
static ec_master_t *master = NULL;
static ec_master_state_t master_state = {};

static ec_domain_t *domain0 = NULL;
static ec_domain_state_t domain_state = {};

static ec_slave_config_t *sc_epos3 = NULL;
static ec_slave_config_state_t sc_epos3_state = {};

// Timer
static unsigned int sig_alarms = 0;
static unsigned int user_alarms = 0;

/****************************************************************************/

// process data
static uint8_t *domain0_output = NULL;

#define SLAVE_DRIVE_0 0, 0
#define MAXON_EPOS3    0x000000fb, 0x64400000

// offsets for PDO entries

static unsigned int off_epos3_cntlwd;
//static unsigned int off_epos3_tvel;
static unsigned int off_epos3_tpos;
static unsigned int off_epos3_off_pos;
static unsigned int off_epos3_off_vel;
static unsigned int off_epos3_off_toq;
static unsigned int off_epos3_moo;
static unsigned int off_epos3_dof;
static unsigned int off_epos3_status;
static unsigned int off_epos3_pos_val;
static unsigned int off_epos3_vel_val;
static unsigned int off_epos3_toq_val;
static unsigned int off_epos3_mood;
static unsigned int off_epos3_dif;

const static ec_pdo_entry_reg_t domain0_regs[] = {
        {SLAVE_DRIVE_0, MAXON_EPOS3, 0x6040, 0, &off_epos3_cntlwd},
        {SLAVE_DRIVE_0, MAXON_EPOS3, 0x607a, 0, &off_epos3_tpos},
        {SLAVE_DRIVE_0, MAXON_EPOS3, 0x60b0, 0, &off_epos3_off_pos},
        {SLAVE_DRIVE_0, MAXON_EPOS3, 0x60b1, 0, &off_epos3_off_vel},
        {SLAVE_DRIVE_0, MAXON_EPOS3, 0x60b2, 0, &off_epos3_off_toq},
        {SLAVE_DRIVE_0, MAXON_EPOS3, 0x6060, 0, &off_epos3_moo},
        {SLAVE_DRIVE_0, MAXON_EPOS3, 0x2078, 1, &off_epos3_dof},
        {SLAVE_DRIVE_0, MAXON_EPOS3, 0x6041, 0, &off_epos3_status},
        {SLAVE_DRIVE_0, MAXON_EPOS3, 0x6064, 0, &off_epos3_pos_val},
        {SLAVE_DRIVE_0, MAXON_EPOS3, 0x606c, 0, &off_epos3_vel_val},
        {SLAVE_DRIVE_0, MAXON_EPOS3, 0x6077, 0, &off_epos3_toq_val},
        {SLAVE_DRIVE_0, MAXON_EPOS3, 0x6061, 0, &off_epos3_mood},
        {SLAVE_DRIVE_0, MAXON_EPOS3, 0x2071, 1, &off_epos3_dif},
        {}
};

static unsigned int counter = 0;
static unsigned int blink = 0;

/*****************************************************************************/

#if CONFIGURE_PDOS

/* Master 0, Slave 0, "EPOS3" 
 * Vendor ID:       0x000000fb 
 * Product code:    0x64400000 
 * Revision number: 0x22100000 
 */ 

ec_pdo_entry_info_t slave_0_pdo_entries[] = { 
    {0x6040, 0x00, 16}, /* 0x6040:00 */ 
    {0x607a, 0x00, 32}, /* 0x607A:00 */ 
    {0x60b0, 0x00, 32}, /* 0x60B0:00 */ 
    {0x60b1, 0x00, 32}, /* 0x60B1:00 */ 
    {0x60b2, 0x00, 16}, /* 0x60B2:00 */ 
    {0x6060, 0x00, 8}, /* 0x6060:00 */ 
    {0x2078, 0x01, 16}, /* 0x2078:01 */ 
    {0x60b8, 0x00, 16}, /* 0x60B8:00 */ 
    {0x6041, 0x00, 16}, /* 0x6041:00 */ 
    {0x6064, 0x00, 32}, /* 0x6064:00 */ 
    {0x606c, 0x00, 32}, /* 0x606C:00 */ 
    {0x6077, 0x00, 16}, /* 0x6077:00 */ 
    {0x6061, 0x00, 8}, /* 0x6061:00 */ 
    {0x2071, 0x01, 16}, /* 0x2071:01 */ 
    {0x60b9, 0x00, 16}, /* 0x60B9:00 */ 
    {0x60ba, 0x00, 32}, /* 0x60BA:00 */ 
    {0x60bb, 0x00, 32}, /* 0x60BB:00 */ 
}; 

ec_pdo_info_t slave_0_pdos[] = { 
    {0x1600, 8, slave_0_pdo_entries + 0}, /* 1st receive PDO Mapping */ 
    {0x1a00, 9, slave_0_pdo_entries + 8}, /* 1st transmit PDO Mapping */ 
}; 

ec_sync_info_t epos3_syncs[] = { 
    {0, EC_DIR_OUTPUT, 0, NULL, EC_WD_DISABLE}, 
    {1, EC_DIR_INPUT, 0, NULL, EC_WD_DISABLE}, 
    {2, EC_DIR_OUTPUT, 1, slave_0_pdos + 0, EC_WD_ENABLE}, 
    {3, EC_DIR_INPUT, 1, slave_0_pdos + 1, EC_WD_DISABLE}, 
    {0xff} 
}; 
#endif

/*****************************************************************************/

#if SDO_ACCESS
static ec_sdo_request_t *sdo;
#endif

/*****************************************************************************/

void check_domain_state(ec_domain_t *domain)
{
    ec_domain_state_t ds;

    ecrt_domain_state(domain, &ds);

    if (ds.working_counter != domain_state.working_counter)
        printf("Domain: WC %u.\n", ds.working_counter);
    if (ds.wc_state != domain_state.wc_state)
        printf("Domain: State %u.\n", ds.wc_state);

    domain_state = ds;
}

/*****************************************************************************/

void check_master_state(void)
{
    ec_master_state_t ms;

    ecrt_master_state(master, &ms);

    if (ms.slaves_responding != master_state.slaves_responding)
        printf("%u slave(s).\n", ms.slaves_responding);
    if (ms.al_states != master_state.al_states)
        printf("AL states: 0x%02X.\n", ms.al_states);
    if (ms.link_up != master_state.link_up)
        printf("Link is %s.\n", ms.link_up ? "up" : "down");

    master_state = ms;
}

/*****************************************************************************/

void check_slave_config_states(void)
{
    ec_slave_config_state_t s;

    ecrt_slave_config_state(sc_epos3, &s);

    if (s.al_state != sc_epos3_state.al_state)
        printf("EPOS3 slave 0 State 0x%02X.\n", s.al_state);
    if (s.online != sc_epos3_state.online)
        printf("EPOS3 slave 0: %s.\n", s.online ? "online" : "offline");
    if (s.operational != sc_epos3_state.operational)
        printf("EPOS3 slave 0: %soperational.\n",
                s.operational ? "" : "Not ");
    sc_epos3_state = s;
}

/*****************************************************************************/

#if SDO_ACCESS
void read_sdo(void)
{
    switch (ecrt_sdo_request_state(sdo)) {
        case EC_REQUEST_UNUSED: // request was not used yet
            ecrt_sdo_request_read(sdo); // trigger first read
            break;
        case EC_REQUEST_BUSY:
            fprintf(stderr, "Still busy...\n");
            break;
        case EC_REQUEST_SUCCESS:
            fprintf(stderr, "SDO value: 0x%04X\n",
                    EC_READ_U16(ecrt_sdo_request_data(sdo)));
            ecrt_sdo_request_read(sdo); // trigger next read
            break;
        case EC_REQUEST_ERROR:
            fprintf(stderr, "Failed to read SDO!\n");
            ecrt_sdo_request_read(sdo); // retry reading
            break;
    }
}

#endif

/****************************************************************************/

void cyclic_task(){
        int i;

        // receive process data
        ecrt_master_receive(master);
        ecrt_domain_process(domain0);

        // check process data state (optional)
        check_domain_state(domain0);

        if (counter) {
               counter--;
        }else {        // do this at 1 Hz
               counter = FREQUENCY;

               // calculate new process data
               blink = !blink;

               // check for master state (optional)
               check_master_state();

               // check for islave configuration state(s) (optional)
               check_slave_config_states();

#if SDO_ACCESS
               // read process data SDO
               read_sdo();
               printf("read_sdo\n");
#endif
        }
        // read process data
        //printf(" stataus word : %u\n",EC_READ_U8(domain1_pd +off_epos3_moo));

        // write process data
        EC_WRITE_U32(domain0_output + off_epos3_tpos, 0xff);

        // send process data
        ecrt_domain_queue(domain0);
        ecrt_master_send(master);


}

/****************************************************************************/

void signal_handler(int signum) {
    switch (signum) {
        case SIGALRM:
            sig_alarms++;
            break;
    }
}

/****************************************************************************/

int main(int argc, char **argv)
{
        ec_slave_config_t *sc;
        struct sigaction sa;
        struct itimerval tv;

        master = ecrt_request_master(0);
               printf("ecrt_request_master is called \n");
        if (!master)
               return -1;

        domain0 = ecrt_master_create_domain(master);
        if(!domain0)
               return -1;

        if(!(sc_epos3 = ecrt_master_slave_config(
                       master, SLAVE_DRIVE_0, MAXON_EPOS3))){
               fprintf(stderr, "Failed to get slave configuration. \n");
               return -1;
        }

        //added by kbkbc
        //if (ecrt_slave_config_sdo16(sc_epos3, 0x6040, 0x00,9 ) == 0)
               //printf("change SDO : 0x6040 \n");

#if SDO_ACCESS
    fprintf(stderr, "Creating SDO requests...\n");
    if (!(sdo = ecrt_slave_config_create_sdo_request(sc_epos3, 0x6060,
0x00, 16))) {
        fprintf(stderr, "Failed to create SDO request.\n");
        return -1;
    }
    ecrt_sdo_request_timeout(sdo, 500); // ms

#endif

#if CONFIGURE_PDOS
        printf("Configuring PDOs...\n");
        if (ecrt_slave_config_pdos(sc_epos3, EC_END, epos3_syncs)) {
               fprintf(stderr, "Failed to configure PDOs.\n");
               return -1;
        }
        printf("configureing PDO is completed!\n");
#endif
        if( ecrt_domain_reg_pdo_entry_list(domain0, domain0_regs)){
               fprintf(stderr, "PDO entty registration filed! \n");
               return -1;
        }

        printf("Activating master...\n");
        if (ecrt_master_activate(master))
               return -1;

        if( !(domain0_output = ecrt_domain_data(domain0))) {
               return -1;
        }

#if PRIORITY
    pid_t pid = getpid();
    if (setpriority(PRIO_PROCESS, pid, -19))
        fprintf(stderr, "Warning: Failed to set priority: %s\n",
                strerror(errno));
#endif

    sa.sa_handler = signal_handler;
    sigemptyset(&sa.sa_mask);
    sa.sa_flags = 0;
    if (sigaction(SIGALRM, &sa, 0)) {
        fprintf(stderr, "Failed to install signal handler!\n");
        return -1;
    }

    printf("Starting timer...\n");
    tv.it_interval.tv_sec = 0;
    tv.it_interval.tv_usec = 1000000 / FREQUENCY;
    tv.it_value.tv_sec = 0;
    tv.it_value.tv_usec = 1000;
    if (setitimer(ITIMER_REAL, &tv, NULL)) {
        fprintf(stderr, "Failed to start timer: %s\n", strerror(errno));
        return 1;
    }

    printf("Started.\n");

    while (1) {
        pause();

        #if 0
        struct timeval t;
        gettimeofday(&t, NULL);
        printf("%u.%06u\n", t.tv_sec, t.tv_usec);
        #endif
        while (sig_alarms != user_alarms) {
            cyclic_task();
            user_alarms++;
        }
    }

    return 0;
}



From: hafiz_nabeel91 at hotmail.com
To: raziebe at gmail.com; shabbyx at gmail.com
CC: etherlab-users at etherlab.org
Subject: RE: [etherlab-users] IgH Ethercat Master and EPOS3
Date: Sat, 23 Nov 2013 11:36:22 +0500




Thank you for your reply, how can I fix ubuntu to run the RT task? I am new to ubuntu and do not know how can I do that.



From: raziebe at gmail.com
Date: Fri, 22 Nov 2013 21:20:30 +0200
Subject: Re: [etherlab-users] IgH Ethercat Master and EPOS3
To: shabbyx at gmail.com
CC: hafiz_nabeel91 at hotmail.com; etherlab-users at etherlab.org

It means you are running  a system that forbids RT tasks from running.  you need to fix ubunto.
I suggest you take a look at the boot command line.

Raz Ben Yehuda




On Fri, Nov 22, 2013 at 4:23 PM, Shahbaz Youssefi <shabbyx at gmail.com> wrote:


I'm forwarding your question to the mailing list.




On Fri, Nov 22, 2013 at 3:18 PM, Muhammad Nabeel <hafiz_nabeel91 at hotmail.com> wrote:




AoA Shahbaz,

Hope you are doing well, I am new to Ubuntu and Ethercat.

I am using EPOS3 from maxon and IgH ethercat master but I am facing difficulties in communication between EPOS3 and IgH ethercat master. I need your help, I tried myself but I still I am confuse how to send/receive data to/from EPOS3. From Etherlab mailing I have found a source code but try to understand it but I still have some confusions. 




Please help me, I will be very thankful to you.

I have attached the source code, please see the attachment. Below is the result when I connect EPOS3 and run the program.

ecrt_request_master is called 



Configuring PDOs...
configureing PDO is completed!
Activating master...
Warning: Failed to set priority: Permission denied
Starting timer...
Started.
1 slave(s).
AL states: 0x02.
Link is up.
EPOS3 slave 0 State 0x02.



EPOS3 slave 0: online.


What is the meaning of this warning "Failed to set priority: Permission denied"?

Please guide me.

Thank you.

Best regards


Nabeel


 
 		 	   		  



_______________________________________________

etherlab-users mailing list

etherlab-users at etherlab.org

http://lists.etherlab.org/mailman/listinfo/etherlab-users




-- 
https://sites.google.com/site/ironspeedlinux/
 		 	   		   		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.etherlab.org/pipermail/etherlab-users/attachments/20131123/0914d8c4/attachment-0004.htm>


More information about the Etherlab-users mailing list