<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 12pt;
font-family:Calibri
}
--></style></head>
<body class='hmmessage'><div dir='ltr'>Dear All,<br><br>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.<br><br><br>ecrt_request_master is called <br>Configuring PDOs...<br>configureing PDO is completed!<br>Activating master...<br>Starting timer...<br>Started.<br>1 slave(s).<br>AL states: 0x02.<br>Link is up.<br>EPOS3 slave 0 State 0x02.<br>EPOS3 slave 0: online.<br>Domain: WC 3.<br>Domain: State 2.<br>AL states: 0x08.<br>EPOS3 slave 0 State 0x08.<br>EPOS3 slave 0: operational.<br><br><br>here is my sample code, I modify code a little bit,<br><br><br><br>#include <errno.h><br>#include <signal.h><br>#include <stdio.h><br>#include <string.h><br>#include <sys/resource.h><br>#include <sys/time.h><br>#include <sys/types.h><br>#include <unistd.h><br><br>/****************************************************************************/<br><br>#include "ecrt.h"<br><br>/****************************************************************************/<br><br>// Application parameters<br>#define FREQUENCY 100<br>#define PRIORITY 1<br><br>// Optional features<br>#define CONFIGURE_PDOS  1<br>#define SDO_ACCESS      0<br><br>/****************************************************************************/<br><br>// EtherCAT<br>static ec_master_t *master = NULL;<br>static ec_master_state_t master_state = {};<br><br>static ec_domain_t *domain0 = NULL;<br>static ec_domain_state_t domain_state = {};<br><br>static ec_slave_config_t *sc_epos3 = NULL;<br>static ec_slave_config_state_t sc_epos3_state = {};<br><br>// Timer<br>static unsigned int sig_alarms = 0;<br>static unsigned int user_alarms = 0;<br><br>/****************************************************************************/<br><br>// process data<br>static uint8_t *domain0_output = NULL;<br><br>#define SLAVE_DRIVE_0 0, 0<br>#define MAXON_EPOS3    0x000000fb, 0x64400000<br><br>// offsets for PDO entries<br><br>static unsigned int off_epos3_cntlwd;<br>//static unsigned int off_epos3_tvel;<br>static unsigned int off_epos3_tpos;<br>static unsigned int off_epos3_off_pos;<br>static unsigned int off_epos3_off_vel;<br>static unsigned int off_epos3_off_toq;<br>static unsigned int off_epos3_moo;<br>static unsigned int off_epos3_dof;<br>static unsigned int off_epos3_status;<br>static unsigned int off_epos3_pos_val;<br>static unsigned int off_epos3_vel_val;<br>static unsigned int off_epos3_toq_val;<br>static unsigned int off_epos3_mood;<br>static unsigned int off_epos3_dif;<br><br>const static ec_pdo_entry_reg_t domain0_regs[] = {<br>        {SLAVE_DRIVE_0, MAXON_EPOS3, 0x6040, 0, &off_epos3_cntlwd},<br>        {SLAVE_DRIVE_0, MAXON_EPOS3, 0x607a, 0, &off_epos3_tpos},<br>        {SLAVE_DRIVE_0, MAXON_EPOS3, 0x60b0, 0, &off_epos3_off_pos},<br>        {SLAVE_DRIVE_0, MAXON_EPOS3, 0x60b1, 0, &off_epos3_off_vel},<br>        {SLAVE_DRIVE_0, MAXON_EPOS3, 0x60b2, 0, &off_epos3_off_toq},<br>        {SLAVE_DRIVE_0, MAXON_EPOS3, 0x6060, 0, &off_epos3_moo},<br>        {SLAVE_DRIVE_0, MAXON_EPOS3, 0x2078, 1, &off_epos3_dof},<br>        {SLAVE_DRIVE_0, MAXON_EPOS3, 0x6041, 0, &off_epos3_status},<br>        {SLAVE_DRIVE_0, MAXON_EPOS3, 0x6064, 0, &off_epos3_pos_val},<br>        {SLAVE_DRIVE_0, MAXON_EPOS3, 0x606c, 0, &off_epos3_vel_val},<br>        {SLAVE_DRIVE_0, MAXON_EPOS3, 0x6077, 0, &off_epos3_toq_val},<br>        {SLAVE_DRIVE_0, MAXON_EPOS3, 0x6061, 0, &off_epos3_mood},<br>        {SLAVE_DRIVE_0, MAXON_EPOS3, 0x2071, 1, &off_epos3_dif},<br>        {}<br>};<br><br>static unsigned int counter = 0;<br>static unsigned int blink = 0;<br><br>/*****************************************************************************/<br><br>#if CONFIGURE_PDOS<br><br>/* Master 0, Slave 0, "EPOS3" <br> * Vendor ID:       0x000000fb <br> * Product code:    0x64400000 <br> * Revision number: 0x22100000 <br> */ <br><br>ec_pdo_entry_info_t slave_0_pdo_entries[] = { <br>    {0x6040, 0x00, 16}, /* 0x6040:00 */ <br>    {0x607a, 0x00, 32}, /* 0x607A:00 */ <br>    {0x60b0, 0x00, 32}, /* 0x60B0:00 */ <br>    {0x60b1, 0x00, 32}, /* 0x60B1:00 */ <br>    {0x60b2, 0x00, 16}, /* 0x60B2:00 */ <br>    {0x6060, 0x00, 8}, /* 0x6060:00 */ <br>    {0x2078, 0x01, 16}, /* 0x2078:01 */ <br>    {0x60b8, 0x00, 16}, /* 0x60B8:00 */ <br>    {0x6041, 0x00, 16}, /* 0x6041:00 */ <br>    {0x6064, 0x00, 32}, /* 0x6064:00 */ <br>    {0x606c, 0x00, 32}, /* 0x606C:00 */ <br>    {0x6077, 0x00, 16}, /* 0x6077:00 */ <br>    {0x6061, 0x00, 8}, /* 0x6061:00 */ <br>    {0x2071, 0x01, 16}, /* 0x2071:01 */ <br>    {0x60b9, 0x00, 16}, /* 0x60B9:00 */ <br>    {0x60ba, 0x00, 32}, /* 0x60BA:00 */ <br>    {0x60bb, 0x00, 32}, /* 0x60BB:00 */ <br>}; <br><br>ec_pdo_info_t slave_0_pdos[] = { <br>    {0x1600, 8, slave_0_pdo_entries + 0}, /* 1st receive PDO Mapping */ <br>    {0x1a00, 9, slave_0_pdo_entries + 8}, /* 1st transmit PDO Mapping */ <br>}; <br><br>ec_sync_info_t epos3_syncs[] = { <br>    {0, EC_DIR_OUTPUT, 0, NULL, EC_WD_DISABLE}, <br>    {1, EC_DIR_INPUT, 0, NULL, EC_WD_DISABLE}, <br>    {2, EC_DIR_OUTPUT, 1, slave_0_pdos + 0, EC_WD_ENABLE}, <br>    {3, EC_DIR_INPUT, 1, slave_0_pdos + 1, EC_WD_DISABLE}, <br>    {0xff} <br>}; <br>#endif<br><br>/*****************************************************************************/<br><br>#if SDO_ACCESS<br>static ec_sdo_request_t *sdo;<br>#endif<br><br>/*****************************************************************************/<br><br>void check_domain_state(ec_domain_t *domain)<br>{<br>    ec_domain_state_t ds;<br><br>    ecrt_domain_state(domain, &ds);<br><br>    if (ds.working_counter != domain_state.working_counter)<br>        printf("Domain: WC %u.\n", ds.working_counter);<br>    if (ds.wc_state != domain_state.wc_state)<br>        printf("Domain: State %u.\n", ds.wc_state);<br><br>    domain_state = ds;<br>}<br><br>/*****************************************************************************/<br><br>void check_master_state(void)<br>{<br>    ec_master_state_t ms;<br><br>    ecrt_master_state(master, &ms);<br><br>    if (ms.slaves_responding != master_state.slaves_responding)<br>        printf("%u slave(s).\n", ms.slaves_responding);<br>    if (ms.al_states != master_state.al_states)<br>        printf("AL states: 0x%02X.\n", ms.al_states);<br>    if (ms.link_up != master_state.link_up)<br>        printf("Link is %s.\n", ms.link_up ? "up" : "down");<br><br>    master_state = ms;<br>}<br><br>/*****************************************************************************/<br><br>void check_slave_config_states(void)<br>{<br>    ec_slave_config_state_t s;<br><br>    ecrt_slave_config_state(sc_epos3, &s);<br><br>    if (s.al_state != sc_epos3_state.al_state)<br>        printf("EPOS3 slave 0 State 0x%02X.\n", s.al_state);<br>    if (s.online != sc_epos3_state.online)<br>        printf("EPOS3 slave 0: %s.\n", s.online ? "online" : "offline");<br>    if (s.operational != sc_epos3_state.operational)<br>        printf("EPOS3 slave 0: %soperational.\n",<br>                s.operational ? "" : "Not ");<br>    sc_epos3_state = s;<br>}<br><br>/*****************************************************************************/<br><br>#if SDO_ACCESS<br>void read_sdo(void)<br>{<br>    switch (ecrt_sdo_request_state(sdo)) {<br>        case EC_REQUEST_UNUSED: // request was not used yet<br>            ecrt_sdo_request_read(sdo); // trigger first read<br>            break;<br>        case EC_REQUEST_BUSY:<br>            fprintf(stderr, "Still busy...\n");<br>            break;<br>        case EC_REQUEST_SUCCESS:<br>            fprintf(stderr, "SDO value: 0x%04X\n",<br>                    EC_READ_U16(ecrt_sdo_request_data(sdo)));<br>            ecrt_sdo_request_read(sdo); // trigger next read<br>            break;<br>        case EC_REQUEST_ERROR:<br>            fprintf(stderr, "Failed to read SDO!\n");<br>            ecrt_sdo_request_read(sdo); // retry reading<br>            break;<br>    }<br>}<br><br>#endif<br><br>/****************************************************************************/<br><br>void cyclic_task(){<br>        int i;<br><br>        // receive process data<br>        ecrt_master_receive(master);<br>        ecrt_domain_process(domain0);<br><br>        // check process data state (optional)<br>        check_domain_state(domain0);<br><br>        if (counter) {<br>               counter--;<br>        }else {        // do this at 1 Hz<br>               counter = FREQUENCY;<br><br>               // calculate new process data<br>               blink = !blink;<br><br>               // check for master state (optional)<br>               check_master_state();<br><br>               // check for islave configuration state(s) (optional)<br>               check_slave_config_states();<br><br>#if SDO_ACCESS<br>               // read process data SDO<br>               read_sdo();<br>               printf("read_sdo\n");<br>#endif<br>        }<br>        // read process data<br>        //printf(" stataus word : %u\n",EC_READ_U8(domain1_pd +off_epos3_moo));<br><br>        // write process data<br>        EC_WRITE_U32(domain0_output + off_epos3_tpos, 0xff);<br><br>        // send process data<br>        ecrt_domain_queue(domain0);<br>        ecrt_master_send(master);<br><br><br>}<br><br>/****************************************************************************/<br><br>void signal_handler(int signum) {<br>    switch (signum) {<br>        case SIGALRM:<br>            sig_alarms++;<br>            break;<br>    }<br>}<br><br>/****************************************************************************/<br><br>int main(int argc, char **argv)<br>{<br>        ec_slave_config_t *sc;<br>        struct sigaction sa;<br>        struct itimerval tv;<br><br>        master = ecrt_request_master(0);<br>               printf("ecrt_request_master is called \n");<br>        if (!master)<br>               return -1;<br><br>        domain0 = ecrt_master_create_domain(master);<br>        if(!domain0)<br>               return -1;<br><br>        if(!(sc_epos3 = ecrt_master_slave_config(<br>                       master, SLAVE_DRIVE_0, MAXON_EPOS3))){<br>               fprintf(stderr, "Failed to get slave configuration. \n");<br>               return -1;<br>        }<br><br>        //added by kbkbc<br>        //if (ecrt_slave_config_sdo16(sc_epos3, 0x6040, 0x00,9 ) == 0)<br>               //printf("change SDO : 0x6040 \n");<br><br>#if SDO_ACCESS<br>    fprintf(stderr, "Creating SDO requests...\n");<br>    if (!(sdo = ecrt_slave_config_create_sdo_request(sc_epos3, 0x6060,<br>0x00, 16))) {<br>        fprintf(stderr, "Failed to create SDO request.\n");<br>        return -1;<br>    }<br>    ecrt_sdo_request_timeout(sdo, 500); // ms<br><br>#endif<br><br>#if CONFIGURE_PDOS<br>        printf("Configuring PDOs...\n");<br>        if (ecrt_slave_config_pdos(sc_epos3, EC_END, epos3_syncs)) {<br>               fprintf(stderr, "Failed to configure PDOs.\n");<br>               return -1;<br>        }<br>        printf("configureing PDO is completed!\n");<br>#endif<br>        if( ecrt_domain_reg_pdo_entry_list(domain0, domain0_regs)){<br>               fprintf(stderr, "PDO entty registration filed! \n");<br>               return -1;<br>        }<br><br>        printf("Activating master...\n");<br>        if (ecrt_master_activate(master))<br>               return -1;<br><br>        if( !(domain0_output = ecrt_domain_data(domain0))) {<br>               return -1;<br>        }<br><br>#if PRIORITY<br>    pid_t pid = getpid();<br>    if (setpriority(PRIO_PROCESS, pid, -19))<br>        fprintf(stderr, "Warning: Failed to set priority: %s\n",<br>                strerror(errno));<br>#endif<br><br>    sa.sa_handler = signal_handler;<br>    sigemptyset(&sa.sa_mask);<br>    sa.sa_flags = 0;<br>    if (sigaction(SIGALRM, &sa, 0)) {<br>        fprintf(stderr, "Failed to install signal handler!\n");<br>        return -1;<br>    }<br><br>    printf("Starting timer...\n");<br>    tv.it_interval.tv_sec = 0;<br>    tv.it_interval.tv_usec = 1000000 / FREQUENCY;<br>    tv.it_value.tv_sec = 0;<br>    tv.it_value.tv_usec = 1000;<br>    if (setitimer(ITIMER_REAL, &tv, NULL)) {<br>        fprintf(stderr, "Failed to start timer: %s\n", strerror(errno));<br>        return 1;<br>    }<br><br>    printf("Started.\n");<br><br>    while (1) {<br>        pause();<br><br>        #if 0<br>        struct timeval t;<br>        gettimeofday(&t, NULL);<br>        printf("%u.%06u\n", t.tv_sec, t.tv_usec);<br>        #endif<br>        while (sig_alarms != user_alarms) {<br>            cyclic_task();<br>            user_alarms++;<br>        }<br>    }<br><br>    return 0;<br>}<br><br><br><br><div><hr id="stopSpelling">From: hafiz_nabeel91@hotmail.com<br>To: raziebe@gmail.com; shabbyx@gmail.com<br>CC: etherlab-users@etherlab.org<br>Subject: RE: [etherlab-users] IgH Ethercat Master and EPOS3<br>Date: Sat, 23 Nov 2013 11:36:22 +0500<br><br>

