Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,6 @@ __pycache__
.idea/

# python
dist/
dist/

uv.lock
31 changes: 29 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,30 @@
[project]
name = "unitree_sdk2py"
version = "1.0.1"
description = "Unitree robot sdk version 2 for python"
readme = { file = "README.md", content-type = "text/markdown" }
requires-python = ">=3.9"
license = { text = "BSD-3-Clause" }
authors = [
{ name = "UnitreeRobotics", email = "[email protected]" }
]
dependencies = [
"cyclonedds @ https://github.com/carlosdp/cyclonedds-python/releases/download/0.10.5/cyclonedds-0.10.5-cp312-cp312-macosx_10_9_x86_64.whl ; platform_system == 'Darwin' and platform_machine == 'x86_64'",
"cyclonedds @ https://github.com/carlosdp/cyclonedds-python/releases/download/0.10.5/cyclonedds-0.10.5-cp312-cp312-macosx_11_0_arm64.whl ; platform_system == 'Darwin' and platform_machine == 'arm64'",
"cyclonedds @ https://github.com/carlosdp/cyclonedds-python/releases/download/0.10.5/cyclonedds-0.10.5-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl ; sys_platform == 'linux' and platform_machine == 'aarch64'",
"cyclonedds @ https://github.com/carlosdp/cyclonedds-python/releases/download/0.10.5/cyclonedds-0.10.5-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl ; sys_platform == 'linux' and platform_machine == 'x86_64'",
"fastcrc>=0.3.2",
"numpy",
"opencv-python",
]

[project.urls]
"Source Code" = "https://github.com/unitreerobotics/unitree_sdk2_python"

[build-system]
requires = ["setuptools", "wheel"]
build-backend = "setuptools.build_meta"
requires = ["setuptools>=64", "wheel"]
build-backend = "setuptools.build_meta"

[tool.setuptools.packages.find]
include = ["unitree_sdk2py", "unitree_sdk2py.*"]

21 changes: 0 additions & 21 deletions setup.py

This file was deleted.

Empty file added unitree_sdk2py/b2/__init__.py
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file added unitree_sdk2py/comm/__init__.py
Empty file.
Empty file added unitree_sdk2py/g1/__init__.py
Empty file.
Empty file.
Empty file.
Empty file.
Empty file added unitree_sdk2py/h1/__init__.py
Empty file.
Empty file.
Empty file added unitree_sdk2py/test/__init__.py
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
55 changes: 9 additions & 46 deletions unitree_sdk2py/utils/crc.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
import struct
import cyclonedds
import cyclonedds.idl as idl
from fastcrc import crc32

from .singleton import Singleton
from ..idl.unitree_go.msg.dds_ import LowCmd_
from ..idl.unitree_go.msg.dds_ import LowState_

from ..idl.unitree_hg.msg.dds_ import LowCmd_ as HGLowCmd_
from ..idl.unitree_hg.msg.dds_ import LowState_ as HGLowState_
import ctypes
import os
import platform

class CRC(Singleton):
def __init__(self):
Expand All @@ -25,17 +22,6 @@ def __init__(self):
self.__packFmtHGLowState = '<2I2B2xI' + '13fh2x' + 'B3x4f2hf7I' * 35 + '40B5I'


script_dir = os.path.dirname(os.path.abspath(__file__))
self.platform = platform.system()
if self.platform == "Linux":
if platform.machine()=="x86_64":
self.crc_lib = ctypes.CDLL(script_dir + '/lib/crc_amd64.so')
elif platform.machine()=="aarch64":
self.crc_lib = ctypes.CDLL(script_dir + '/lib/crc_aarch64.so')

self.crc_lib.crc32_core.argtypes = (ctypes.POINTER(ctypes.c_uint32), ctypes.c_uint32)
self.crc_lib.crc32_core.restype = ctypes.c_uint32

def Crc(self, msg: idl.IdlStruct):
if msg.__idl_typename__ == 'unitree_go.msg.dds_.LowCmd_':
return self.__Crc32(self.__PackLowCmd(msg))
Expand Down Expand Up @@ -192,37 +178,14 @@ def __Trans(self, packData):

return calcData

def _crc_py(self, data):
bit = 0
crc = 0xFFFFFFFF
polynomial = 0x04c11db7

for i in range(len(data)):
bit = 1 << 31
current = data[i]

for b in range(32):
if crc & 0x80000000:
crc = (crc << 1) & 0xFFFFFFFF
crc ^= polynomial
else:
crc = (crc << 1) & 0xFFFFFFFF
def __Crc32(self, data):
return crc32.mpeg_2(words_to_bytes(data))

if current & bit:
crc ^= polynomial

bit >>= 1

return crc
def words_to_bytes(data):
"""
Convert a list of 32-bit integers (data[i]) into bytes,
in big-endian order, matching the _crc_py bit processing.
"""
return b"".join(word.to_bytes(4, byteorder="big") for word in data)

def _crc_ctypes(self, data):
uint32_array = (ctypes.c_uint32 * len(data))(*data)
length = len(data)
crc=self.crc_lib.crc32_core(uint32_array, length)
return crc

def __Crc32(self, data):
if self.platform == "Linux":
return self._crc_ctypes(data)
else:
return self._crc_py(data)
Binary file removed unitree_sdk2py/utils/lib/crc_aarch64.so
Binary file not shown.
Binary file removed unitree_sdk2py/utils/lib/crc_amd64.so
Binary file not shown.