GripperController

Robotiq Gripper Interface for aiofranka

This module provides an async wrapper for Robotiq grippers, following the same design pattern as FrankaController - a background control loop continuously sends commands while you update the target position.

Requires optional dependencies: pip install “aiofranka[robotiq]”

Example

>>> import asyncio
>>> from aiofranka.gripper import GripperController
>>>
>>> async def main():
...     gripper = GripperController("/dev/ttyUSB1")
...     await gripper.start()
...     gripper.speed = 128  # Set speed (like kp/kd)
...     gripper.q_desired = 200  # Set target position
...     await asyncio.sleep(1)
...     await gripper.stop()
>>>
>>> asyncio.run(main())
class aiofranka.gripper.GripperController(port='/dev/ttyUSB1', speed=255, force=255, loop_rate=50.0, read_every_n=2)[source]

Bases: object

Async gripper controller with background control loop.

Similar to FrankaController, this runs a background loop that continuously sends goTo commands. You only need to set the target position - the loop handles the communication.

q_desired

Target gripper position (0=open, 255=closed)

Type:

int

qpos

Current gripper position (read-only)

Type:

int

speed

Gripper speed setting (1-255), like kp gain

Type:

int

force

Gripper force setting (0-255), like kd gain

Type:

int

state

Current gripper state (qpos, q_desired, speed, force)

Type:

dict

running

Whether control loop is active

Type:

bool

Parameters:
  • port (str) – Serial port for the gripper (e.g., “/dev/ttyUSB1”)

  • speed (int) – Initial speed setting (default: 255)

  • force (int) – Initial force setting (default: 255)

  • loop_rate (float) – Control loop frequency in Hz (default: 50)

  • read_every_n (int)

Example

>>> gripper = GripperController("/dev/ttyUSB1")
>>> await gripper.start()
>>>
>>> # Set gains (speed/force) like you set kp/kd
>>> gripper.speed = 128
>>> gripper.force = 200
>>>
>>> # Set target position (like q_desired for Franka)
>>> gripper.q_desired = 255  # Close
>>> await asyncio.sleep(0.5)
>>> gripper.q_desired = 0    # Open
>>> await asyncio.sleep(0.5)
>>>
>>> # Read current position (like qpos for Franka)
>>> print(gripper.qpos)
>>>
>>> await gripper.stop()
__init__(port='/dev/ttyUSB1', speed=255, force=255, loop_rate=50.0, read_every_n=2)[source]
Parameters:
property q_desired: int

Target gripper position (0=open, 255=closed).

property position: int

Alias for q_desired (deprecated).

property speed: int

Gripper speed (1-255). Higher = faster. Like kp gain.

property force: int

Gripper force (0-255). Higher = stronger grip. Like kd gain.

property qpos: int

Current gripper position (read-only).

property current_position: int

Alias for qpos (deprecated).

property state: dict

Current gripper state dictionary.

set_freq(freq)[source]

Set the update frequency for rate-limited set() calls.

Parameters:

freq (float) – Desired update frequency in Hz (typically 10-100 Hz)

async set(attr, value)[source]

Rate-limited setter (same pattern as FrankaController).

Parameters:
  • attr (str) – Attribute name (“q_desired”, “speed”, “force”)

  • value – Value to set

async start()[source]

Initialize gripper and start background control loop.

Returns:

The background control loop task

Return type:

asyncio.Task

async stop()[source]

Stop the control loop and wait for thread to finish.

open()[source]

Set target to fully open (0).

close()[source]

Set target to fully closed (255).

async wait_until_reached(tolerance=5, timeout=5.0)[source]

Wait until gripper reaches target position.

Parameters:
  • tolerance (int) – Position tolerance in gripper units

  • timeout (float) – Maximum wait time in seconds

Returns:

True if position reached, False if timeout

Return type:

bool