OpenEtherCATsociety / SOEM

Simple Open Source EtherCAT Master
Other
1.35k stars 686 forks source link

Unable to transition to OPERATIONAL state #868

Closed hshah44 closed 3 weeks ago

hshah44 commented 3 weeks ago

Hello -

I have been at this issue for a few days not and appreciate all or any help. I am unable to transition the drive I am using to OPERATIONAL state. My goal (ATM) is to "rotate" the servo motor connected to the Servo drive.

I went through the suggestions in various issue like #224.

sudo ./slaveinfo en7 -map

SOEM (Simple Open EtherCAT Master)
Slaveinfo
Starting slaveinfo
ec_init on en7 succeeded.
1 slaves found and configured.
Calculated workcounter 3

Slave:1
 Name:InoSV660N
 Output size: 96bits
 Input size: 224bits
 State: 4
 Delay: 0[ns]
 Has DC: 1
 DCParentport:0
 Activeports:1.0.0.0
 Configured address: 1001
 Man: 00100000 ID: 000c010d Rev: 00010000
 SM0 A:1000 L: 256 F:00010026 Type:1
 SM1 A:1400 L: 256 F:00010022 Type:2
 SM2 A:1800 L:  12 F:00010064 Type:3
 SM3 A:1c00 L:  28 F:00010020 Type:4
 FMMU0 Ls:00000000 Ll:  12 Lsb:0 Leb:7 Ps:1800 Psb:0 Ty:02 Act:01
 FMMU1 Ls:0000000c Ll:  28 Lsb:0 Leb:7 Ps:1c00 Psb:0 Ty:01 Act:01
 FMMUfunc 0:1 1:2 2:3 3:0
 MBX length wr: 256 rd: 256 MBX protocols : 06
 CoE details: 0d FoE details: 00 EoE details: 02 SoE details: 00
 Ebus current: 0[mA]
 only LRD/LWR:0
PDO mapping according to CoE :
  SM2 outputs
     addr b   index: sub bitl data_type    name
  [0x0000.0] 0x6040:0x00 0x10
  [0x0002.0] 0x607A:0x00 0x20
  [0x0006.0] 0x60B8:0x00 0x10
  [0x0008.0] 0x60FE:0x01 0x20
  SM3 inputs
     addr b   index: sub bitl data_type    name
  [0x000C.0] 0x603F:0x00 0x10
  [0x000E.0] 0x6041:0x00 0x10
  [0x0010.0] 0x6064:0x00 0x20
  [0x0014.0] 0x6077:0x00 0x10
  [0x0016.0] 0x60F4:0x00 0x20
  [0x001A.0] 0x60B9:0x00 0x10
  [0x001C.0] 0x60BA:0x00 0x20
  [0x0020.0] 0x60BC:0x00 0x20
  [0x0024.0] 0x60FD:0x00 0x20
End slaveinfo, close socket
End program

Here's my main

int main() {

    if (ec_init(IFNAME)) {
        printf("Socket connection: %s\n", IFNAME);
    } else {
        printf("No socket connection: %s\n", IFNAME);
        return 1;
    }

    if (ec_config_init(FALSE) > 0) {
        printf("EtherCAT slaves detected: %d\n", ec_slavecount);

        printf("config_map: %d\n", ec_config_map(&IOmap));
        ec_configdc();

        ec_slave[1].state = EC_STATE_OPERATIONAL;
        ec_slave[1].outputs[0] = 0x02;

        printf("send: %d\n", ec_send_processdata());
        printf("recv: %d (wkc)\n", ec_receive_processdata(EC_TIMEOUTRET));

        printf("writestate: %d\n", ec_writestate(1));
        printf("statecheck: %d\n", ec_statecheck(1, EC_STATE_OPERATIONAL, EC_TIMEOUTSTATE));

        printf("current state: %d\n", ec_readstate());

    } else {
        printf("No EtherCAT slaves detected\n");
        return 1;
    }
}

Output

sudo ./main
Socket connection: en7
EtherCAT slaves detected: 1
config_map: 40
send: 1
recv: 2 (wkc)
writestate: 1
statecheck: 4
current state: 4
Slave 1 : 4097 DC: 1 Delay: 0 Topology 1 Parent: 0 StatusCode=0x27 : Freerun not supported State=0x14 : UNKNOWN

Text Output of Wireshark

packet_text.txt


Output of simple_test

SOEM (Simple Open EtherCAT Master)
Simple test
Starting simple test
ec_init on en7 succeeded.
1 slaves found and configured.
Slaves mapped, state to SAFE_OP.
segments : 1 : 40 0 0 0
Request operational state for all slaves
Calculated workcounter 3
Not all slaves reached operational state.
Slave 1 State=0x14 StatusCode=0x0027 : Freerun not supported

Request init state for all slaves
End simple test, close socket
End program

Appreciate any pointers. Thank you!

ArthurKetels commented 3 weeks ago

Slave 1 State=0x14 StatusCode=0x0027 : Freerun not supported

I think this error message is very clear. You need to activate SYNC0 at the appropriate frequency, make a real-time thread that synchronizes to the reference slave. Just like in the red_test example. You can also read about synchronized PDO in many issues posted here.

Also I would encourage you to read some more about the workings and principles of EtherCAT. I guess you are missing some basics.

hshah44 commented 3 weeks ago

Thank you @ArthurKetels.