Metadata-Version: 2.5
Name: DobotTCP
Version: 1.2.0
Summary: A library to control Dobot robots via TCP
Project-URL: Homepage, https://github.com/MichaelHengge/DobotTCP
Project-URL: Issues, https://github.com/MichaelHengge/DobotTCP/issues
Author-email: Michael Hengge <michael.hengge@physik.hu-berlin.de>
License-Expression: MIT
License-File: LICENSE
Keywords: dobot,robotics,tcp
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Requires-Python: >=3.10
Requires-Dist: multipledispatch>=1.0.0
Description-Content-Type: text/markdown

# DobotTCP Library

DobotTCP is a Python library to control the Dobot robot range via its TCP interface. The library provides functions for managing motion, I/O, and configuration of the Dobot robot. It was specially developed with the Dobot Magician E6 in mind.

## Installation

Install the library via pip:

```bash
pip install DobotTCP
```

Ensure Python 3.10+ is installed. Install dependencies if not automatically installed:

```bash
pip install multipledispatch
```

Import the library in your project:

```python
from DobotTCP import Dobot
```

## Basic Usage

### Example

```python
from DobotTCP import Dobot

# Connect the robot
robot = Dobot(ip="192.168.5.1", port=29999)
robot.Connect()

# Enable robot and parse response
(err, rsp, cmd) = robot.EnableRobot()
print(f"  Error code: {err}")
print(f"  Response: {rsp}")
print(f"  Command: {cmd}")

# Move robot with joint motion to pose (returns once the motion is finished)
robot.MovJ("pose={0,0,0,0,0,0}")

# Home robot
robot.Home()

robot.Disconnect()
```

Numeric arguments can be given as `int` or `float`, e.g. `robot.RelMovLTool(10, 0, 0, 0, 0, 0)`.

### Error handling and motion waiting

By default every command that the robot answers with an error raises a `DobotError` (with `code`, `message` and `command` attributes), and every queued motion command only returns once the robot has finished the motion. With `debugLevel > 0` the returned value or error of each command is printed.

```python
from DobotTCP import Dobot, DobotError

robot = Dobot()
robot.Connect()

try:
    robot.MoveJJ(0, 0, 0, 0, 0, 0)    # Waits until the move is done
except DobotError as e:
    print(e.code, e.message)

robot.SetRaiseOnError(False)          # Only print errors and return the response tuple
robot.SetWaitForMotion(False)         # Return immediately after sending motion commands
robot.WaitForMotion()                 # Wait manually for the last motion
robot.SetWaitForMotion(True, timeout=60)
```

A motion counts as finished when the robot is enabled and idle and the current command ID has reached the ID returned by the motion command. Waiting raises a `TimeoutError` after the timeout (default 30 s) and a `RuntimeError` if the robot goes into alarm, collision, disabled or power-off status.

### Additional move functions

Besides the commands of the TCP protocol, some shortcut functions are included:

```python
robot.MoveJJ(0, 0, -90, 0, 90, 0)     # Joint motion to joint angles
robot.MoveJP(300, 0, 200, 180, 0, 0)  # Joint motion to pose
robot.MoveLJ(0, 0, -90, 0, 90, 0)     # Linear motion to joint angles
robot.MoveLP(300, 0, 200, 180, 0, 0)  # Linear motion to pose

robot.MoveOffsetZ(-20)                # Linear move 20 mm along tool -Z
robot.MoveOffsetX(15, frame="user")   # Linear move 15 mm along user X
```

`MoveOffsetX/Y/Z` calculate the target from the current pose with `RelPointTool` or `RelPointUser` (default frame: tool) and move there linearly.

## Included Classes

Additional classes for robot accessories have been added.

### Flexible Gripper

Basic controls for a flexible gripper

```python
from DobotTCP import Dobot, FlexGripper

robot = Dobot()
gripper = FlexGripper(robot)
gripper.Open()
gripper.Close()
```

### Servo Gripper

Basic controls for a servo gripper (IO mode)

```python
from DobotTCP import Dobot, ServoGripper

robot = Dobot()
servo_gripper = ServoGripper(robot)
servo_gripper.SetState(1)  # Open
servo_gripper.SetState(2)  # Close
print(servo_gripper.GetState())
```

### Sucker

Suction cup on a tool DO with an "adsorbed" signal on a tool DI. `ApproachAndAdsorb` jogs along tool Z until an object is adsorbed and stops after a safety distance if nothing is picked up.

```python
from DobotTCP import Dobot, Sucker

robot = Dobot()
sucker = Sucker(robot)  # Tool DO 1 for suction, tool DI 1 for adsorbed signal
if sucker.ApproachAndAdsorb(speed=3, retract_dist=10, max_dist=50):
    # ... move to the place position ...
    sucker.Release()
```

### Feedback

This class was implemented to receive feedback from the robot via TCP. Incomplete or misaligned packets are discarded and fetched again automatically.

```python
from DobotTCP import Dobot, Feedback

robot = Dobot()
feedback = Feedback(robot)
feedback.Connect()
feedback.Get()                   # Optional: Get(retries=5, timeout=1.0)
print(feedback.data.get("RobotType"))
```

## Notes

- This class was written with the intention to stay as close to the syntax formatting of the original [Dobot TCP protocol v4.6.0](https://download.dobot.cc/2025/01/Dobot%20TCP_IP%20Remote%20Control%20Interface%20Guide%20V4.6.0_20250115_en.pdf). (Note, as per 19.11.2026, this PDF is not findable on the Dobot Webpage. The latest version there is still v4.5.2) Therefore, not all python style guides are followed. For example function names start with a capital letter.

- Since method overloading is not trivial in python, some functions had to be changed in order to make them work in python. This is especially the case for the tray functions.

- The drag sensitivity command is sent as `DragSensivity`, which is the spelling used in the Dobot protocol. The Python method is still called `DragSensitivity`.

## Version Changelog

- v1.0.0 (17.01.2025): Initial release based on TCP protocol v4.5.0
- v1.1.0 (20.01.2025):
  - Update library based on new TCP protocol v4.6.0. **Some new commands may require the robot controller version to be updated to V4.6.0.**
  - Add module docstring and parsing functions
- v1.1.1 (27.01.2025): Various bug fixes
- v1.1.2 (31.01.2025): Fixes bugs when parsing robot responses
- v1.1.3 (16.06.2025): Fixes bug with incorrect __init__ file
- v1.1.4 (27.06.2025): Fixes bugs with Flexgripper class
- v1.1.5 (15.01.2026): Fixes typos in relative motion commands
- v1.1.6 (15.01.2026): Fixes naming mismatch
- v1.2.0 (19.11.2026): Major update. **Contains breaking changes, see below.**
  - New features:
    - Motion commands wait until the robot has finished the motion (`SetWaitForMotion`, `WaitForMotion`)
    - Robot errors raise a `DobotError` (`SetRaiseOnError`). Returned values and errors are printed with `debugLevel > 0`
    - New `Sucker` class with `ApproachAndAdsorb` (incl. safety distance) and `Release`
    - New offset moves `MoveOffsetX`, `MoveOffsetY`, `MoveOffsetZ`
    - New command `FCSetStiffness`
    - Overloaded functions accept `int` and `float` arguments
  - Fixes (checked against TCP protocol v4.6.0):
    - `MovLIO` and `MovJIO` sent `MovL`/`MovJ` instead of `MovLIO`/`MovJIO`
    - Overloads of `EnableRobot` (4 and 5 parameters), `MovJIO` and `RelJointMovJ` could not be called
    - Motion commands with `speed`/`r` sent both `v` and `speed` and both `cp` and `r`. Now `speed` and `r` are only sent if > 0
    - `SetCoils` did not send the `count` parameter
    - `DragSensitivity` now sends `DragSensivity`, the command name used in the protocol
    - `StartPath`, `RunTo`, `ServoJ` and `ServoP` now send optional parameters as `key=value`, `ForceDriveMode` sends `user` as plain value
    - String parameters of `RunScript`, `SetPayload`, `ModbusCreate`, `ModbusRTUCreate` and `SetTool485` are quoted
    - `InverseKin` only sends `useJointNear`/`jointNear` when used
    - `ForceDriveSpped` renamed to `ForceDriveSpeed` and `RelMovLUser` sent a malformed `v` parameter
    - Feedback parser was shifted by 2 bytes from `BrakeStatus` onwards. Added `HandType` and `SafeState`
    - `Feedback.Get` failed on incomplete packets. It now reads complete packets, validates them and retries, with timeout
    - Responses from the robot are read completely (previously a single `recv` could return a partial response)
    - `ServoGripper.GetState` never matched a state
  - Other changes:
    - Corrected docstrings (ranges, units, defaults, examples) and spelling throughout
    - `FCSetMass` and `FCSetDamping` rotational defaults corrected to 20 and 50
    - `setHoldRegs` renamed to `SetHoldRegs` (old name still works)
    - Removed duplicate `StopDrag`
  - Breaking changes:
    - Errors now raise a `DobotError` by default. Use `SetRaiseOnError(False)` for the previous behaviour
    - Motion commands now block until the motion is finished. Use `SetWaitForMotion(False)` for the previous behaviour
    - `Dobot.SetSucker` was removed. Use `Sucker(robot).On()` / `Off()`
    - In the full motion overloads, `speed=0` / `r=0` now means "use `v`" / "use `cp`"
    - Requires Python 3.10+

## Contributing

Feel free to contribute to the project by submitting issues or pull requests.

## License

This project is licensed under the MIT License.