<style><!--
.ExternalClass .ecxhmmessage P {
padding:0px;
}

.ExternalClass body.ecxhmmessage {
font-size:12pt;
font-family:Calibri;
}

--></style>
<div dir="ltr">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.<br><br><br><br><div><hr id="ecxstopSpelling">From: raziebe@gmail.com<br>Date: Fri, 22 Nov 2013 21:20:30 +0200<br>Subject: Re: [etherlab-users] IgH Ethercat Master and EPOS3<br>To: shabbyx@gmail.com<br>CC: hafiz_nabeel91@hotmail.com; etherlab-users@etherlab.org<br><br><div dir="ltr"><div><div><div>It means you are running  a system that forbids RT tasks from running.  you need to fix ubunto.<br></div>I suggest you take a look at the boot command line.<br></div><br></div>Raz Ben Yehuda<br>

</div><div class="ecxgmail_extra"><br><br><div class="ecxgmail_quote">On Fri, Nov 22, 2013 at 4:23 PM, Shahbaz Youssefi <span dir="ltr"><<a href="mailto:shabbyx@gmail.com" target="_blank">shabbyx@gmail.com</a>></span> wrote:<br>

<blockquote class="ecxgmail_quote" style="border-left:1px #ccc solid;padding-left:1ex;"><div dir="ltr">I'm forwarding your question to the mailing list.<br><div><div class="ecxgmail_extra"><br><br><div class="ecxgmail_quote">

