Skip to main content

Python bindings for WujiHandCpp

Project description

WujihandPy: Python bindings for WujiHandCpp

WujihandPy 是 WujiHandCpp 的 Python 绑定。

提供更简洁、更高效、更易用的接口与灵巧手设备进行交互。

安装

WujihandPy 支持 pip 一键安装:

pip install wujihandpy

对于 Linux 用户,需要额外配置 udev 规则以允许非 root 用户访问 USB 设备,可在终端中输入:

echo 'SUBSYSTEM=="usb", ATTR{idVendor}=="0483", ATTRS{idProduct}=="5740", MODE="0666"' |
sudo tee /etc/udev/rules.d/95-wujihand.rules &&
sudo udevadm control --reload-rules &&
sudo udevadm trigger

支持的 CPU 架构

  • x86_64
  • ARM64

最低系统要求 (Linux)

glibc 2.28+

使用 glibc 2.28 或更高版本的 Linux 发行版:

  • Debian 10+
  • Ubuntu 18.10+
  • Fedora 29+
  • CentOS/RHEL 8+

Python 3.8+

支持以下 Python 版本:

  • Python 3.8-3.14

最低系统要求 (Windows)

WujihandPy 目前暂不支持 Windows,我们会尽快推进相关支持。

示例代码

所有示例代码均位于 example 目录下。

部分参考 API

导入模块

import wujihandpy
import numpy as np

连接至灵巧手

hand = wujihandpy.Hand()

读数据

def read_<dataname>(self) -> np.<datatype>
def read_<dataname>(self) -> np.array<datatype> # For bulk-read

所有可使用的数据均定义在 wujihandpy/_core.pyi 中。

例如,读取灵巧手的上电运行时间(us):

time = hand.read_system_time()

除整手唯一的数据外,每个关节也有自己的数据,数据名称均以 joint 作为开头。

例如,读取第1个手指(食指),第0个关节的当前位置数据:

position = hand.finger(1).joint(0).read_joint_position()

用一条指令读取多个数据也是可行的,这被称为批量读 (Bulk-Read)

例如,以下指令读取整手所有(20个)关节的当前位置数据:

positions = hand.read_joint_position()

进行批量读时,函数返回包含所有数据的 np.array

>>> np.set_printoptions(formatter={'int': lambda x: hex(x)})
>>> print(positions)
[[0x200828 0x2062D3 0x20186B 0x200535]
 [0xDFFE7A 0xBF2318 0x7FC3C2 0x802342]
 [0xE01213 0x900C79 0x3FB49B 0x60191E]
 [0xE04051 0x601EFB 0x4035B6 0x60026B]
 [0xDFD9AC 0x3FA315 0x4015C2 0x5FDF6A]]

read 函数会阻塞,直到读取完成。保证当函数返回时,读取一定成功。

写数据

写数据拥有类似的API,但多了一个参数用于传递目标值:

def write_<dataname>(self, np.<datatype>)
def write_<dataname>(self, np.array<datatype>) # For bulk-write

例如,写入单个关节的目标位置数据:

hand.finger(1).joint(0).write_joint_control_position(np.int32(0x800000))

关节位置的合法范围为 [0x000000, 0xFFFFFF]

批量写数据也是可行的,例如,批量写入第1个手指的目标位置数据:

hand.finger(1).write_joint_control_position(np.int32(0x800000))

如果每个关节的目标值不同,可以传入一个包含所有目标值的 np.array

hand.finger(1).write_joint_control_position(
    np.array(
        #   J1        J2        J3        J4
        [0xDFFFFF, 0xBFFFFF, 0x400000, 0x600000],
        dtype=np.int32,
    )
)

write 函数会阻塞,直到写入完成。保证当函数返回时,写入一定成功。

异步读/写

读写函数均有对应的异步版本,函数名以 _async 作为后缀。

async def read_<dataname>_async(self) -> np.<datatype>
async def read_<dataname>_async(self) -> np.array<datatype> # For bulk-read
async def write_<dataname>_async(self, np.<datatype>)
async def write_<dataname>_async(self, np.array<datatype>)  # For bulk-write

