set_position_sync Method
- XenseGripper.set_position_sync(self, position, vmax=80.0, fmax=27.0, tolerance=0.01, timeout=5.0, poll_interval=0.05)
Synchronous position control (moves the gripper to the target position and blocks until the target position is reached or a timeout occurs)
- Parameters:
position (float) – Target position of the gripper, in millimeters (mm). Must be within the range (0, 85). 0 mm means fully open, 85 mm means fully closed.
vmax (float) – Maximum movement speed, in millimeters per second (mm/s). Must be within the range (0, 350). The default value is 80 mm/s.
fmax (float) – Maximum output force, in Newtons (N). Must be within the range (0, 60). The default value is 27 N.
tolerance (float, 可选) – Position error tolerance for determining movement completion, in millimeters (mm). The default value is 0.01 mm.
timeout (float, 可选) – Maximum time to wait for the target position to be reached, in seconds. The default value is 5.0 seconds.
poll_interval (float, 可选) – Time interval for position checking, in seconds. The default value is 0.05 seconds.
- Raises:
ValueError – Triggered when any input parameter exceeds its allowed physical limit range.
- Returns:
Returns True if the gripper reaches the target position within the timeout period (within the allowed error range), otherwise returns False.
- Return type:
bool
Example Code
from xensegripper import XenseGripper
# 创建夹爪实例
gripper = XenseGripper.create("9a14e81bb832")
# 同步设置夹爪位置为 30mm,使用默认参数
success = gripper.set_position_sync(30)
# 同步设置夹爪位置为 70mm,指定参数(符合最新范围)
success = gripper.set_position_sync(
position=70, # 在 (0, 85) 范围内
vmax=250, # 在 (0, 350) 范围内(高于原示例,体现新上限)
fmax=50, # 在 (0, 60) 范围内(高于原示例,体现新上限)
tolerance=0.02,
timeout=8.0,
poll_interval=0.04
)
# 错误示例:力参数超出范围(体现最新上限60N)
try:
gripper.set_position_sync(40, fmax=70) # 70N 超过最大 60N 限制
except ValueError as e:
print(e)