夹爪和升降轴
夹爪和升降轴 API 参考文档
模块:leesn_lift_api — 夹爪和升降轴 HTTP 客户端
一、GripperClient — 夹爪控制
GripperClient GripperClient()
GripperClient(base_url, token, device_id="pgc_gripper", timeout_s=3.0, default_poll_dt=0.2)
参数
| 参数 | 类型 | 必需 | 默认值 | 说明 |
|---|---|---|---|---|
base_url |
str | 是 | — | Web 服务器地址 |
token |
str | 是 | — | API 令牌 |
device_id |
str | 否 | "pgc_gripper" |
设备 ID |
timeout_s |
float | 否 | 3.0 |
请求超时(秒) |
default_poll_dt |
float | 否 | 0.2 |
轮询间隔(秒) |
使用示例
Python
from leesn_lift_api.gripper_client import GripperClient gripper = GripperClient( base_url="http://127.0.0.1:8000", token="123456", device_id="pgc_gripper" )
GripperClient gripper.open()
gripper.open(speed=50, force=30, continuous=False, wait=True, timeout_s=8.0)
参数
| 参数 | 类型 | 必需 | 默认值 | 说明 |
|---|---|---|---|---|
speed |
int | 否 | 50 |
速度 |
force |
int | 否 | 30 |
力 |
continuous |
bool | 否 | False |
持续模式 |
wait |
bool | 否 | True |
等待完成 |
timeout_s |
float | 否 | 8.0 |
超时时间 |
使用示例
Python
# 张开夹爪 gripper.open(speed=80, force=30, wait=True) # 闭合夹爪 gripper.close(speed=80, force=80, wait=True)
说明:
close() 参数同 open()。GripperClient gripper.move_mm()
gripper.move_mm(mm, speed=50, force=50, continuous=False, wait=True, timeout_s=8.0)
参数
| 参数 | 类型 | 必需 | 默认值 | 说明 |
|---|---|---|---|---|
mm |
float | 是 | — | 目标开合度(毫米) |
speed |
int | 否 | 50 |
速度 |
force |
int | 否 | 50 |
力 |
continuous |
bool | 否 | False |
持续模式 |
wait |
bool | 否 | True |
等待完成 |
timeout_s |
float | 否 | 8.0 |
超时时间 |
使用示例
Python
gripper.move_mm(50.0, speed=80, force=50, wait=True)
GripperClient gripper.stop() / gripper.telemetry()
使用示例
Python
# 停止夹爪运动 gripper.stop() # 获取夹爪遥测数据 tel = gripper.telemetry() print(f"开合度: {tel.open_mm}mm") print(f"忙碌: {tel.busy}")
GripperTelemetry 字段
| 字段 | 类型 | 说明 |
|---|---|---|
ts |
float | 时间戳 |
open_mm |
Optional[float] | 当前开合度 (mm) |
current_i16 |
Optional[int] | 电流 |
temp_c |
Optional[int] | 温度 (°C) |
error_code |
Optional[int] | 错误代码 |
status |
Optional[int] | 状态 |
status_text |
str | 状态文本 |
mode |
str | 模式 |
busy |
bool | 是否忙碌 |
last_error |
str | 最后错误 |
estop |
bool | 急停状态 |
二、LiftClient — 升降轴控制
LiftClient LiftClient()
LiftClient(base_url, token, device_id="lift_z", timeout_s=3.0, default_poll_dt=0.2)
参数
| 参数 | 类型 | 必需 | 默认值 | 说明 |
|---|---|---|---|---|
base_url |
str | 是 | — | Web 服务器地址 |
token |
str | 是 | — | API 令牌 |
device_id |
str | 否 | "lift_z" |
设备 ID |
timeout_s |
float | 否 | 3.0 |
请求超时 |
default_poll_dt |
float | 否 | 0.2 |
轮询间隔 |
使用示例
Python
from leesn_lift_api.lift_client import LiftClient lift = LiftClient( base_url="http://127.0.0.1:8000", token="123456", device_id="lift_z" )
LiftClient lift.move_pos()
lift.move_pos(target_mm, max_speed_dps=1200, wait=True, timeout_s=60.0, poll_dt=None, tol_mm=1.0)
参数
| 参数 | 类型 | 必需 | 默认值 | 说明 |
|---|---|---|---|---|
target_mm |
float | 是 | — | 目标位置(毫米) |
max_speed_dps |
int | 否 | 1200 |
最大速度 |
wait |
bool | 否 | True |
等待完成 |
timeout_s |
float | 否 | 60.0 |
超时时间 |
poll_dt |
float | 否 | None |
轮询间隔 |
tol_mm |
float | 否 | 1.0 |
位置容差 |
使用示例
Python
lift.move_pos(target_mm=100.0, max_speed_dps=1200, wait=True)
LiftClient lift.set_speed_mm_s() / lift.set_limits() / lift.status()
set_speed_mm_s — 设置运动速度
| 参数 | 类型 | 必需 | 说明 |
|---|---|---|---|
speed_mm_s |
float | 是 | 速度(毫米/秒) |
set_limits — 设置软限位
| 参数 | 类型 | 必需 | 说明 |
|---|---|---|---|
low_mm |
float | 是 | 下限位置(毫米) |
high_mm |
float | 是 | 上限位置(毫米) |
status — 获取升降轴状态
| 字段 | 类型 | 说明 |
|---|---|---|
pos_mm |
float | 当前位置 |
speed_dps |
float | 当前速度 |
temp_c |
float | 温度 |
mode |
str | 模式 |
busy |
bool | 是否忙碌 |
estop |
bool | 急停状态 |
raw |
dict | 原始数据 |
使用示例
Python
# 设置运动速度 lift.set_speed_mm_s(20.0) # 20mm/s # 设置软限位 lift.set_limits(low_mm=-630, high_mm=340) # 获取升降轴状态 st = lift.status() print(f"位置: {st.pos_mm}mm") print(f"忙碌: {st.busy}")
三、完整使用示例
完整示例 夹爪 + 升降轴
Python
from leesn_lift_api.gripper_client import GripperClient from leesn_lift_api.lift_client import LiftClient # 夹爪控制 with GripperClient("http://127.0.0.1:8000", "123456") as gripper: gripper.open(speed=80, force=30, wait=True) gripper.move_mm(50.0, speed=80, force=50, wait=True) gripper.close(speed=80, force=80, wait=True) # 升降轴控制 with LiftClient("http://127.0.0.1:8000", "123456") as lift: lift.set_limits(low_mm=-630, high_mm=340) lift.move_pos(target_mm=100.0, max_speed_dps=1200, wait=True) st = lift.status() print(f"位置: {st.pos_mm}mm")
四、依赖安装
Shell
pip install requests
Y1 | 夹爪和升降轴 API 文档 Ver1.0.0