异步读/写函数同样会异步阻塞,直到读/写完成。保证当函数返回时,读/写一定成功。

Unchecked 读/写

如果不关心读/写是否成功,可以使用 Unchecked 版本的读/写函数,函数名以 _unchecked 作为后缀。

def read_<dataname>_unchecked(self) -> np.<datatype>
def read_<dataname>_unchecked(self) -> np.array<datatype> # For bulk-read
def write_<dataname>_unchecked(self, np.<datatype>)
def write_<dataname>_unchecked(self, np.array<datatype>)  # For bulk-write

Unchecked 函数总是立即返回,不会阻塞,通常用于对实时性要求较高的场景。

Get

如果希望获取以往读/写的结果,可以使用 get 系列函数:

def get_<dataname>(self) -> np.<datatype>
def get_<dataname>(self) -> np.array<datatype> # For bulk-read

get 系列函数同样不会阻塞,它总是立即返回最近一次读取到的数据,无论该数据来自 readasync-read 还是 read-unchecked

如果尚未请求过该数据,或请求尚未成功,get 函数的返回值是未定义的(通常为0)。

性能与优化

WujihandPy 在充分保证易用性的同时,尽可能优化了性能与效率。

我们强烈建议优先使用批量读/写以最大限度地发挥性能。

许可证

本项目采用 MIT 许可证,详情见 LICENSE 文件。

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

wujihandpy-0.2.1-cp314-cp314t-manylinux_2_28_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.14tmanylinux: glibc 2.28+ x86-64

wujihandpy-0.2.1-cp314-cp314t-manylinux_2_28_aarch64.whl (1.1 MB view details)

Uploaded CPython 3.14tmanylinux: glibc 2.28+ ARM64

wujihandpy-0.2.1-cp314-cp314-manylinux_2_28_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.28+ x86-64

