<span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:14px;background-color:rgb(255,255,255)">Hi all, my name CJ from south korea.</span><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:14px;background-color:rgb(255,255,255)">
<br></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:14px;background-color:rgb(255,255,255)">I modified an example in /example/user/main.c</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:14px;background-color:rgb(255,255,255)">
<br></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:14px;background-color:rgb(255,255,255)">My goal is to communicate with slave motor drive(epos3) by using ethercat through SDO and PDO messages.</div>
<div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:14px;background-color:rgb(255,255,255)"><br></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:14px;background-color:rgb(255,255,255)">
My slave drive can get into OP state like these messages</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:14px;background-color:rgb(255,255,255)"><br></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:14px;background-color:rgb(255,255,255)">
<p><span lang="EN-US" style="font-family:ÇÔÃÊ·Ò¹ÙÅÁ,serif">Activating master...</span><span lang="EN-US"></span></p><p><span lang="EN-US" style="font-family:ÇÔÃÊ·Ò¹ÙÅÁ,serif">Starting timer...</span><span lang="EN-US"></span></p><p>
<span lang="EN-US" style="font-family:ÇÔÃÊ·Ò¹ÙÅÁ,serif">Started.</span><span lang="EN-US"></span></p><p><span lang="EN-US" style="font-family:ÇÔÃÊ·Ò¹ÙÅÁ,serif">1 slave(s).</span><span lang="EN-US"></span></p><p><span lang="EN-US" style="font-family:ÇÔÃÊ·Ò¹ÙÅÁ,serif">AL states: 0x02.</span><span lang="EN-US"></span></p>
<p><span lang="EN-US" style="font-family:ÇÔÃÊ·Ò¹ÙÅÁ,serif">Link is up.</span><span lang="EN-US"></span></p><p><span lang="EN-US" style="font-family:ÇÔÃÊ·Ò¹ÙÅÁ,serif">EPOS3 slave 0 State 0x02.</span><span lang="EN-US"></span></p><p>
<span lang="EN-US" style="font-family:ÇÔÃÊ·Ò¹ÙÅÁ,serif">EPOS3 slave 0: online.</span><span lang="EN-US"></span></p><p><span lang="EN-US" style="font-family:ÇÔÃÊ·Ò¹ÙÅÁ,serif">Domain: WC 3.</span><span lang="EN-US"></span></p><p><span lang="EN-US" style="font-family:ÇÔÃÊ·Ò¹ÙÅÁ,serif">Domain: State 2.</span><span lang="EN-US"></span></p>
<p><span lang="EN-US" style="font-family:ÇÔÃÊ·Ò¹ÙÅÁ,serif">AL states: 0x08.</span><span lang="EN-US"></span></p><p><span lang="EN-US" style="font-family:ÇÔÃÊ·Ò¹ÙÅÁ,serif">EPOS3 slave 0 State 0x08.</span><span lang="EN-US"></span></p>
<p><span lang="EN-US" style="font-family:ÇÔÃÊ·Ò¹ÙÅÁ,serif">EPOS3 slave 0: operational.</span><span lang="EN-US"></span></p><p><span lang="EN-US" style="font-family:ÇÔÃÊ·Ò¹ÙÅÁ,serif"><br></span></p><p><span lang="EN-US" style="font-family:ÇÔÃÊ·Ò¹ÙÅÁ,serif">and kernel messages are like this,</span></p>
<p><span lang="EN-US" style="font-family:ÇÔÃÊ·Ò¹ÙÅÁ,serif"></span></p><p><span lang="EN-US">...</span><span lang="EN-US"></span></p><p><span lang="EN-US">[29145.133927] EtherCAT DEBUG 0: Stopping master thread.</span><span lang="EN-US"></span></p>
<p><span lang="EN-US">[29145.133930] EtherCAT DEBUG 0: Master IDLE thread exiting...</span><span lang="EN-US"></span></p><p><span lang="EN-US">[29145.133952] EtherCAT 0: Master thread exited.</span><span lang="EN-US"></span></p>
<p><span lang="EN-US">[29145.133954] EtherCAT DEBUG 0: FSM datagram is ffff8800527bd648.</span><span lang="EN-US"></span></p><p><span lang="EN-US">[29145.133955] EtherCAT 0: Starting EtherCAT-OP thread.</span><span lang="EN-US"></span></p>
<p><span lang="EN-US">[29145.133973] EtherCAT DEBUG 0: mmap()</span><span lang="EN-US"></span></p><p><span lang="EN-US">[29145.133975] EtherCAT DEBUG 0: Vma fault, virtual_address = 00007fb7e9b61000, offset = 0, page = ffffea00011ffe30</span><span lang="EN-US"></span></p>
<p><span lang="EN-US">[29145.134008] EtherCAT DEBUG 0: Operation thread running with fsm interval = 10000 us, max data size=112500</span><span lang="EN-US"></span></p><p><span lang="EN-US">[29145.134010] EtherCAT WARNING 0: 1 datagram UNMATCHED!</span><span lang="EN-US"></span></p>
<p><span lang="EN-US">[29145.143508] EtherCAT DEBUG 0: Configuration changed (aborting state check).</span><span lang="EN-US"></span></p><p><span lang="EN-US">[29145.143511] EtherCAT DEBUG 0: Writing system time offsets...</span><span lang="EN-US"></span></p>
<p><span lang="EN-US">[29145.143512] EtherCAT WARNING 0: No app_time received up to now, but master already active.</span><span lang="EN-US"></span></p><p><span lang="EN-US">[29145.143513] EtherCAT DEBUG 0: Requesting OP...</span><span lang="EN-US"></span></p>
<p><span lang="EN-US">[29145.181179] EtherCAT DEBUG 0-0: Changing state from PREOP to OP.</span><span lang="EN-US"></span></p><p><span lang="EN-US">[29145.181182] EtherCAT DEBUG 0-0: Configuring...</span><span lang="EN-US"></span></p>
<p><span lang="EN-US">[29145.215005] EtherCAT DEBUG 0-0: Now in INIT.</span><span lang="EN-US"></span></p><p><span lang="EN-US">[29145.215007] EtherCAT DEBUG 0-0: Clearing FMMU configurations...</span><span lang="EN-US"></span></p>
<p><span lang="EN-US">[29145.235006] EtherCAT DEBUG 0-0: Clearing sync manager configurations...</span><span lang="EN-US"></span></p><p><span lang="EN-US">[29145.255046] EtherCAT DEBUG 0-0: Clearing DC assignment...</span><span lang="EN-US"></span></p>
<p><span lang="EN-US">[29145.274967] EtherCAT DEBUG 0-0: Configuring mailbox sync managers...</span><span lang="EN-US"></span></p><p><span lang="EN-US">[29145.274995] EtherCAT DEBUG 0-0: SM0: Addr 0x1000, Size 1024, Ctrl 0x26, En 1</span><span lang="EN-US"></span></p>
<p><span lang="EN-US">[29145.274997] EtherCAT DEBUG 0-0: SM1: Addr 0x1400, Size 1024, Ctrl 0x22, En 1</span><span lang="EN-US"></span></p><p><span lang="EN-US">[29145.334911] EtherCAT DEBUG 0-0: Now in PREOP.</span><span lang="EN-US"></span></p>
<p><span lang="EN-US">[29145.334918] EtherCAT DEBUG 0-0: Setting PDO assignment of SM2:</span><span lang="EN-US"></span></p><p><span lang="EN-US">[29145.334919] EtherCAT DEBUG 0-0: Currently assigned PDOs: 0x1600. PDOs to assign: 0x1600</span><span lang="EN-US"></span></p>
<p><span lang="EN-US">[29145.334922] EtherCAT DEBUG 0-0: Setting number of assigned PDOs to zero.</span><span lang="EN-US"></span></p><p><span lang="EN-US">[29145.334923] EtherCAT DEBUG 0-0: Downloading SDO 0x1C12:00.</span><span lang="EN-US"></span></p>
<p><span lang="EN-US">[29145.334924] EtherCAT DEBUG: 00</span><span lang="EN-US"></span></p><p><span lang="EN-US">[29145.334926] EtherCAT DEBUG 0-0: Expedited download request:</span><span lang="EN-US"></span></p><p><span lang="EN-US">[29145.334927] EtherCAT DEBUG: 00 20 2F 12 1C 00 00 00 00 00</span><span lang="EN-US"></span></p>
<p><span lang="EN-US">[29145.394874] EtherCAT DEBUG 0-0: Download response:</span><span lang="EN-US"></span></p><p><span lang="EN-US">[29145.394876] EtherCAT DEBUG: 00 30 60 12 1C 00 00 00 00 00</span><span lang="EN-US"></span></p>
<p><span lang="EN-US">[29145.394881] EtherCAT DEBUG 0-0: Assigning PDO 0x1600 at position 1.</span><span lang="EN-US"></span></p><p><span lang="EN-US">[29145.394882] EtherCAT DEBUG 0-0: Downloading SDO 0x1C12:01.</span><span lang="EN-US"></span></p>
<p><span lang="EN-US">[29145.394883] EtherCAT DEBUG: 00 16</span><span lang="EN-US"></span></p><p><span lang="EN-US">[29145.394885] EtherCAT DEBUG 0-0: Expedited download request:</span><span lang="EN-US"></span></p><p><span lang="EN-US">[29145.394885] EtherCAT DEBUG: 00 20 2B 12 1C 01 00 16 00 00</span><span lang="EN-US"></span></p>
<p><span lang="EN-US">[29145.454815] EtherCAT DEBUG 0-0: Download response:</span><span lang="EN-US"></span></p><p><span lang="EN-US">[29145.454816] EtherCAT DEBUG: 00 30 60 12 1C 01 00 16 00 00</span><span lang="EN-US"></span></p>
<p><span lang="EN-US">[29145.454820] EtherCAT DEBUG 0-0: Setting number of assigned PDOs to 1.</span><span lang="EN-US"></span></p><p><span lang="EN-US">[29145.454822] EtherCAT DEBUG 0-0: Downloading SDO 0x1C12:00.</span><span lang="EN-US"></span></p>
<p><span lang="EN-US">[29145.454822] EtherCAT DEBUG: 01</span><span lang="EN-US"></span></p><p><span lang="EN-US">[29145.454824] EtherCAT DEBUG 0-0: Expedited download request:</span><span lang="EN-US"></span></p><p><span lang="EN-US">[29145.454824] EtherCAT DEBUG: 00 20 2F 12 1C 00 01 00 00 00</span><span lang="EN-US"></span></p>
<p><span lang="EN-US">[29145.514775] EtherCAT DEBUG 0-0: Download response:</span><span lang="EN-US"></span></p><p><span lang="EN-US">[29145.514777] EtherCAT DEBUG: 00 30 60 12 1C 00 01 00 00 00</span><span lang="EN-US"></span></p>
<p><span lang="EN-US">[29145.514783] EtherCAT DEBUG 0-0: Successfully configured PDO assignment of SM2.</span><span lang="EN-US"></span></p><p><span lang="EN-US">[29145.514787] EtherCAT DEBUG 0-0: Setting PDO assignment of SM3:</span><span lang="EN-US"></span></p>
<p><span lang="EN-US">[29145.514787] EtherCAT DEBUG 0-0: Currently assigned PDOs: 0x1A00. PDOs to assign: 0x1A00</span><span lang="EN-US"></span></p><p><span lang="EN-US">[29145.514790] EtherCAT DEBUG 0-0: Setting number of assigned PDOs to zero.</span><span lang="EN-US"></span></p>
<p><span lang="EN-US">[29145.514792] EtherCAT DEBUG 0-0: Downloading SDO 0x1C13:00.</span><span lang="EN-US"></span></p><p><span lang="EN-US">[29145.514792] EtherCAT DEBUG: 00</span><span lang="EN-US"></span></p><p><span lang="EN-US">[29145.514794] EtherCAT DEBUG 0-0: Expedited download request:</span><span lang="EN-US"></span></p>
<p><span lang="EN-US">[29145.514794] EtherCAT DEBUG: 00 20 2F 13 1C 00 00 00 00 00</span><span lang="EN-US"></span></p><p><span lang="EN-US">[29145.574693] EtherCAT DEBUG 0-0: Download response:</span><span lang="EN-US"></span></p>
<p><span lang="EN-US">[29145.574695] EtherCAT DEBUG: 00 30 60 13 1C 00 00 00 00 00</span><span lang="EN-US"></span></p><p><span lang="EN-US">[29145.574700] EtherCAT DEBUG 0-0: Assigning PDO 0x1A00 at position 1.</span><span lang="EN-US"></span></p>
<p><span lang="EN-US">[29145.574702] EtherCAT DEBUG 0-0: Downloading SDO 0x1C13:01.</span><span lang="EN-US"></span></p><p><span lang="EN-US">[29145.574703] EtherCAT DEBUG: 00 1A</span><span lang="EN-US"></span></p><p><span lang="EN-US">[29145.574704] EtherCAT DEBUG 0-0: Expedited download request:</span><span lang="EN-US"></span></p>
<p><span lang="EN-US">[29145.574705] EtherCAT DEBUG: 00 20 2B 13 1C 01 00 1A 00 00</span><span lang="EN-US"></span></p><p><span lang="EN-US">[29145.634651] EtherCAT DEBUG 0-0: Download response:</span><span lang="EN-US"></span></p>
<p><span lang="EN-US">[29145.634653] EtherCAT DEBUG: 00 30 60 13 1C 01 00 1A 00 00</span><span lang="EN-US"></span></p><p><span lang="EN-US">[29145.634656] EtherCAT DEBUG 0-0: Setting number of assigned PDOs to 1.</span><span lang="EN-US"></span></p>
<p><span lang="EN-US">[29145.634658] EtherCAT DEBUG 0-0: Downloading SDO 0x1C13:00.</span><span lang="EN-US"></span></p><p><span lang="EN-US">[29145.634659] EtherCAT DEBUG: 01</span><span lang="EN-US"></span></p><p><span lang="EN-US">[29145.634660] EtherCAT DEBUG 0-0: Expedited download request:</span><span lang="EN-US"></span></p>
<p><span lang="EN-US">[29145.634661] EtherCAT DEBUG: 00 20 2F 13 1C 00 01 00 00 00</span><span lang="EN-US"></span></p><p><span lang="EN-US">[29145.694597] EtherCAT DEBUG 0-0: Download response:</span><span lang="EN-US"></span></p>
<p><span lang="EN-US">[29145.694599] EtherCAT DEBUG: 00 30 60 13 1C 00 01 00 00 00</span><span lang="EN-US"></span></p><p><span lang="EN-US">[29145.694603] EtherCAT DEBUG 0-0: Successfully configured PDO assignment of SM3.</span><span lang="EN-US"></span></p>
<p><span lang="EN-US">[29145.694607] EtherCAT DEBUG 0-0: SM2: Addr 0x1800, Size 19, Ctrl 0x64, En 1</span><span lang="EN-US"></span></p><p><span lang="EN-US">[29145.694609] EtherCAT DEBUG 0-0: SM3: Addr 0x1C00, Size 15, Ctrl 0x20, En 1</span><span lang="EN-US"></span></p>
<p><span lang="EN-US">[29145.714583] EtherCAT DEBUG 0 0:0: FMMU: LogAddr 0x00000000, Size 19, PhysAddr 0x1800, SM2, Dir out</span><span lang="EN-US"></span></p><p><span lang="EN-US">[29145.714585] EtherCAT DEBUG 0 0:0: FMMU: LogAddr 0x00000013, Size 15, PhysAddr 0x1C00, SM3, Dir in</span><span lang="EN-US"></span></p>
<p><span lang="EN-US">[29145.764458] EtherCAT 0: Domain 0: Working counter changed to 3/3.</span><span lang="EN-US"></span></p><p><span lang="EN-US">[29145.774506] EtherCAT DEBUG 0-0: Now in SAFEOP.</span><span lang="EN-US"></span></p>
<p><span lang="EN-US">[29145.814535] EtherCAT DEBUG 0-0: Now in OP. Finished configuration.</span><span lang="EN-US"></span></p><p><span lang="EN-US">[29145.840543] EtherCAT 0: Slave states: OP.</span><span lang="EN-US"></span></p>
<p><span lang="EN-US"><br></span></p><p><span lang="EN-US">------------------------------------------------------------------------------------------------</span></p><p><span lang="EN-US"><br></span></p><p><span lang="EN-US">I guess that the pdos may be sent by master module.</span></p>
<p>but the actual value of objects in slave's object dictionary are not changed.</p><p>what is the problem?</p><p>please do me a favor.</p><p>and this is my example code.</p><p><br></p><p></p><p><span lang="EN-US" style="font-family:±¼¸²Ã¼">/*****************************************************************************<br>
*<br> * $Id: main.c,v 60a116ed3897 2009/07/27 10:44:16 fp $<br> *<br> * Copyright (C) 2007-2009 Florian Pose, Ingenieurgemeinschaft IgH<br> *<br> * This file is part of the IgH EtherCAT Master.<br> *<br> * The IgH EtherCAT Master is free software; you can redistribute it and/or<br>
* modify it under the terms of the GNU General Public License version 2, as<br> * published by the Free Software Foundation.<br> *<br> * The IgH EtherCAT Master is distributed in the hope that it will be useful,<br> * but WITHOUT ANY WARRANTY; without even the implied warranty of<br>
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General<br> * Public License for more details.<br> *<br> * You should have received a copy of the GNU General Public License along<br> * with the IgH EtherCAT Master; if not, write to the Free Software<br>
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA<br> *<br> * ---<br> *<br> * The license mentioned above concerns the source code only. Using the<br> * EtherCAT technology and brand is only permitted in compliance with the<br>
* industrial property and similar rights of Beckhoff Automation GmbH.<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>static ec_pdo_entry_info_t epos3_pdo_rx_entries[] = {<br> {0x6040, 0, 16}, // controlword<br>
{0x607a, 0, 32}, // target position<br> {0x60b0, 0, 32}, // position offset<br> {0x60b1, 0, 32}, // velocity offset<br> {0x60b2, 0, 16}, // torque offset<br> {0x6060, 0, 8}, // modes of opeartion<br>
{0x2078, 1, 16} // digital output functionality<br><br>};<br><br>static ec_pdo_entry_info_t epos3_pdo_tx_entries[] = {<br> {0x6041, 0, 16}, // status word<br> {0x6064, 0, 32}, // position actual value<br>
{0x606c, 0, 32}, // velocity actual value<br> {0x6077, 0, 16}, // torque actual value<br> {0x6061, 0, 8}, // modes of operation display<br> {0x2071, 1, 16} // digital input functionality<br>
};<br><br>static ec_pdo_info_t epos3_pdos[] = {<br> {0x1600, 7, epos3_pdo_rx_entries},<br> {0x1a00, 6, epos3_pdo_tx_entries}<br>};<br><br>static ec_sync_info_t epos3_syncs[] = {<br> {2, EC_DIR_OUTPUT, 1, epos3_pdos},<br>
{3, EC_DIR_INPUT, 1, epos3_pdos+1},<br> {0xff}<br>};<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, 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>/****************************************************************************/</span></p></div>