Coder Social home page Coder Social logo

pydobot's Introduction

CircleCI

Python library for Dobot Magician

Based on Communication Protocol V1.1.4 (latest version here)

Installation

Install driver from https://www.silabs.com/products/development-tools/software/usb-to-uart-bridge-vcp-drivers.

pip install pydobot

Example

from serial.tools import list_ports

import pydobot

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

device = pydobot.Dobot(port=port, verbose=True)

(x, y, z, r, j1, j2, j3, j4) = device.pose()
print(f'x:{x} y:{y} z:{z} j1:{j1} j2:{j2} j3:{j3} j4:{j4}')

device.move_to(x + 20, y, z, r, wait=False)
device.move_to(x, y, z, r, wait=True)  # we wait until this movement is done before continuing

device.close()

Methods

  • Dobot(port, verbose=False) Creates an instance of dobot connected to given serial port.

    • port: string with name of serial port to connect
    • verbose: bool will print to console all serial comms
  • .pose() Returns the current pose of dobot, as a tuple (x, y, z, r, j1, j2, j3, j4)

    • x: float current x cartesian coordinate
    • y: float current y cartesian coordinate
    • z: float current z cartesian coordinate
    • r: float current effector rotation
    • j1: float current joint 1 angle
    • j2: float current joint 2 angle
    • j3: float current joint 3 angle
    • j4: float current joint 4 angle
  • .move_to(x, y, z, r, wait=False) queues a translation in dobot to given coordinates

    • x: float x cartesian coordinate to move
    • y: float y cartesian coordinate to move
    • z: float z cartesian coordinate to move
    • r: float r effector rotation
    • wait: bool waits until command has been executed to return to process
  • .speed(velocity, acceleration) changes velocity and acceleration at which the dobot moves to future coordinates

    • velocity: float desired translation velocity
    • acceleration: float desired translation acceleration
  • .suck(enable)

    • enable: bool enables/disables suction
  • .grip(enable)

    • enable: bool enables/disables gripper
  • .wait(ms) adds a waiting period to the internal queue of messages

    • ms: int number of milliseconds to wait

pydobot's People

Contributors

knutsun avatar ksketo avatar luismesas avatar remintz avatar retospect avatar zdenekm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pydobot's Issues

Dobot get lock when go to specific location

Hi,

I have question related to move dobot magician to specific location

when i try basic-example the dobot move according to current pose. However , when I try to put specific number such as



from serial.tools import list_ports

import pydobot

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

device = pydobot.Dobot(port=port, verbose=True)

(x, y, z, r, j1, j2, j3, j4) = device.pose()
print(f'x:{x} y:{y} z:{z} j1:{j1} j2:{j2} j3:{j3} j4:{j4}')

for i in range(2):
    device.move_to(x+2, y + 20 , z + 50 , r, wait=True) # first direction 
    device.wait(1000)
    device.move_to ( 20 , 40 , 50 , 0 , wait=True) # second direction 
    device.wait(1000)

device.close()

From above code , the first direction is ok , when robot move to second direction is get lock and won't move back to the first direction. I dont think the robot excess the direction limit . I go to dobot studio and test with the second direction , it could move to other direction I want.

Notice : I also try the software package , when i do similar position code , the robot is get lock with red indicator

I'm not sure what is the issue. Any suggestion ?

How could i write the new function like this.

dear,luismesas
Hi, I am an IT undergraduate student. I am very sorry to have disturbed you. But do want to go and know how to write a new function using the method you have adopted. If you can, could you take the time to explain it?

How to Set Jog Command ?

In the dType library , there is a set jog command where I could control jog by select the specific JOG . How could I add the set jog command in the library. I use the protocol and API user manual to set the function. The way I set similar to PTP command in pydobot library , except I change the protocol ID and control value to four . As the result, dobot not response or running. Any advice to add that function in library ?

When i try to move dobot it gives me an output

