dobot-python icon indicating copy to clipboard operation
dobot-python copied to clipboard

Issue with robot response

Open h-mitchell opened this issue 3 years ago • 4 comments

Hi, I'm getting an issue running protocols using this API. Using a modified version of the example gripper protocol:

import cv2
from serial.tools import list_ports
import sys
import os
sys.path.insert(0, os.path.abspath('.'))
from time import sleep
from lib.interface import Interface

available_ports = list_ports.comports()
print(f'available ports: {[x.device for x in available_ports]}')
port = available_ports[1].device

bot = Interface(port)

if bot.connected():
    print('Connected')
else:
    print('Not connected')

print('Bot status:', 'connected' if bot.connected() else 'not connected')

#status = bot.get_end_effector_gripper()
#print('Status:', status)

bot.set_end_effector_gripper(True, False)
sleep(2)

bot.set_end_effector_gripper(True, True)
sleep(2)

bot.set_end_effector_gripper(True, False)
sleep(2)

bot.set_end_effector_gripper(False, False)

I'm connected with the correct port (COM4) but there is no response from the bot. When I turn the bot off, I get a response:

available ports: ['COM3', 'COM4']
Connected
Bot status: connected
Traceback (most recent call last):
  File "C:\Users\ib816\dobot-python\examples\test.py", line 25, in <module>
    bot.set_end_effector_gripper(True, False)
  File "C:\Users\ib816\dobot-python\lib\interface.py", line 155, in set_end_effector_gripper
    return self.send(request)
  File "C:\Users\ib816\dobot-python\lib\interface.py", line 26, in send
    return response.params
AttributeError: 'NoneType' object has no attribute 'params'

It seems the bot is connecting but I'm not able to run any commands. I was able to get this script to run previously but after rebooting I can no longer run any scripts. I'm guessing the error flagged in bash is because the bot is off, but I don't get any errors as to why nothing is happening. Running code in Python 3.10.5, dobot firmware 3.7.0, Windows 10.

h-mitchell avatar Jun 17 '22 12:06 h-mitchell

I no longer have access to a robot, so I won't be of much help. There seems to be some missing None check in interface.py where Interface.send is used:

https://github.com/AlexGustafsson/dobot-python/blob/a7a3281399bae491f9ac34ecdcd06edbd103538b/lib/interface.py#L26

So the response you get from the robot seems to be empty. I have no idea as to why that is, though. It might just be that it's off as you said.

Perhaps there's a firmware or driver update available?

AlexGustafsson avatar Jul 26 '22 07:07 AlexGustafsson

Hi, I have the same issue with the response object. So far I figured out that the robot does not respond with "\xaa\xaa" as header and the error comes from message.py: https://github.com/AlexGustafsson/dobot-python/blob/a7a3281399bae491f9ac34ecdcd06edbd103538b/lib/message.py#L54-L58

When the header is not b'\xaa\xaa' it returns None and None has of course no 'params' that is later needed here: https://github.com/AlexGustafsson/dobot-python/blob/a7a3281399bae491f9ac34ecdcd06edbd103538b/lib/interface.py#L20-L26

In my case, the robot responded with a "\xff" and no further bytes. Additionally, I tested with Dobot Studio. After the error occured, it was impossible with Dobot Studio to connect again. I had to switch the robot off and on to be able to connect/disconnect it again with Dobot studio. When controlled with the Dobot studio, also "Home" works.

Interestingly, some weeks ago during my first tests with the robot everything worked with dobot-python. I do not know yet what has changed inbetween. For some reason, Dobot studio is sending the commands in a somehow different way, maybe the serial port is configured a bit differently as it does not crash the robot

@h-mitchell Connecting the robot with dobot-python and Dobot studio is probably different. While dobot-python just creates and opens the COM port, Dobot studio is probably doing some additional communication as it checks whether a Dobot Magician is present at the COM port.

Tested with python 3.6, firmware 3.7.0, Windows 10. If somebody figures out more, please let me know.

@AlexGustafsson: Thanks for making the library available. It helps a lot!

afischer-sweepme avatar Oct 04 '22 19:10 afischer-sweepme

Finally figured out that the "Reset" button at the backside of the robot is more effective than switching off and switching on. In our case, it solved the problem and the Dobot Magician was reacting to commands sent with python. @h-mitchell could you try this as well?

afischer-sweepme avatar Oct 07 '22 15:10 afischer-sweepme

@afischer-sweepme sorry for the delay, have tried using the reset button instead of the power switch but makes no difference, still getting the same error. Have managed to use the default python dobot library to write my scripts - a lot less intuitive but doesn't throw the same error.

h-mitchell avatar Oct 28 '22 16:10 h-mitchell