PilzDE / pilz_robots

PILZ robot manipulator module PRBT 6 in ROS
https://wiki.ros.org/pilz_robots
52 stars 25 forks source link

Failing Modbus connection often produces no error message #382

Closed ct2034 closed 4 years ago

ct2034 commented 4 years ago

Commit

b5d88cf6b3d0628ec25a5720522ed4a7d213c4fe

Steps to reproduce

  1. make sure Modbus connection can be established.
  2. disconnect the ethernet cable
  3. try to establish Modbus connection again

Other

The same behaviour happens when:

Expected behaviour

An error message is shown that describes the problem directly

Observed behaviour

No error is produced. In fact, the console looks exactly the same as when a connection is established successfully.

agutenkunst commented 4 years ago

I check this and observed that if you run with some arbitrary IP

roslaunch prbt_hardware_support modbus_client.launch modbus_server_ip:=210.168.0.1 modbus_server_port:=5020

it will after some time throw an error (for me 130s)

This is due getting stuck at https://github.com/PilzDE/pilz_robots/blob/cddde81f7ec3f4ab8c25703cb04c034aa75af869/prbt_hardware_support/src/libmodbus_client.cpp#L40

In my opinion this could be fixed by simple calling setResponseTimeout before connecting, however since Ubuntu 18 comes with libmodbus 3.0.6 this has no effect. We would need https://github.com/stephane/libmodbus/commit/8dc21ddaf51bace2030f5f06b51754eb4de6e87d

But maybe after https://github.com/PilzDE/pilz_robots/blob/cddde81f7ec3f4ab8c25703cb04c034aa75af869/prbt_hardware_support/src/libmodbus_client.cpp#L38 we could use this modbus_connection_ to manually set the timeout (maybe SO_RCVTIMEO and SO_SNDTIMEO via setsockopt) for the raw socket. But I am not sure if this influences the actual timeout during the initial commit. (See https://stackoverflow.com/questions/4181784/how-to-set-socket-timeout-in-c-when-making-multiple-connections)

This observation can be reproduced without a actual server.

If you need a server for further investigation maybe https://gist.github.com/agutenkunst/fc2d260ef9aabe34d8a9e8b3e19ae857 helps.

jschleicher commented 4 years ago

Currently in progress, see #410