Exception in thread Thread-1:
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 810, in __bootstrap_inner
self.run()
File "/usr/local/lib/python2.7/dist-packages/pydobot/dobot.py", line 52, in run
self._get_pose()
File "/usr/local/lib/python2.7/dist-packages/pydobot/dobot.py", line 89, in _get_pose
response = self._send_command(msg)
File "/usr/local/lib/python2.7/dist-packages/pydobot/dobot.py", line 65, in _send_command
self._send_message(msg)
File "/usr/local/lib/python2.7/dist-packages/pydobot/dobot.py", line 74, in _send_message
self.ser.write(msg.bytes())
File "/usr/local/lib/python2.7/dist-packages/pydobot/message.py", line 36, in bytes
self.refresh()
File "/usr/local/lib/python2.7/dist-packages/pydobot/message.py", line 29, in refresh
self.checksum = self.checksum + int(self.params[i])
ValueError: invalid literal for int() with base 10: '['
Exception in thread Thread-1:
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 810, in __bootstrap_inner
self.run()
File "/usr/local/lib/python2.7/dist-packages/pydobot/dobot.py", line 52, in run
self._get_pose()
File "/usr/local/lib/python2.7/dist-packages/pydobot/dobot.py", line 89, in _get_pose
response = self._send_command(msg)
File "/usr/local/lib/python2.7/dist-packages/pydobot/dobot.py", line 65, in _send_command
self._send_message(msg)
File "/usr/local/lib/python2.7/dist-packages/pydobot/dobot.py", line 74, in _send_message
self.ser.write(msg.bytes())
File "/usr/local/lib/python2.7/dist-packages/pydobot/message.py", line 36, in bytes
self.refresh()
File "/usr/local/lib/python2.7/dist-packages/pydobot/message.py", line 29, in refresh
self.checksum += self.params[i]
TypeError: unsupported operand type(s) for +=: 'int' and 'str'

Reading Robot's Status/Error Messages

Hi,
I wanted to know if someone has an idea how to read the robots status/error messages (e.g. reaching an axis limit). I know that in _read_message() you could obtain the robot's msg but not how to extract an actual information from that return value.
Edit: I just saw that in the CommunicationProtocollDs.py the GET_ALARM_STATE msg.id exists. However I still don't know how to get an actual information out of the return value (that would look something like AA AA:3:50:0:00:206)

Dobot's inputs/outputs (request)

Would love to have this Python library with capable of controlling the Dobot's inputs/outputs. Such as controlling the Dobot's linear rail, Conveyor Belt, 3D printing, photoelectric switches, color sensors, and etc.

Thanks,
Steven

No port found for Dobot Magician

Hi, for some reason the port can't be found for the Dobot Magician. I have it connected to COM4 and I checked the connection, but the problem persists. Do you have suggestions? Thanks.

Controlling the Gripper

Is there any way to control the gripper (open, close)?

I can only enable it, but not open and close or disable it again. Is this method missing or am I missing something?
Thank you for your help!

Dobot does not respond with this library!

Hi @lusimesas, i am using Dobot black board, and as much as i would love to use your code to control Dobot, it wouldn't respond. Are there any setup steps i am missing?

I tried with 2.7 with errors, then i tried with 3.5 and there are no errors, the code runs but there is no response from Dobot.

How do i connect 2 or more robots to one PC?

I use pycharm and i can get along with 1 robot. It moves, but once i connect another dobot it doesnt work. They wont move and give errors sometimes. I've tried somethings I came up with, but Im still a nooby with python ;p.

Thanks in advance!

`from serial.tools import list_ports

from pydobot import Dobot

port = list_ports.comports()[0].device

port1 = list_ports.comports()[1].device

device2 = Dobot(port=port1)

device = Dobot(port=port)

pose = device.get_pose()

print(pose)

position = pose.position

device.move_to(position.x + 20, position.y, position.z, position.r)
device.move_to(position.x, position.y, position.z, position.r ) # we wait until this movement is done before continuing

device.move_to(position.x + 20, position.y, position.z, position.r)
device.move_to(position.x, position.y, position.z, position.r ) # we wait until this movement is done before continuing

device.move_to(position.x + 20, position.y, position.z, position.r)
device.move_to(position.x, position.y, position.z, position.r ) # we wait until this movement is done before continuing

print(list_ports.comports())

device.close()`

Cant run basic.py

