[etherlab-users] state change error and UNMATCHED datagram
許凱揚
naruto60509 at gmail.com
Sat Jul 29 16:54:07 CEST 2017
HI
I use ethercat-1.5.2 and connect to the driver ( HIWIN D2 driver)
But I can't change the state from Servo not ready to Servo ready
the module is 8139too, and I tried generic but it still not work
I think the reason is my code is wrong.
So I tried to change the "EC_WRITE_S16(domainOutput_pd + HIWIN_cntlwd,
0xF); "
But whatever I modify the code , the message i get by dmesg is state change
error and UNMATCHED datagram everytime.
I don't know where have error and I want to know what " 0B 7F 00 00 00 00
13 80 00 00 00 00 00 00 00 00 " means.
When I execute my program, the terminal always show the slave state is:
0 0:0 PREOP E D2 CoE Drive
And the dmesg show that:
[19967.768070] EtherCAT ERROR 0-0: Failed to set SAFEOP state, slave
refused state change (PREOP + ERROR).
[19967.808571] EtherCAT ERROR 0-0: AL status message 0x001E: "Invalid input
configuration".
[19967.890679] EtherCAT 0-0: Acknowledged state PREOP.
[19968.764822] EtherCAT 0: Domain 0: Working counter changed to 0/1.
[19980.238918] EtherCAT 0: Releasing master...
[19980.238924] EtherCAT DEBUG 0: ecrt_master_deactivate(master =
0xffff88014f4e2000)
[19980.238926] EtherCAT DEBUG 0: Stopping master thread.
[19980.238932] EtherCAT DEBUG 0: Master OP thread exiting...
[19980.238948] EtherCAT 0: Master thread exited.
[19980.238958] EtherCAT 0: Starting EtherCAT-IDLE thread.
[19980.238986] EtherCAT DEBUG 0: OPERATION -> IDLE.
[19980.238988] EtherCAT 0: Released.
[19980.239791] EtherCAT DEBUG 0: Idle thread running with send interval =
10000 us, max data size=112500
[19980.239800] EtherCAT DEBUG 0: UNMATCHED datagram:
[19980.239802] EtherCAT DEBUG: 0B 7F 00 00 00 00 13 80 00 00 00 00 00 00 00
00
[19980.239810] EtherCAT DEBUG: 00 00 00 00 00 00 0F 00 00 00 00 00 00 00 00
[19980.239818] EtherCAT DEBUG 0: UNMATCHED datagram:
[19980.239819] EtherCAT DEBUG: 0A 80 13 00 00 00 0E 80 00 00 00 00 00 00 00
00
[19980.239827] EtherCAT DEBUG: 00 00 00 00 00 00 00 00 00 00
-----------------------------------------------------------------------------------------------------
my code:
#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 <inttypes.h>
/****************************************************************************/
#include "ecrt.h"
/****************************************************************************/
// Application parameters
#define FREQUENCY 50
#define PRIORITY 1
/****************************************************************************/
// EtherCAT
static ec_master_t *master = NULL;
static ec_master_state_t master_state = {};
static ec_domain_t *domainInput = NULL;
static ec_domain_state_t domainInput_state = {};
static ec_domain_t *domainOutput = NULL;
static ec_domain_state_t domainOutput_state = {};
static ec_slave_config_t *sc_motor = NULL;
static ec_slave_config_state_t sc_motor_state = {};
// Timer
static unsigned int sig_alarms = 0;
static unsigned int user_alarms = 0;
/****************************************************************************/
// process data
static uint8_t *domainOutput_pd = NULL;
static uint8_t *domainInput_pd = NULL;
#define MotorSlavePos 0, 0
#define HIWIN 0x0000AAAA, 0x00000003
// offsets for PDO entries
static unsigned int HIWIN_cntlwd;
static unsigned int HIWIN_tarvel;
static unsigned int HIWIN_tarpos;
static unsigned int HIWIN_provel;
static unsigned int HIWIN_proacc;
static unsigned int HIWIN_prodec;
static unsigned int HIWIN_maxvel;
static unsigned int HIWIN_modeop;
static unsigned int HIWIN_status;
static unsigned int HIWIN_actpos;
static unsigned int HIWIN_actvel;
static unsigned int HIWIN_feacv;
static unsigned int HIWIN_proacc;
const static ec_pdo_entry_reg_t domainOutput_regs[] = {
//{ MotorSlavePos, HIWIN, 0x607F, 0, &HIWIN_maxvel },
{ MotorSlavePos, HIWIN, 0x60FF, 0, &HIWIN_tarvel },
{ MotorSlavePos, HIWIN, 0x607A, 0, &HIWIN_tarpos },
{ MotorSlavePos, HIWIN, 0x6081, 0, &HIWIN_provel },
{ MotorSlavePos, HIWIN, 0x6040, 0, &HIWIN_cntlwd },
{ MotorSlavePos, HIWIN, 0x6060, 0, &HIWIN_modeop },
{ MotorSlavePos, HIWIN, 0x6083, 0, &HIWIN_proacc },//Profile acceleration
{}
};
const static ec_pdo_entry_reg_t domainInput_regs[] = {
{ MotorSlavePos, HIWIN, 0x6064, 0, &HIWIN_actpos },
{ MotorSlavePos, HIWIN, 0x606C, 0, &HIWIN_actvel },
{ MotorSlavePos, HIWIN, 0x6041, 0, &HIWIN_status },
{ MotorSlavePos, HIWIN, 0x60F4, 0, &HIWIN_feacv },//Following error actual
value
{}
};
/*****************************************************************************/
static ec_pdo_entry_info_t HIWIN_pdo_entries_output[] = {
{ 0x60FF, 0x00, 32 },
{ 0x607A, 0x00, 32 },
{ 0x6081, 0x00, 32 },
{ 0x6040, 0x00, 16 },
{ 0x6060, 0x00, 8 },
{ 0x6083, 0x00, 32},
};
static ec_pdo_entry_info_t HIWIN_pdo_entries_input[] = {
{ 0x6064, 0x00, 32 },
{ 0x606C, 0x00, 32 },
{ 0x6041, 0x00, 16 },
{ 0x60F4, 0x00, 32 },
};
static ec_pdo_info_t HIWIN_pdo_1600[] = {
{ 0x1600, 6, HIWIN_pdo_entries_output },
};
static ec_pdo_info_t HIWIN_pdo_1a00[] = {
{ 0x1A00, 4, HIWIN_pdo_entries_input },
};
static ec_sync_info_t HIWIN_syncs[] = {
{ 0, EC_DIR_OUTPUT, 0, NULL, EC_WD_DISABLE },
{ 1, EC_DIR_INPUT, 0, NULL, EC_WD_DISABLE },
{ 2, EC_DIR_OUTPUT, 1, HIWIN_pdo_1600, EC_WD_DISABLE },
{ 3, EC_DIR_INPUT, 1, HIWIN_pdo_1a00, EC_WD_DISABLE },
{ 0xff }
};
/*****************************************************************************/
void check_domain_state(void)
{
ec_domain_state_t ds;
ecrt_domain_state(domainOutput, &ds);
if (ds.working_counter != domainOutput_state.working_counter)
printf("domainOutput: WC %u.\n", ds.working_counter);
if (ds.wc_state != domainOutput_state.wc_state)
printf("domainOutput: State %u.\n", ds.wc_state);
domainOutput_state = ds;
ecrt_domain_state(domainInput, &ds);
if (ds.working_counter != domainInput_state.working_counter)
printf("domainInput: WC %u.\n", ds.working_counter);
if (ds.wc_state != domainInput_state.wc_state)
printf("domainInput: State %u.\n", ds.wc_state);
domainInput_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);
//printf("state: %d\n",state);
}
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_motor, &s);
if (s.al_state != sc_motor_state.al_state)
printf("Motor: State 0x%02X.\n", s.al_state);
if (s.online != sc_motor_state.online)
printf("Motor: %s.\n", s.online ? "online" : "offline");
if (s.operational != sc_motor_state.operational)
printf("Motor: %soperational.\n",s.operational ? "" : "Not ");
sc_motor_state = s;
}
/****************************************************************************/
void cyclic_task()
{
static int state = 0;
// receive process data
ecrt_master_receive(master);
ecrt_domain_process(domainOutput);
ecrt_domain_process(domainInput);
// check process data state (optional)
check_domain_state();
// check for master state (optional)
check_master_state();
// check for islave configuration state(s) (optional)
check_slave_config_states();
}
EC_WRITE_S16(domainOutput_pd + HIWIN_cntlwd, 0xF);
ecrt_domain_queue(domainOutput);
ecrt_domain_queue(domainInput);
ecrt_master_send(master);
}
/********************************************************cntlwd********************/
int main(int argc, char **argv)
{
// Requests an EtherCAT master for realtime operation.
master = ecrt_request_master(0); // Index of the master to request.
if (!master)
return -1;
// Creates a new process data domain
domainOutput = ecrt_master_create_domain(master);
if (!domainOutput)
return -1;
domainInput = ecrt_master_create_domain(master);
if (!domainInput)
return -1;
// Obtains a slave configuration
if (!(sc_motor = ecrt_master_slave_config(master, MotorSlavePos, HIWIN))) {
fprintf(stderr, "Failed to get slave configuration.\n");
return -1;
}
// Configuring PDOs
printf("Configuring PDOs...\n");
if (ecrt_slave_config_pdos(sc_motor, EC_END, HIWIN_syncs)) {
fprintf(stderr, "Failed to configure PDOs.\n");//error
return -1;
}
if (ecrt_domain_reg_pdo_entry_list(domainOutput, domainOutput_regs)) {
fprintf(stderr, "PDO entry registration failed!\n");//error
return -1;
}
if (ecrt_domain_reg_pdo_entry_list(domainInput, domainInput_regs)) {
fprintf(stderr, "PDO entry registration failed!\n");
return -1;
}
printf("Activating master...\n");
if (ecrt_master_activate(master))
return -1;
if (!(domainOutput_pd = ecrt_domain_data(domainOutput))) {
return -1;
}
if (!(domainInput_pd = ecrt_domain_data(domainInput))) {
return -1;
}
printf("Started.\n");
while (1) {
usleep(1000000 / FREQUENCY);
cyclic_task();
}
return 0;
}
---------------------------------------------------------------
If the information is not enough, please tell me and I'll supplement as
soon as possible
thanks
Best regard -Young
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.etherlab.org/pipermail/etherlab-users/attachments/20170729/922edb12/attachment-0002.htm>
More information about the Etherlab-users
mailing list