On Fri, Nov 22, 2013 at 3:18 PM, Muhammad Nabeel <span dir="ltr"><<a href="mailto:hafiz_nabeel91@hotmail.com" target="_blank">hafiz_nabeel91@hotmail.com</a>></span> wrote:<br>
<blockquote class="ecxgmail_quote" style="border-left:1px #ccc solid;padding-left:1ex;">


<div><div dir="ltr">AoA Shahbaz,<br><br>Hope you are doing well, I am new to Ubuntu and Ethercat.<br><br>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. <br>


<br>Please help me, I will be very thankful to you.<br><br>I have attached the source code, please see the attachment. Below is the result when I connect EPOS3 and run the program.<br><br>ecrt_request_master is called <br>


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


EPOS3 slave 0: online.<br><br><br>What is the meaning of this warning "Failed to set priority: Permission denied"?<br><br>Please guide me.<br><br>Thank you.<br><br>Best regards<span><font color="#888888"><br>
<br>Nabeel<br><br><br> <br>                                    </font></span></div></div>
</blockquote></div><br></div></div></div>
<br>_______________________________________________<br>
etherlab-users mailing list<br>
<a href="mailto:etherlab-users@etherlab.org">etherlab-users@etherlab.org</a><br>
<a href="http://lists.etherlab.org/mailman/listinfo/etherlab-users" target="_blank">http://lists.etherlab.org/mailman/listinfo/etherlab-users</a><br>
<br></blockquote></div><br><br clear="all"><br>-- <br><div dir="ltr"><div><a href="https://sites.google.com/site/ironspeedlinux/" target="_blank">https://sites.google.com/site/ironspeedlinux/</a></div></div>
</div></div>                                          </div></div>                                        </div></body>
</html>