Hi, I'm not an expert on python. I get this error message, does it say you anything?
Am I missing any pre-req? I installed the latest Dobot Studio.
Running this on my PC.

C:\Users\asif.mithawala\Desktop\pydobot>python basic.py
pydobot: COM3 open
pydobot: >> AA AA:2:240:1::15
pydobot: >> AA AA:2:245:1::10
pydobot: >> AA AA:34:80:3:00 00 48 43 00 00 48 43 00 00 48 43 00 00 48 43 00 00 48 43 00 00 48 43 00 00 48 43 00 00 48 43:85
pydobot: >> AA AA:18:81:3:00 00 48 43 00 00 48 43 00 00 48 43 00 00 48 43:128
pydobot: >> AA AA:10:82:3:00 00 20 41 00 00 48 43:191
pydobot: >> AA AA:10:83:3:00 00 C8 42 00 00 C8 42:150
pydobot: >> AA AA:2:10:0::246
Traceback (most recent call last):
File "basic.py", line 6, in
device = Dobot(port=port, verbose=True)
File "C:\Users\asif.mithawala\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pydobot\dobot.py", line 46, in init
self._get_pose()
File "C:\Users\asif.mithawala\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pydobot\dobot.py", line 102, in _get_pose
self.x = struct.unpack_from('f', response.params, 0)[0]
AttributeError: 'NoneType' object has no attribute 'params'

No Port found for Dobot Magician

Hey Luismesas,

i've installed all required files to my raspberry pi 3, but as soon as i start the sample.py, ig get this error-message.

Can you help me?

device.suck(1) doesn't turn on suction cup

I am trying to get the suction cup to turn on and off but de "device.suck(1) or device.suck(0)" has no effect. The suction cup does work in Dobot studio.

Here's my code:

import time
from glob import glob

from pydobot import Dobot

available_ports = glob('/dev/cu*usb*')  # mask for OSX Dobot port
if len(available_ports) == 0:
    print('no port found for Dobot Magician')
    exit(1)

device = Dobot(port=available_ports[0])

device.speed(300)

for i in range(1):
    device.suck(1)
    device.suck(0)
    
time.sleep(1)

device.close()

What am I doing wrong?

Function for Gripper

Hi, I can't seem to figure out the code for activating/deactivating the gripper. Here's the code that I've done so far:

def _set_end_effector_gripper(self, grip=False):
    msg = Message()
    msg.id = 63
    msg.ctrl = 0x03
    msg.params = bytearray([])
    msg.params.extend(bytearray([0x01]))
    if grip is True:
        msg.params.extend(bytearray([0x01]))
    else:
        msg.params.extend(bytearray([0x00]))
    return self._send_command(msg)

def grip(self, grip):
    self._set_end_effector_gripper(grip)

trouble with 'message' module

It appears that pydobot requires the 'message' module (https://pypi.org/project/message/), but every time I try to install it with pip, it fails with the following error:
AttributeError: partially initialized module 'message' has no attribute '__all__' (most likely due to a circular import)
easy_install returns the same error.

I'm running Python 3.8 on Windows 10 and also tried Python 3.5 in the WSL.

Has anyone else encountered this problem?

Creating an arc command

I would like to move the arm in an arc. Is this something you have considered implementing in the library? If I was going to do it myself, have you encountered any issues?

Dobot python Portrait

Hi, not sure if you can help but i need to write a code to image process a simple portrait from google and then code for the dobot arm to move accordingly.
Thank you

Error When Running the Demo

I used python3 to run the basic code, the code returned with "No module 'message'".
------------------ ENV ----------------------
Ubuntu 1804,
Python 3.6, python 3.8
------------------ Log ----------------------
Traceback (most recent call last):
File "/home/jeffery-hw/Desktop/MagneticManipulation/DobotController.py", line 3, in
from pydobot import Dobot
File "/home/jeffery-hw/anaconda3/lib/python3.8/site-packages/pydobot/init.py", line 1, in
from pydobot.dobot import Dobot
File "/home/jeffery-hw/anaconda3/lib/python3.8/site-packages/pydobot/dobot.py", line 7, in
from message import Message
ModuleNotFoundError: No module named 'message'

Then, I installed the message package and returned error as below:
I checked some answers on StackOverflow: it said I have some self-defined python filed called message, but actually my env is pure and I just reinstall my ubuntu system.

ERROR: Command errored out with exit status 1:
 command: /home/jeffery-hw/anaconda3/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-6pqjycwt/message/setup.py'"'"'; __file__='"'"'/tmp/pip-install-6pqjycwt/message/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-7pdeb4ce
     cwd: /tmp/pip-install-6pqjycwt/message/
Complete output (7 lines):
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/tmp/pip-install-6pqjycwt/message/setup.py", line 6, in <module>
    import message
  File "/tmp/pip-install-6pqjycwt/message/message/__init__.py", line 10, in <module>
    ] + message.__all__ + observable.__all__
