-
Notifications
You must be signed in to change notification settings - Fork 4
feat(runtime): basic PolicyRuntime implementation #118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
33ea11c
runtime draft
maxxgx 8f2b00a
add tests
maxxgx ab1bb31
add goal time to send action
maxxgx 07790a7
remove plan
maxxgx c79b0e9
fix style
maxxgx e6a9863
remove outdated example
maxxgx 4368f33
add example script
maxxgx ed9fda7
replace ActionCursor with deque, return 1D and 2D shape for select_ac…
maxxgx cdb3fab
remove obs_to_input, move inside policy runtime
maxxgx 41003bb
Address comment: runtime manages robot/camera lifecycle
maxxgx 93696bb
Potential fix for pull request finding
maxxgx 90effbf
Potential fix for pull request finding
maxxgx ac6c8e3
address copilot
maxxgx 211fba4
fix ruff
maxxgx 3d05530
fix all linting issues
maxxgx 51a8927
update copyright header
maxxgx 3c8b0a3
address PR comments
maxxgx f2df028
fix style
maxxgx fb12417
fix style
maxxgx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| #!/usr/bin/env python3 | ||
| # Copyright (C) 2026 Intel Corporation | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| """Async inference with PolicyRuntime. | ||
|
|
||
| python examples/runtime/async_inference.py \ | ||
| --model ./exports/pi05_cans_openvino \ | ||
| --device GPU.0 \ | ||
| --port /dev/ttyACM0 \ | ||
| --calibration /home/max/.cache/physicalai/robots/a8d8d997-a59e-4423-9006-5d991d223887/calibrations/0b2f185a-8ab2-4956-91c2-3a2ac2dbd8c1.json \ | ||
| --overhead-camera /dev/v4l/by-id/usb-UGREEN_Camera_2K_UGREEN_Camera_2K_SN0001-video-index0 \ | ||
| --arm-camera 353322271391 \ | ||
| --front-camera /dev/v4l/by-id/usb-Innomaker_Innomaker-U20CAM-1080p-S1_SN0001-video-index0 \ | ||
| --width 640 \ | ||
| --height 480 \ | ||
| --fps 30 \ | ||
| --duration-s 60 | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import argparse | ||
|
|
||
| import openvino as ov | ||
| import numpy as np | ||
|
|
||
| from physicalai.capture import discover_all | ||
| from physicalai.capture.transport import SharedCamera | ||
| from physicalai.inference import InferenceModel | ||
| from physicalai.robot import SO101 | ||
| from physicalai.runtime import ( | ||
| ActionQueue, | ||
| AsyncExecution, | ||
| LerpSmoother, | ||
| PolicyRuntime, | ||
| ) | ||
|
|
||
|
|
||
| def main(): | ||
| parser = argparse.ArgumentParser(description="Run policy with PolicyRuntime") | ||
| parser.add_argument("--model", required=True, help="Exported model directory") | ||
| parser.add_argument("--device", default="GPU.0", help="OpenVINO device") | ||
| parser.add_argument("--port", default="/dev/ttyACM0", help="Robot serial port") | ||
| parser.add_argument("--calibration", required=True, help="Robot calibration file") | ||
| parser.add_argument("--overhead-camera", required=True, help="Overhead camera device path") | ||
| parser.add_argument("--arm-camera", required=True, help="Arm camera serial number") | ||
| parser.add_argument("--front-camera", required=True, help="Front camera device path") | ||
| parser.add_argument("--width", type=int, default=640) | ||
| parser.add_argument("--height", type=int, default=480) | ||
| parser.add_argument("--duration-s", type=float, default=60.0) | ||
| parser.add_argument("--fps", type=float, default=30.0) | ||
| args = parser.parse_args() | ||
|
|
||
| import openvino_tokenizers # noqa: F401 — registers OV tokenizer ops | ||
|
|
||
| print(f"Available devices:") | ||
| core = ov.Core() | ||
| devices = core.available_devices | ||
| for dev in devices: | ||
| print(f" {dev}: {core.get_property(dev, 'FULL_DEVICE_NAME')}") | ||
| print(f"Selected device: {args.device}") | ||
|
|
||
| model = InferenceModel.load(args.model, device=args.device) | ||
| robot = SO101(port=args.port, calibration=args.calibration, role="follower") | ||
| cameras = { | ||
| "overhead": SharedCamera("uvc", device=args.overhead_camera, width=args.width, height=args.height, fps=int(args.fps)), | ||
| "front": SharedCamera("uvc", device=args.front_camera, width=args.width, height=args.height, fps=int(args.fps)), | ||
| "arm": SharedCamera("realsense", serial_number=args.arm_camera, width=args.width, height=args.height, fps=int(args.fps)), | ||
| } | ||
|
|
||
| runtime = PolicyRuntime( | ||
| robot=robot, | ||
| model=model, | ||
| execution=AsyncExecution(threshold=0.3, fps=int(args.fps)), | ||
| action_queue=ActionQueue(smoother=LerpSmoother(duration_frames=5)), | ||
| cameras=cameras, | ||
| fps=args.fps, | ||
| ) | ||
|
|
||
| try: | ||
| runtime.connect() | ||
| except Exception as e: | ||
| print(f"Failed to connect: {e}") | ||
| print("Available cameras:") | ||
| for driver, devices in discover_all().items(): | ||
| for dev in devices: | ||
| print(f" Driver: {driver}, Device: {dev.device_id}, Info: {dev.name}") | ||
| return | ||
|
|
||
| for name, cam in cameras.items(): | ||
| print(f"Camera '{name}' connected: {cam.actual_width}x{cam.actual_height} @ {cam.actual_fps}fps") | ||
|
|
||
| print("Starting policy runtime...") | ||
| try: | ||
| stats = runtime.run(duration_s=args.duration_s) | ||
| print(f"\nDone — {stats.steps} steps, {stats.inference_count} inferences, {stats.total_holds} holds") | ||
| finally: | ||
| runtime.disconnect() | ||
| print("Disconnected") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.