2FG7 Modbus client๏
Low-level 2FG7 Modbus RTU client over the UR tool serial bridge. Writes width/force/speed/mode registers at 0x0000 and reads eight status registers at 0x0100. Dataclass GripperStatus holds decoded widths, busy flag, raw status and registers; no auto-connect at construction.
onrobot_2fg7_driver.modbus_client ยท Source
Tools and end effectors ยท Guide ยท Symbol index
How it is used๏
OnRobot2FG7Client is the serial transport used by the ROS driver. Construction configures the client; connect() opens the connection. Read status through read_status(), send grip commands through the mode-specific methods, and call disconnect() when finished.
Widths are in millimetres, force in newtons, and speed in percent. A successful command means the register write succeeded, not that the gripper reached its requested width. Callers must inspect status to determine completion; is_busy() alone cannot distinguish an idle gripper from a failed status read.
Start here๏
Callable |
Purpose |
|---|---|
Delegate opening the configured serial connection to pymodbus. |
|
Read eight holding registers and decode busy, external/internal widths and the last status register. |
|
Send a width/force/speed command in external (1) mode through the shared register encoder. |
|
Send a width/force/speed command in internal (2) mode through the shared register encoder. |
|
Close the pymodbus client connection. |
OnRobot2FG7Client๏
Encode 2FG7 commands and decode status over Modbus RTU. The caller owns connection lifetime and completion checks.
OnRobot2FG7Client.connect()๏
Delegate opening the configured serial connection to pymodbus.
Lifecycle ยท Source
connect(self) -> bool
Returns: Underlying client.connect() Boolean indicating connection success.
Errors: Underlying exceptions propagate.
Side effects: Opens the serial device/PTY.
OnRobot2FG7Client.read_status()๏
Read eight holding registers and decode busy, external/internal widths and the last status register.
Method ยท Source
read_status(self) -> 'GripperStatus | None'
Returns: GripperStatus with busy Boolean, external_width_mm/internal_width_mm floats, status integer and raw_registers list; None for a Modbus error response.
Errors: Error responses log; short register arrays and transport exceptions propagate.
Side effects: Performs a serial Modbus read.
Referenced in source (2)
OnRobot2FG7Client.get_widthโ onrobot_2fg7_driver.modbus_clientOnRobot2FG7Client.is_busyโ onrobot_2fg7_driver.modbus_client
OnRobot2FG7Client.grip_external()๏
Send a width/force/speed command in external (1) mode through the shared register encoder.
Method ยท Source
grip_external(self, width_mm: float, force_n: int=40, speed_pct: int=100) -> bool
Parameter |
Meaning |
|---|---|
|
Target gripper width in millimetres. |
|
Requested newtons, clamped to 0โ140 by _write_command. |
|
Requested speed percent, clamped to 1โ100. |
Returns: Boolean command-write acceptance; does not wait for motion or grip confirmation.
Errors: Returns False for Modbus error response; conversion/transport exceptions propagate.
Side effects: Writes gripper command registers and can move fingers.
OnRobot2FG7Client.grip_internal()๏
Send a width/force/speed command in internal (2) mode through the shared register encoder.
Method ยท Source
grip_internal(self, width_mm: float, force_n: int=40, speed_pct: int=100) -> bool
Parameter |
Meaning |
|---|---|
|
Target gripper width in millimetres. |
|
Requested newtons, clamped to 0โ140 by _write_command. |
|
Requested speed percent, clamped to 1โ100. |
Returns: Boolean command-write acceptance; does not wait for motion or grip confirmation.
Errors: Returns False for Modbus error response; conversion/transport exceptions propagate.
Side effects: Writes gripper command registers and can move fingers.
OnRobot2FG7Client.disconnect()๏
Close the pymodbus client connection.
Lifecycle ยท Source
disconnect(self)
Returns: None; underlying close return value is discarded.
Errors: Underlying close errors propagate.
Side effects: Closes serial resources.
OnRobot2FG7Client.__init__()๏
Construct a pymodbus serial client using 8N1 on the local virtual port and retain the slave keyword and optional logger.
Lifecycle ยท Source
__init__(
self,
port = DEFAULT_PORT,
slave_id = DEFAULT_SLAVE_ID,
baudrate = DEFAULT_BAUD,
timeout = 0.5,
logger = None,
)
Parameter |
Meaning |
|---|---|
|
Serial device/PTY path, default /tmp/ttyUR. |
|
Modbus slave address, default 0x41 (65). |
|
Serial baud rate in bits per second, default 1,000,000. |
|
Serial response timeout in seconds, default 0.5. |
|
Optional object exposing error(str) for Modbus error responses. |
Returns: None; self.client is configured but not connected.
Errors: pymodbus/client option errors propagate.
Side effects: Allocates client state; opening the port is deferred to connect().
Referenced in source (1)
OnRobot2FG7DriverNode._connect_gripperโ onrobot_2fg7_driver.driver_node
OnRobot2FG7Client.release()๏
Send an external-mode width command with a fixed 20 N force; the caller chooses the opening width.
Method ยท Source
release(self, width_mm: float, speed_pct: int=100) -> bool
Parameter |
Meaning |
|---|---|
|
Target external width in millimetres. |
|
Speed percent clamped to 1โ100. |
Returns: Boolean write acceptance, not verified release completion.
Errors: Shared encoder/transport errors propagate; Modbus error responses yield False.
Side effects: Commands gripper width in external mode.
OnRobot2FG7Client.get_width()๏
Read status once and extract its external width.
Method ยท Source
get_width(self) -> 'float | None'
Returns: Float millimetres or None when the status read returns None.
Errors: Transport/decode errors propagate.
Side effects: Performs a Modbus status read.
OnRobot2FG7Client.is_busy()๏
Read the gripper status and return its busy flag. A failed status read also returns False, so this method alone cannot confirm that the gripper is idle.
Method ยท Source
is_busy(self) -> bool
Returns: Boolean busy flag; False is ambiguous between idle and failed read.
Errors: Transport/decode errors propagate despite response errors mapping to False.
Side effects: Performs a Modbus status read.
Internal callbacks and helpers๏
OnRobot2FG7Client._write_command()๏
Encode width to rounded tenths of a millimetre and write four command registers, clamping force, speed and mode.
Internal helper ยท Source
_write_command(self, width_mm: float, force_n: int, speed_pct: int, mode: int) -> bool
Parameter |
Meaning |
|---|---|
|
Requested width in millimetres; rounded ร10 and clamped only at zero, with no upper register/physical-width bound here. |
|
Force in newtons, int-converted and clamped to 0โ140. |
|
Speed percentage, int-converted and clamped to 1โ100. |
|
Mode integer clamped to 1โ2: external/internal grip. |
Returns: True for a nonerror Modbus write response, False for result.isError(); not a motion-completion indication.
Errors: Error responses log when a logger exists; transport, invalid numeric and register-range exceptions propagate.
Side effects: Writes device registers and can initiate gripper motion.
Referenced in source (3)
OnRobot2FG7Client.grip_externalโ onrobot_2fg7_driver.modbus_clientOnRobot2FG7Client.grip_internalโ onrobot_2fg7_driver.modbus_clientOnRobot2FG7Client.releaseโ onrobot_2fg7_driver.modbus_client