# X4_ARM_SDK **Repository Path**: BigYellow12138/X4_ARM_SDK ## Basic Information - **Project Name**: X4_ARM_SDK - **Description**: 有你同创公司旗下机械臂的开源SDK - **Primary Language**: Unknown - **License**: LGPL-3.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-05-27 - **Last Updated**: 2026-06-17 ## Categories & Tags **Categories**: Uncategorized **Tags**: SDK, Python ## README # X4_ARM_SDK > `unibot_arm_sdk` is the company-level Python SDK for UniBot robotic arms. This repository, `X4_ARM_SDK`, currently prioritizes Arm_X4 support and provides layered APIs for serial communication, DM motor protocol, kinematics, 6-axis arm control, and independent gripper control. ## Table of Contents - [Switch to 中文](#x4_arm_sdk-使用说明) - [Introduction](#x4_arm_sdk) - [Environment](#environment) - [Documentation](#documentation) - [Install](#install) - [Quick Start](#quick-start) - [Notes](#notes) - [License](#license) ### Environment - Ubuntu: `20.04 / 22.04 / 24.04` - Windows: `10 / 11` - macOS (Darwin) - Python: `3.8` and above (compatible up to `3.13`) ### Documentation | Topic | Link | | --- | --- | | User Guide | [docs/SDK_GUIDE.md](./docs/SDK_GUIDE.md) | | API Reference | [docs/api_reference.md](./docs/api_reference.md) | | Architecture & Design | [docs/architecture.md](./docs/architecture.md) | | Joint Limit Calibration | [docs/joint_limit_calibration.md](./docs/joint_limit_calibration.md) | | DM Motor Protocol | [docs/调试助手使用说明书(达妙驱动控制协议)V1.4.md](./docs/调试助手使用说明书(达妙驱动控制协议)V1.4.md) | | Changelog | [CHANGELOG.md](./CHANGELOG.md#changelog) | | Demos | [unibot_arm_sdk/demos](./unibot_arm_sdk/demos) | ### Install This repository is the SDK project root. Run installation and test commands from this directory. GitHub: ```shell git clone https://github.com/Vsonic12138/unibot-arm-sdk.git cd X4_ARM_SDK pip3 install . ``` Gitee: ```shell git clone https://gitee.com/BigYellow12138/unibot-arm-sdk.git cd X4_ARM_SDK pip3 install . ``` For development (editable install with test dependencies): ```shell pip3 install -e ".[dev]" ``` If editable installation reports that the backend is missing the `build_editable` hook, upgrade `pip` and `setuptools` first: ```shell python3 -m pip install --upgrade pip setuptools wheel python3 -m pip install -e . ``` Core dependencies: - `pyserial >= 3.5` - `numpy >= 1.20` ### Quick Start #### Virtual Mode (no hardware required) Virtual mode does not require a physical arm, suitable for API flow verification. ```python from unibot_arm_sdk import ARM_X4_REST_JOINTS, ArmConfig, WaitOptions, create_arm arm = create_arm(ArmConfig.virtual(home_joints=ARM_X4_REST_JOINTS)) arm.connect() print("connected:", arm.is_connected()) print("joints:", [s.position for s in arm.get_joint_states()]) arm.move_j([0.0, 0.1, -0.1, 0.0, 0.0, 0.0], velocity=1.0) arm.move_p([0.2, 0.0, 0.20, 3.14159, 0.0, -1.5708], velocity=0.5) arm.move_home(velocity=0.5, wait=WaitOptions(timeout=5.0)) arm.disconnect() ``` #### Serial Mode (real hardware) Defaults: `/dev/ttyACM0`, baud `921600`, `DM4340` motors, `POS_VEL` control mode, joint motor IDs `0x01`–`0x06`. Arm_X4 main motion APIs currently support `POS_VEL` only. Other DM control modes remain protocol-layer capabilities and are not exposed as stable arm-level motion APIs yet. ```python from unibot_arm_sdk import ARM_X4_REST_JOINTS, ArmConfig, create_arm arm = create_arm(ArmConfig.serial( port="/dev/ttyACM0", baudrate=921600, home_joints=ARM_X4_REST_JOINTS, )) arm.connect() try: arm.move_j([0.0, 0.1, -0.1, 0.0, 0.0, 0.0], velocity=0.5) arm.move_p([0.2, 0.0, 0.20, 3.14159, 0.0, -1.5708], velocity=0.5) finally: arm.disconnect() ``` #### Gripper Control The gripper is modeled as an independent end effector (DM motor ID `0x07`). `init_effector()` creates and registers the gripper driver; call `gripper.enable()` before commanding it. ```python gripper = arm.init_effector("dm_gripper") gripper.enable() gripper.close(velocity=0.5) gripper.open(velocity=0.5) gripper.set_position(-0.75, velocity=0.3) status = gripper.get_status() print("position:", status.position) ``` ### Notes - **Linux**: ensure the current user has read/write permission on the serial port (e.g. add to `dialout` group). - **Safety**: verify that target positions will not cause the arm to collide with the environment or itself before commanding motion. - **Real demos**: real-hardware demos require `--confirm-real`; `safe_recovery_demo` also requires user-confirmed `--home-joints`. - **Virtual mode**: `VirtualComm` is a lightweight byte-channel mock for API flow testing; it does not simulate full arm dynamics or complete motor feedback. - **TCP offset**: `move_p()` treats the input as a **TCP target pose**. If a TCP offset has been set via `set_tcp_offset()`, the SDK automatically converts it to a flange pose before running IK. It then commands joints through `move_j()`; it is not Cartesian straight-line interpolation. - **Soft stop**: `stop_joints()` keeps the arm connected and enabled while holding current fresh joint positions. It does not pause user task loops; later motion commands can override it. `emergency_stop()` disables and disconnects the driver context. - **Home pose**: `ARM_X4_REST_JOINTS` is the measured X4 rest pose and can be passed explicitly to `ArmConfig.home_joints`; `move_home()` still requires explicit configuration. - **Gripper range**: The X4 gripper defaults to `open=0.0 rad`, `close=-1.5 rad`; override with `gripper.set_range()` if your hardware differs. - **Joint limits**: the built-in Arm_X4 limits are temporary software defaults. Use [docs/joint_limit_calibration.md](./docs/joint_limit_calibration.md) to collect real six-axis limits before production use. - **Fault feedback**: motor ERR feedback is exposed through structured status fields such as `error_code`, `hardware_fault`, and `fault_name`; fault feedback also emits SDK logs for diagnostics. ### Contact & Support - Website: [https://unitc.cn/zh](https://unitc.cn/zh) - QQ Group: 811348489 ### License This project is licensed under the [LGPL-3.0 License](./LICENSE). --- # X4_ARM_SDK 使用说明 > `unibot_arm_sdk` 是公司统一机械臂 Python SDK。当前仓库 `X4_ARM_SDK` 优先支持 Arm_X4,提供分层、可测试、可扩展的 API,涵盖串口通信、DM 电机协议、运动学、6 轴机械臂控制和独立夹爪控制。 ## 目录 - [切换到 English](#x4_arm_sdk) - [简介](#x4_arm_sdk-使用说明) - [环境支持](#环境支持) - [文档入口](#文档入口) - [安装方法](#安装方法) - [快速开始](#快速开始-1) - [注意事项](#注意事项) - [许可证](#许可证) ## 环境支持 - Ubuntu:`20.04 / 22.04 / 24.04` - Windows:`10 / 11` - macOS (Darwin) - Python:`3.8` 及以上(目前适配至 `3.13`) ## 文档入口 | 说明 | 文档 | | --- | --- | | 使用指南 | [docs/SDK_GUIDE.md](./docs/SDK_GUIDE.md) | | API 参考 | [docs/api_reference.md](./docs/api_reference.md) | | 架构设计 | [docs/architecture.md](./docs/architecture.md) | | 关节限位获取 | [docs/joint_limit_calibration.md](./docs/joint_limit_calibration.md) | | 达妙电机协议 | [docs/调试助手使用说明书(达妙驱动控制协议)V1.4.md](./docs/调试助手使用说明书(达妙驱动控制协议)V1.4.md) | | 更新日志 | [CHANGELOG.md](./CHANGELOG.md#更新日志) | | 示例代码 | [unibot_arm_sdk/demos](./unibot_arm_sdk/demos) | ## 安装方法 本仓库目录即 SDK 项目根目录。安装、测试和运行示例命令都应在该目录下执行。 GitHub: ```shell git clone https://github.com/Vsonic12138/unibot-arm-sdk.git cd X4_ARM_SDK pip3 install . ``` Gitee: ```shell git clone https://gitee.com/BigYellow12138/unibot-arm-sdk.git cd X4_ARM_SDK pip3 install . ``` 开发模式(可编辑安装,含测试依赖): ```shell pip3 install -e ".[dev]" ``` 核心依赖: - `pyserial >= 3.5` - `numpy >= 1.20` ## 快速开始 ### 虚拟模式(无需硬件) 虚拟模式不需要真实机械臂,适合验证 API 调用流程。 ```python from unibot_arm_sdk import ARM_X4_REST_JOINTS, ArmConfig, WaitOptions, create_arm arm = create_arm(ArmConfig.virtual(home_joints=ARM_X4_REST_JOINTS)) arm.connect() print("connected:", arm.is_connected()) print("joints:", [s.position for s in arm.get_joint_states()]) arm.move_j([0.0, 0.1, -0.1, 0.0, 0.0, 0.0], velocity=1.0) arm.move_p([0.2, 0.0, 0.20, 3.14159, 0.0, -1.5708], velocity=0.5) arm.move_home(velocity=0.5, wait=WaitOptions(timeout=5.0)) arm.disconnect() ``` ### 真实串口模式 默认配置:`/dev/ttyACM0`、波特率 `921600`、`DM4340` 电机、`POS_VEL` 控制模式、关节电机 ID `0x01`–`0x06`。 Arm_X4 当前稳定的主运动 API 只支持 `POS_VEL`;其他 DM 控制模式暂时保留在协议层,不作为机械臂级稳定运动接口开放。 ```python from unibot_arm_sdk import ARM_X4_REST_JOINTS, ArmConfig, create_arm arm = create_arm(ArmConfig.serial( port="/dev/ttyACM0", baudrate=921600, home_joints=ARM_X4_REST_JOINTS, )) arm.connect() try: arm.move_j([0.0, 0.1, -0.1, 0.0, 0.0, 0.0], velocity=0.5) arm.move_p([0.2, 0.0, 0.20, 3.14159, 0.0, -1.5708], velocity=0.5) finally: arm.disconnect() ``` ### 夹爪控制 夹爪作为独立末端执行器建模(DM 电机 ID `0x07`)。 `init_effector()` 负责创建夹爪驱动并注册电机;控制夹爪前需要显式调用 `gripper.enable()`。 ```python gripper = arm.init_effector("dm_gripper") gripper.enable() gripper.close(velocity=0.5) gripper.open(velocity=0.5) gripper.set_position(-0.75, velocity=0.3) status = gripper.get_status() print("position:", status.position) ``` ## 注意事项 - **Linux**:确保当前用户对串口设备有读写权限(例如加入 `dialout` 用户组)。 - **安全**:下发运动命令前,确认目标位置不会导致机械臂碰撞环境或自身结构。 - **真实 demo**:真实硬件 demo 需要显式传入 `--confirm-real`;`safe_recovery_demo` 还需要传入用户现场确认过的 `--home-joints`。 - **虚拟模式**:`VirtualComm` 是轻量字节通道 mock,仅用于 API 流程测试,不模拟完整机械臂动力学或完整电机反馈。 - **TCP 偏移**:`move_p()` 将传入位姿视为 **TCP 目标**。若通过 `set_tcp_offset()` 设置了偏移,SDK 会自动将 TCP 目标转换为法兰位姿后再执行 IK,并最终通过 `move_j()` 下发关节目标;它不是笛卡尔直线插补。 - **软停**:`stop_joints()` 会在保持连接和使能的情况下保持当前新鲜关节位置,但不会暂停用户自己的任务循环;后续运动命令会覆盖软停。`emergency_stop()` 会失能并断开驱动上下文。 - **Home 姿态**:`ARM_X4_REST_JOINTS` 是 X4 实测休息位,可显式传给 `ArmConfig.home_joints`;`move_home()` 仍要求显式配置。 - **夹爪范围**:X4 夹爪默认打开位为 `0.0 rad`,关闭位为 `-1.5 rad`;如现场硬件不同,可用 `gripper.set_range()` 覆盖。 - **关节限位**:内置 Arm_X4 限位是临时软件默认值。量产或真机长期使用前,请按 [docs/joint_limit_calibration.md](./docs/joint_limit_calibration.md) 获取六轴真实限位。 - **故障反馈**:达妙 ERR 反馈会暴露到 `error_code`、`hardware_fault`、`fault_name` 等结构化状态字段,并通过 SDK 日志提示,便于现场诊断。 ## 联系我们 - 官网:[https://unitc.cn/zh](https://unitc.cn/zh) - QQ群:811348489 ## 许可证 本项目采用 [LGPL-3.0 许可证](./LICENSE)。