Kinovarobotics / kortex

Code examples and API documentation for KINOVA® KORTEX™ robotic arms
https://www.kinovarobotics.com/
Other
107 stars 84 forks source link

Modbus Emergency Stop and Reset #170

Closed BBlumhofer closed 1 year ago

BBlumhofer commented 1 year ago

Description

I am forced to use the Modbus TCP connection to the robot as it will be later controlled by a PLC. I built up a testing setup using pymodbus on a laptop. The example script works well for me but I can not activate reliable the emergency stop and can not reset the robot at all. I tried different methods to send the message. I attached a small code snippet with both commands. Can you explain me where my coding fault is or if it is a bug on the robot

Version

Robot: Gen3 Ultra Lightweight Robot 6DOF Firmware: 2.4.0-3

Steps to reproduce

run the code in python

Code example

#! /usr/bin/env python3

import time
from pymodbus.client.sync import ModbusTcpClient

# Default modbus port.
PORT = 502

# IP address of the robot that holds the modbus slave.
IP_ADDRESS = '192.168.1.10'

def reset():
    # instantiate modbus client connection
    client = ModbusTcpClient(IP_ADDRESS, PORT)
    assert client.connect(), "Unable to connect to the slave"

    client.write_coil(0, True)
    time.sleep(2)

    client.write_coil(2, False)

    client.close()

if __name__ == "__main__":
    reset()

Expected behavior

Any other information

felixmaisonneuve commented 1 year ago

Hi @BBlumhofer,

I am not sure what you mean when you say you cannot set the emergency stop in a reliable way. Is it because it won't work sometimes or is it because you cannot remove the error afterwards?

I am not a Modbus expert, but I think you need to set back the "Quick stop" to False (client.write_coil(0, False)) before clearing errors with client.write_coil(2, False). Otherwise I think the flag will stay active and the error will simply be triggered again.

If you are moving the arm with Actions, you think you could also write 2 in the Holding Registers 200. It will send an Action Stop that will abort your current action without causing an error

Best, Felix

BBlumhofer commented 1 year ago

Hi Felix,

There are two issues. At first, the E-Stop using Modbus does not work every time. This was fixed by using client.write_coil(0, False) before triggering it again. But resetting the robot does not work even with the solution you proposed. I don't move the arm using actions. I want to use ROS to do that. Below you can see the structure I planned to use.

graph TD

    A[Robot] -->|ROS Interface| C(Industrial PC)
    C--> F(Task and Path Planning)
    A-->| Modbus TCP|B(Safety PLC)
    B--> D(E-Stop)
    B--> E(Teach-Panel)
felixmaisonneuve commented 1 year ago

If by "resetting the robot" you mean clearing faults (to clear the emergency stop fault) so you can use the arm again, you can use the base's clear_faults service. We have an example of that here : https://github.com/Kinovarobotics/ros_kortex/blob/noetic-devel/kortex_examples/src/full_arm/example_cartesian_poses_with_notifications.py#L81-L90

It uses the service defined above : https://github.com/Kinovarobotics/ros_kortex/blob/noetic-devel/kortex_examples/src/full_arm/example_cartesian_poses_with_notifications.py#L41-L44

You can find something equivalent in C++ as well : https://github.com/Kinovarobotics/ros_kortex/blob/noetic-devel/kortex_examples/src/full_arm/example_full_arm_movement.cpp#L81-L97

If this is not what you meant, can you elaborate on what you need and what you want to do?

Best, Felix

BBlumhofer commented 1 year ago

Hi Felix, Yes, I meant clearing faults. Sorry for being to not precise on that.

To make it more clear what I am planning to do:

I hope this helps you to understand what the issue is.

Best, Benjamin

felixmaisonneuve commented 1 year ago

Ok, I understand.

It should work the same way it does to set the emergency stop.

You ave to set client.write_coil(2, True) (that will clear faults), then set it back to client.write_coil(2, False) so you can re-enable it later.

I don't know why I didn't spot it earlier (I even copied it in my first response), but I think it will probably fix your issue

Best, Felix

BBlumhofer commented 1 year ago

Hi Felix,

Ah okay, thank you this worked for me! Thanks for your help.

Best, Benjamin