wujihandpy-0.2.1-cp314-cp314-manylinux_2_28_aarch64.whl (1.1 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.28+ ARM64

wujihandpy-0.2.1-cp313-cp313t-manylinux_2_28_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.13tmanylinux: glibc 2.28+ x86-64

wujihandpy-0.2.1-cp313-cp313t-manylinux_2_28_aarch64.whl (1.1 MB view details)

Uploaded CPython 3.13tmanylinux: glibc 2.28+ ARM64

wujihandpy-0.2.1-cp313-cp313-manylinux_2_28_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ x86-64

wujihandpy-0.2.1-cp313-cp313-manylinux_2_28_aarch64.whl (1.1 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ ARM64

wujihandpy-0.2.1-cp312-cp312-manylinux_2_28_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64

wujihandpy-0.2.1-cp312-cp312-manylinux_2_28_aarch64.whl (1.1 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ ARM64

wujihandpy-0.2.1-cp311-cp311-manylinux_2_28_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64

wujihandpy-0.2.1-cp311-cp311-manylinux_2_28_aarch64.whl (1.1 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ ARM64

wujihandpy-0.2.1-cp310-cp310-manylinux_2_28_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

wujihandpy-0.2.1-cp310-cp310-manylinux_2_28_aarch64.whl (1.1 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ ARM64

wujihandpy-0.2.1-cp39-cp39-manylinux_2_28_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.28+ x86-64

wujihandpy-0.2.1-cp39-cp39-manylinux_2_28_aarch64.whl (1.1 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.28+ ARM64

wujihandpy-0.2.1-cp38-cp38-manylinux_2_28_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.8manylinux: glibc 2.28+ x86-64

wujihandpy-0.2.1-cp38-cp38-manylinux_2_28_aarch64.whl (1.1 MB view details)

Uploaded CPython 3.8manylinux: glibc 2.28+ ARM64

File details

Details for the file wujihandpy-0.2.1-cp314-cp314t-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for wujihandpy-0.2.1-cp314-cp314t-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 3ad45d911cd69de9a0f1df5d04ef05e309db80d96b685d19d801c29a8dfb2aa1
MD5 45123465c31cca5716d4735ae95b5249
BLAKE2b-256 20d5e53a9107a89a71ffb23f7b831f864b3dbf8b2c67fc64eccf9d1a160bdf8e

See more details on using hashes here.

File details

Details for the file wujihandpy-0.2.1-cp314-cp314t-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for wujihandpy-0.2.1-cp314-cp314t-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 529f3fba2fa8d9ee8a4357ed556c0fa7d68b595a79486ba86858905411924eb2
MD5 3533fa81cd876320b32719a7502de767
BLAKE2b-256 222937c1bd9865fd1aaec9885926ee306e2ef68d11144288a5195f52b4450a7b

See more details on using hashes here.

File details

Details for the file wujihandpy-0.2.1-cp314-cp314-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for wujihandpy-0.2.1-cp314-cp314-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 3cb762cb8289121136a59f3fcd80bb018d1a7106a32155bb1993989b4dd27267
MD5 16eabbcc16e09d65a2d7c6d177d0db5f
BLAKE2b-256 b8feebf4af8d2b9a5554ce43277969504aa1c4969f92981caf524f661997db9d

See more details on using hashes here.

File details

Details for the file wujihandpy-0.2.1-cp314-cp314-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for wujihandpy-0.2.1-cp314-cp314-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 b0dc781f7e9b42604d0c756d22c19bb3d52236df320203e3f40bc1557aa96556
MD5 129ea66974180a7c8daf7e280267703b
BLAKE2b-256 a380323a5866f489ff1abb086b0847bd050e1d447f085e6980ca2afa884b7dbf

See more details on using hashes here.

File details

Details for the file wujihandpy-0.2.1-cp313-cp313t-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for wujihandpy-0.2.1-cp313-cp313t-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 2ac02df88d5e9387e75281f9c1eabdd3dace7d30752a56ffa30ec057fd41a370
MD5 cd41236bfd11370890dee3c51bc63c9b
BLAKE2b-256 5a105b7f15d5f726e62f83dda200e5645e0362bfd9679b5b703b92db216fc7ba

See more details on using hashes here.

File details

Details for the file wujihandpy-0.2.1-cp313-cp313t-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for wujihandpy-0.2.1-cp313-cp313t-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 b22b41881ff0465af87eb9ee12f34227149955c211bf15b7ecdc4868e55400db
MD5 d186adcfd341cfb8874047bce4b31a98
BLAKE2b-256 93bfdecf2d6762e8cd3e63f7133b1b1c1c1bbd3829f17a6ee9e2e6a8e5e107c2

See more details on using hashes here.

File details

Details for the file wujihandpy-0.2.1-cp313-cp313-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for wujihandpy-0.2.1-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 0ef9628196c3daf1df7ba1860cc25e560125a2bf9079f3525f198dd61deccdfa
MD5 e7740dc5b2b47b56b5b14673be559e5c
BLAKE2b-256 ffba3f385d80dcfdf7389a0c07b59317f74b1a02e52d0bbc4e27aa8557e450e3

See more details on using hashes here.

File details

Details for the file wujihandpy-0.2.1-cp313-cp313-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for wujihandpy-0.2.1-cp313-cp313-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 caa56b3031f530d93cc107791024d6512c72b31dc8a883f1ec07edb45ece5264
MD5 1e6b02cc63eb878711f1bfee600d7afb
BLAKE2b-256 770481abe28f489047f1d54f8b203068f34c2c7c4016e24b8f3c69c9681858df

See more details on using hashes here.

File details

Details for the file wujihandpy-0.2.1-cp312-cp312-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for wujihandpy-0.2.1-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 1ee67d23c0eb3b6229f4c479641b31150bed0609bbb24e9b38e5d8672bb31890
MD5 0b0d359d1c9abea4856ba80af2e0fce8
BLAKE2b-256 3e291d61304af6364a1491139553745b66ea8cbf3dbbfee470b7861510446731

See more details on using hashes here.

File details

Details for the file wujihandpy-0.2.1-cp312-cp312-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for wujihandpy-0.2.1-cp312-cp312-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 58eea0b5a3fc4fc7262df779d6ebe6599ff4966237f7740b772c509fbf7653ed
MD5 4ce560f4075bce41da75071a66153ef5
BLAKE2b-256 b00cc637a1e2c8d7ac937d4ce706d1acd96ca5abc9f3f708c7ab25fac41a519b

See more details on using hashes here.

File details

Details for the file wujihandpy-0.2.1-cp311-cp311-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for wujihandpy-0.2.1-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 1eaa0c3e0169430db4596215b9f7214f67f112ac56b0c3d7d01de31604c129c4
MD5 82ed470a05b2578ea9a1b902e4788592
BLAKE2b-256 a16b626e3b86e93abb24fcd1c0ba82ff56b37482dc22956d913e48f05d242f0e

See more details on using hashes here.

File details

Details for the file wujihandpy-0.2.1-cp311-cp311-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for wujihandpy-0.2.1-cp311-cp311-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 9b99e720a4bfaa81263866fae0087596d23d23e8e277628492e761f26944d0ff
MD5 11121570b4869684a66fac01e5bedbcf
BLAKE2b-256 7dceb1d17339f1006e7d58996facf9233d614836ffdcf01f98243a8d29ae750f

See more details on using hashes here.

File details

Details for the file wujihandpy-0.2.1-cp310-cp310-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for wujihandpy-0.2.1-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 b82bf252094bbc5a34e17d5edc125b3ddd1c82ccb18351322bd221999f90d164
MD5 e99a19ce230b85afe3e55ec3c4d671be
BLAKE2b-256 4c4ef14fbd80f1d59a15fd859b9a2f0f4673ad1e943b5b59936cc5170078cb7c

See more details on using hashes here.

File details

Details for the file wujihandpy-0.2.1-cp310-cp310-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for wujihandpy-0.2.1-cp310-cp310-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 d85b9a4d2178a75c3d724131dab6a2b948b387bc7887879a7245a7f222370b4a
MD5 c35df1d75cfa1856e47578630d7094e2
BLAKE2b-256 eef48a90a597db9c4e6d023946db5c6e913e1fc9e49a30fe2f2ab1bb53e6e464

See more details on using hashes here.

File details

Details for the file wujihandpy-0.2.1-cp39-cp39-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for wujihandpy-0.2.1-cp39-cp39-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 4bc68372966ad183796a73544c6b6d70e6da41b417d6ddfa3285457096ed9814
MD5 6ca105c784838a555be2aa1e5870f858
BLAKE2b-256 2ae7d94b45e19f95652cd6f8bb4d4ad23808d504b1d333733f2ac30831e4078c

See more details on using hashes here.

File details

Details for the file wujihandpy-0.2.1-cp39-cp39-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for wujihandpy-0.2.1-cp39-cp39-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 25ae5f635c776e9bc43ddd29bd9e36240c58444e290d77768b820a6c06c4e7cb
MD5 9dd01c744293b4648bce0eea0f119dd5
BLAKE2b-256 17359145a42c1bacec8048b1bd140e2d0bad087d8c76311d4ea5ea42d6101c45

See more details on using hashes here.

File details

Details for the file wujihandpy-0.2.1-cp38-cp38-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for wujihandpy-0.2.1-cp38-cp38-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 6ff6f142f606db7107bcc71f3bd18eab4cd8f516e7abfd5cdd9a3e3450141a32
MD5 c917a7142430f07058beaddb64b5e60f
BLAKE2b-256 f6b469c9cfd4620b9306ca3f79d2b350bd92e7729eed93b449a8385dd479bbfc

See more details on using hashes here.

File details

Details for the file wujihandpy-0.2.1-cp38-cp38-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for wujihandpy-0.2.1-cp38-cp38-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 584d5af6adf938ac7e2536024ee4da97eced2489a4308a6c4d83f50827e42200
MD5 9877f1ca1633db18838b7e86deb0258e
BLAKE2b-256 23f8a2ec22d01dc8646a339a9c7afd2c99c7a80a8d31ccbf37661240f2f65d28

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page