AttributeError: partially initialized module 'message' has no attribute '__all__' (most likely due to a circular import)
----------------------------------------

ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

Exception when response empty

Hi,
After a few minutes with the Dobot Magician Lite I'm getting this exception, because of an empty response:

Traceback (most recent call last):
  File "direct_cords_read.py", line 81, in <module>
    device.move_to(current_x, y + draw_start_y, z_down, 0.0, wait=True)
  File "/home/pi/.local/lib/python3.7/site-packages/pydobot/dobot.py", line 315, in move_to
    self._set_ptp_cmd(x, y, z, r, mode=PTPMode.MOVL_XYZ, wait=wait)
  File "/home/pi/.local/lib/python3.7/site-packages/pydobot/dobot.py", line 240, in _set_ptp_cmd
    return self._send_command(msg, wait)
  File "/home/pi/.local/lib/python3.7/site-packages/pydobot/dobot.py", line 103, in _send_command
    expected_idx = struct.unpack_from('L', response.params, 0)[0]
AttributeError: 'NoneType' object has no attribute 'params'

I found this solution, and added the if clause in the middle:

    def _send_command(self, msg, wait=False):
        self.lock.acquire()
        self._send_message(msg)
        response = self._read_message()
        self.lock.release()
        if response is None:
            print("Receive empty response")
            return

        if not wait:
            return response

Best regards

dobot is connect with windows laptop

pydobot: COM3 open
pydobot: >> AAAA:18:81:3:00004843000048430000484300004843:128
pydobot: >> AAAA:10:83:3:0000484300004843:148
Traceback (most recent call last):
File "", line 1, in
File "C:\python3\lib\site-packages\pydobot\dobot.py", line 47, in init
self._set_ptp_common_params(velocity=200.0, acceleration=200.0)
File "C:\python3\lib\site-packages\pydobot\dobot.py", line 132, in _set_ptp_common_params
return self._send_command(msg)
File "C:\python3\lib\site-packages\pydobot\dobot.py", line 66, in _send_command
response = self._read_message()
File "C:\python3\lib\site-packages\pydobot\dobot.py", line 80, in _read_message
msg = Message(b)
File "C:\python3\lib\site-packages\pydobot\message.py", line 11, in init
self.len = b[2]
IndexError: index out of range

Jogging Function

Hello,
I was wondering if it's possible to add a function for using the jogging feature of the robot. Would anyone have an idea what the message you send to the robot would need to look like? From looking at the CommunicationProtocollDs.py I would guess that the msg.id would be something like 73, however I don't know about the params and the rest of the message.
Any help would be much appreciated.

Clear the Alarm

Is there any way that can clear the alarm

Python code will not work unless resetting the Dobot Magician's current alarm

I don't think this library built-in with Alarm commands yet.

Thanks in advance

Pydobot Gripper Issue (Cannot Disable Gripper)

Hi,

Is there currently a way to disable the gripper attachment once it has been activated? Currently I am only able to open and close the gripper, but not able to fully release. Thanks!

pydobot installation

Hello,

I am trying to install pydobot with "pip install pydobot" command.
It seems that there are some prerequisites.
I get errors and I already installed the packages wheel, observable and I cannot install the package message.

I have
Windows 10 64-bit
Python 3.8.1 64-bit
pip 20.1

So, which are the prerequisites?
Do I have any problems because of the versions of my OS/Python/pip?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.