Coder Social home page Coder Social logo

uarm-python-sdk's Introduction

uArm-Python-SDK


Overview

This module encapsulates the operations for uArm. It provides basic movement on Python. The library only supports uArm Swift/SwiftPro. For Metal, please use pyuarm or pyuf instead.

Related

Update Summary for 2.0

  • Support multi-machine synchronization.
  • New Support Swift Pro firmware V4.0 or later.
  • Supoort event callback register and release.
  • Support api callback.
  • Support more custom configuration.
  • Better in management threads.
  • Easy to use.

Caution

  • Temporarily only supports Swift / SwiftPro.
  • Temporarily only supports Python3 (development is python3.5).
  • if your uArm's firmware is 4.0 or later, please set the speed between 1 to 250, or with the api set_speed_factor to fix.
  • Make sure you move the device head to a safe position and completely quit uArm Studio before running the tests.

Installation

python setup.py install
  • Install is not necessary, you can run examples without installation.

Doc

Example:

Import

from uarm.wrapper import SwiftAPI
swift = SwiftAPI()
swift = SwiftAPI(filters={'hwid': 'USB VID:PID=2341:0042')
swift = SwiftAPI(filters={'hwid': 'USB VID:PID=2341:0042', do_not_open=true)
swift = SwiftAPI(filters={'hwid': 'USB VID:PID=2341:0042', cmd_pend_size=2)
swift = SwiftAPI(filters={'hwid': 'USB VID:PID=2341:0042', enable_write_thread=True)
swift = SwiftAPI(filters={'hwid': 'USB VID:PID=2341:0042', enable_handle_report_thread=True)
swift = SwiftAPI(filters={'hwid': 'USB VID:PID=2341:0042', enable_write_thread=True, enable_handle_report_thread=True)
swift = SwiftAPI(filters={'hwid': 'USB VID:PID=2341:0042', callback_thread_pool_size=10)
swift = SwiftAPI(filters={'hwid': 'USB VID:PID=2341:0042', callback_thread_pool_size=1)
swift = SwiftAPI(filters={'hwid': 'USB VID:PID=2341:0042', callback_thread_pool_size=10)

Wait

swift.waiting_ready()
swift.flush_cmd()

Connect/Disconnect

swift.connect()
swift.disconnect()

Get

swift.get_power_status()
swift.get_device_info()
swift.get_limit_switch()
swift.get_gripper_catch()
swift.get_pump_status()
swift.get_mode()
swift.get_servo_attach(servo_id=2)
swift.get_servo_angle()
swift.get_polar()
swift.get_position()
swift.get_analog(0)
swift.get_digital(0)

Set

swift.set_speed_factor(1)
swift.set_mode(mode=0)
swift.set_wrist(90)
swift.set_servo_attach()
swift.set_servo_detach()
swift.set_buzzer(frequency=1000, duration=2)
swift.set_pump(on=True)
swift_set_gripper(catch=True)

Move

swift.reset()
swift.set_position(x=200, y=0, z=100, speed=100000)
swift.set_polar(stretch=200, rotation=90, height=150)
swift.set_servo_angle(servo_id=0, angle=90)

Event register/release

swift.register_report_position_callback(callback)
swift.release_report_position_callback(callback)
swift.set_report_position(0.5)

API callback

swift.get_polar(wait=False, callback=lambda i: print('polar', i))
swift.get_position(wait=False, callback=lambda i: print('pos', i))

License

uArm-Python-SDK is published under the BSD license

uarm-python-sdk's People

Contributors

huttonge avatar topgunzh avatar tpoliaw avatar vimior 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

Watchers

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

uarm-python-sdk's Issues

Set_servo_angle and go down

Hello, I am having issues figuring out how to set servo angle at 180° and then go down with the arm. I need it to not bet set_positon and then servo angle, need it servo agle and then go down.

Thanks

uArm is not connected when using python sdk

When using this sdk to control uArm Swift Pro, there are several problems:

  1. It takes 30 secs to 1 minute for the arm to move.
  2. The error "uArm is not connected" happens quite frequently, but uArm Studio works well at the same time.
  3. The running results of the same test file(.py) are not consistent, sometimes it works just right, but sometimes the arm moves too fast, and the arm may replay the commands I sent in the previous run.

Moreover, these problems also exist when I run your pressure test file, so I don't know whether the python sdk can work anymore. If not, should I turn to use Arduino or something else? I need to control the arm with small latency and stability.

Swift Pro exception thrown 'device reports readiness to read but returned no data'

Whenever I start up my server that connects to my Swift Pro, I do this:

  # setup arm
  sys.path.append(os.path.join(os.path.dirname(__file__), '../..'))
  swift = SwiftAPI() # default by filters: {'hwid': 'USB VID:PID=2341:0042'}
  print('sleep 2 sec ...')
  sleep(2)
  print('device info: ')
  print(swift.get_device_info())

And the following happens:

Exception in thread Thread-2:
Traceback (most recent call last):
  File "/Users/njonas/.pyenv/versions/3.6.1/lib/python3.6/site-packages/pyserial-3.4-py3.6.egg/serial/serialposix.py", line 501, in read
    'device reports readiness to read but returned no data '
serial.serialutil.SerialException: device reports readiness to read but returned no data (device disconnected or multiple access on port?)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/njonas/.pyenv/versions/3.6.1/lib/python3.6/threading.py", line 916, in _bootstrap_inner
    self.run()
  File "/Users/njonas/.pyenv/versions/3.6.1/lib/python3.6/site-packages/pyuf-1.3-py3.6.egg/uf/comm/serial_ascii.py", line 44, in run
    line = self.com.readline()
  File "/Users/njonas/.pyenv/versions/3.6.1/lib/python3.6/site-packages/pyserial-3.4-py3.6.egg/serial/serialposix.py", line 509, in read
    raise SerialException('read failed: {}'.format(e))
serial.serialutil.SerialException: read failed: device reports readiness to read but returned no data (device disconnected or multiple access on port?)

And I also get this timeout:

cmd "#1 G0 Z40 F5000" timeout

It still works, but was wondering what this all meant and if there was a way to avoid it?

Thanks!

Work with Python 11

Does it work with Python 11?

I noticed some code with latest python async syntax

`

    # @staticmethod
    # @asyncio.coroutine
    # def _async_run_callback(callback, msg):
    #     yield from callback(msg)

    @staticmethod
    async def _async_run_callback(callback, msg):
        await callback(msg)

`

But even that, init error.

Arm steps to end position rather than going there in a single smooth motion

When using the set_position() function, the arm goes to the end position in a number of noticeable discrete steps rather than in a single smooth motion. In other words, the arm executes part of the motion, stops and then executes another step.

This is behavior is not observed when using the Armstudio software. Therefore, I assume this is a bug.

Swift.get_device_info() can not be run

Hello. At first, I would like to say "thank you for your development of pyuf".
I tried to run "test_swift_api.py".
But, it will not proceed after "device info:" is printed. (swift.get_device_info())
Please tell me the solution to run "test_swift_api.py".

The system and environment are as follows:
0. Windows10, and laptop

  1. Anaconda3 (python3.6.3)
  2. uArm Swift (not Pro)

As a supplement, I can control uArm Swift with UarmStudio.

set_position suddenly stops working with x & y parameters

After working for about 4 hours with the Swift Pro and the Python library, it all of a sudden stops responding to set_position when the x and y are set, but if only the z is set, it's fine.

if __name__ == '__main__':
  print("setting up Swift...")
  sys.path.append(os.path.join(os.path.dirname(__file__), '../..'))
  swift = SwiftAPI()
  sleep(2)
  response = swift.set_position(x=0, y=0, z=45, relative=False, wait=False, speed=5, timeout=10)
  print(response)

Note response is always True, but the arm doesn't move.

If I do the following, without the x and y, the arm moves up just fine:

 response = swift.set_position(z=45, relative=False, wait=False, speed=5, timeout=10)

I've tried turning it on and off, replugging it in, recalibrating, but it still doesn't work.

Does anyone know why this might happen? Again, this has been working all day but suddenly stopped.

Certain Marlin commands don't work

Hi,
since the uArm firmware is based on Marlin, but has implemented its own way of numbering commands, any Marlin commands that do not have this feature enabled will not work with this python library, even though they work when sent directly.

e.g. if I call send_cmd_sync('M105'), the python library will append #N and expect $N in return, but since it's a Marlin command, it only return ok T:23.3 /0.0 @:0 which means that the library will think that the firmware never actually responded.

I could solve this by modifying packed_in_cb in protocol_ascii.py like so, but it only works if there are no other commands pending.

    def packet_in_cb(self, msg):
        #print('{}: <- '.format(self.node) + msg)
        if len(msg) < 2:
            return
        if msg[0:1] == '@':
            if self.ports['report']['handle']:
                self.logger.log(logging.VERBOSE, 'report: ' + msg)
                self.ports['report']['handle'].publish(msg[1:])
        elif msg[0:1] == '$':
            index = msg.find(' ')
            index = index if index != -1 else len(msg)
            cnt = int(msg[1:index])
            if cnt in self.cmd_pend.keys():
                # TODO: avoid KeyError
                self.cmd_pend[cnt].finish(msg[index + 1:])
            else:
                pass # warning...
        elif msg[0:2] == 'ok' and len(self.cmd_pend) == 1:
            cnt = list(self.cmd_pend)[0]
            self.cmd_pend[cnt].finish(msg)

Let me know if you would like me to submit a PR.

Communication Problem-Port does not found

Hello I am having communication issue with between robot and code. I always have **port does not found** error. How can I solve this problem and how can I find port name ? Thank you

Screenshot 2022-10-04 142556

set_pump blocks the thread

Everytime I call set_pump(True) the Thread hangs for several seconds until I get
swift_api: WARNING: set_pump ret: err, timeout for on, last ret: ok V1

In in the documentation it says timeout is not supported. I think it would be a very important feature because in this state the pump is not usable in Python.

KeyError - Swift Pro

I'm trying to both start a web server and talk to the Swift Pro so on certain POST requests I can call
a series of set_position commands.

I don't really know what this error means, but I'm getting it from trying something pretty simple:

 * Running on http://localhost:8080/ (Press CTRL+C to quit)
 * Restarting with stat
setting up Swift...
Exception in thread Thread-14:
Traceback (most recent call last):
  File "/Users/njonas/.pyenv/versions/3.6.1/lib/python3.6/threading.py", line 916, in _bootstrap_inner
    self.run()
  File "/Users/njonas/.pyenv/versions/3.6.1/lib/python3.6/threading.py", line 1182, in run
    self.function(*self.args, **self.kwargs)
  File "<my_project_path>/uf/comm/protocol_ascii.py", line 66, in timeout_cb
    self.delete() # TODO: avoid KeyError if the 'finish' called at same time
  File "<my_project_path>/uf/comm/protocol_ascii.py", line 53, in delete
    del self.owner.cmd_pend[self.cnt]
KeyError:

And this is what I'm doing to get this error:

# setup arm
print("setting up Swift...")
sys.path.append(os.path.join(os.path.dirname(__file__), '../..'))
swift = SwiftAPI() # default by filters: {'hwid': 'USB VID:PID=2341:0042'}

sleep(2)

if True != swift.set_position(z = RAISED_Z, relative = False, wait = True, speed = SPEED, timeout = 0):
  print("Set position failed!")

swift.flush_cmd()
sleep(1)

if __name__ == '__main__':
    run_simple('localhost', 8080, app, use_reloader=True, use_debugger=True)

Error in reset function

The reset function tries to shut off the pump and close the gripper. Even if these are not attached, this leads to a timeout error. The bug is in the pyuf\uf\wrapper\swift_api.py file and in the reset function

self.set_pump(False)
self.set_gripper(False)

get_position only works when servos are attached.

Hi,
I noticed in uArm Studio, when you click on the Move command and it tells you to "Drag uArm to a destination", it shows you the X, Y and Z coordinates as you are moving it, but I am unable to use pyuf to get these coordinates using swift.get_position() while the servos are detached. I can only get the position when I attach the servos.
I noticed that while P2220 doesn't change while servos are detached, the values P2242 do change.
Is the client functioning as intended?
If so, is there a way to easily convert between B,L,R -> X,Y,Z ?

Here is my device info from pyuf:
['SwiftPro', '3.3.0', '3.1.9', '3.1.9', 'D43639DF6537']
I am using uArm Studio v1.1.12 with firmware v3.1.9

Thanks

Failure to execute movement commands under certain circumstances

I've been having trouble getting the robot to execute a series of actions. It moves to the first position perfectly, but after that refuses to move any further. The set_position calls all immediately return true, even with wait enabled.
After comparing my code to the samples, I found what seems to be a bug (as I can see no obvious explanation for it. Using the following code, setting the initial Z value greater than 197 causes the arm to ignore all subsequent set_position calls.

import sys
import numpy as np
from time import sleep

from uf.wrapper.swift_api import SwiftAPI
from uf.utils.log import *
logger_init(logging.INFO)

uarm = SwiftAPI()
sleep(2.0)

uarm.set_position(350, 0, 197, speed = 1500, timeout = 20)
uarm.flush_cmd()
uarm.set_position(x = 300)
#uarm.set_position(x = 190)
uarm.flush_cmd()
print('done ...')
while True:
    sleep(1)

Furthermore, removing the 2nd or 3rd set_position call yields a similar result: the robot does not move after reaching the first position.

Is there an explanation for these issues that I've overlooked? It seems that I'm running into issues with limits of the arm's range of motion, but the thresholds are much smaller than the actual physical range. On top of that, requesting positions beyond these threshold is handles differently for each axis (On the X axis, get_position never returns anything higher than 300. Calling set_position with a value outside that threshold does not cause anything to fail; it simply stops the arm at the edge.)

SDK is very inconsistent

When I run the tests, half the time they pass, half the time they fail.

The move test task 30-45 seconds to start.
When using uArm studio, the latency is less than a second.

Why on earth is this SDK so unreliable?

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.