Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with robot response #3

Open
h-mitchell opened this issue Jun 17, 2022 · 4 comments
Open

Issue with robot response #3

h-mitchell opened this issue Jun 17, 2022 · 4 comments

Comments

@h-mitchell
Copy link

h-mitchell commented Jun 17, 2022

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.

@AlexGustafsson
Copy link
Owner

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:

return response.params

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?

@afischer-sweepme
Copy link

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:

@staticmethod
def read(serial):
header = serial.read(2)
if header != b'\xaa\xaa':
return None

When the header is not b'\xaa\xaa' it returns None and None has of course no 'params' that is later needed here:

def send(self, message):
self.lock.acquire()
self.serial.write(message.package())
self.serial.flush()
response = Message.read(self.serial)
self.lock.release()
return response.params

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
Copy link

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?

@h-mitchell
Copy link
Author

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants