|
| 1 | +""" |
| 2 | +Async client quickstart for PAROL6. |
| 3 | +- Starts a local headless controller at 127.0.0.1:5001 |
| 4 | +- Enables simulator mode for safety |
| 5 | +- Shows basic queries and status streaming |
| 6 | +
|
| 7 | +Run from the repository root: |
| 8 | + python external/PAROL6-python-API/examples/async_client_quickstart.py |
| 9 | +""" |
| 10 | + |
| 11 | +import asyncio |
| 12 | +from parol6 import AsyncRobotClient |
| 13 | +from parol6.client.manager import managed_server |
| 14 | + |
| 15 | +HOST = "127.0.0.1" |
| 16 | +PORT = 5001 |
| 17 | + |
| 18 | + |
| 19 | +async def run_client() -> int: |
| 20 | + async with AsyncRobotClient(host=HOST, port=PORT, timeout=2.0) as client: |
| 21 | + ready = await client.wait_for_server_ready(timeout=5.0) |
| 22 | + print(f"server ready: {ready}") |
| 23 | + if not ready: |
| 24 | + return 1 |
| 25 | + |
| 26 | + # Safety: enable simulator for this demo |
| 27 | + ok = await client.simulator_on() |
| 28 | + print(f"simulator_on: {ok}") |
| 29 | + |
| 30 | + print("ping:", await client.ping()) |
| 31 | + pose_xyz = await client.get_pose_xyz() |
| 32 | + print("pose xyz:", pose_xyz) |
| 33 | + |
| 34 | + # Consume one status broadcast |
| 35 | + print("one status frame speeds:") |
| 36 | + async for status in client.status_stream(): |
| 37 | + print(status.get("speeds")) |
| 38 | + break |
| 39 | + |
| 40 | + # Small relative TRF move (safe in simulator) |
| 41 | + # Move +5mm in Z over 1.0s |
| 42 | + moved = await client.move_cartesian_rel_trf([0, 0, 5, 0, 0, 0], duration=1.0) |
| 43 | + print("move_cartesian_rel_trf ->", moved) |
| 44 | + |
| 45 | + return 0 |
| 46 | + |
| 47 | + |
| 48 | +def main() -> None: |
| 49 | + # Auto-start and stop controller for this example |
| 50 | + with managed_server(host=HOST, port=PORT, normalize_logs=True): |
| 51 | + code = asyncio.run(run_client()) |
| 52 | + raise SystemExit(code) |
| 53 | + |
| 54 | + |
| 55 | +if __name__ == "__main__": |
| 56 | + main() |
0 commit comments