Skip to content

Commit 46e4b5f

Browse files
SachidanandAllebinliunlsmocsharpwendell-homwhom3
authored
Telesurgery Workflow (#149)
- [x] Env setup (similar to other 2 workflows) - [x] IGX Support to run patient in real/physical world - [x] x86 Support to run patient in simulation world - [x] Surgeon to fetch/instruct command over Gamepad - [x] Haply device support for both SIM and Real - [ ] Dockerfile (needs to be verified; otherwise it's just a copy based on other 2 workflows) > HINT:: Reviewers Install and Try the setup > HINT:: Do direct [Code walk](https://github.com/isaac-for-healthcare/i4h-workflows/tree/sachi/telesurgery/workflows/telesurgery/scripts) --------- Signed-off-by: Sachidanand Alle <[email protected]> Signed-off-by: binliu <[email protected]> Signed-off-by: Victor Chang <[email protected]> Signed-off-by: binliunls <[email protected]> Co-authored-by: binliunls <[email protected]> Co-authored-by: Victor Chang <[email protected]> Co-authored-by: Victor Chang <[email protected]> Co-authored-by: wendell-hom <[email protected]> Co-authored-by: Wendell Hom <[email protected]> Co-authored-by: binliu <[email protected]> Co-authored-by: Mingxin Zheng <[email protected]>
1 parent fdc5552 commit 46e4b5f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+3995
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ cython_debug/
185185

186186
# VSCode
187187
.vscode/
188+
.idea/
188189

189190
# Wandb
190191
wandb/

.pre-commit-config.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ repos:
1717
hooks:
1818
- id: ruff
1919
entry: ruff check
20+
exclude: |
21+
(?x)^(
22+
workflows/telesurgery/cmake/pybind11/__init__.py
23+
)$
2024
- repo: https://github.com/pycqa/isort
2125
rev: 6.0.0
2226
hooks:

NOTICE.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ Licensed under GPL-3.0 (https://gcc.gnu.org/onlinedocs/libstdc++/manual/license.
4646
libxcb-cursor0 (https://launchpad.net/ubuntu/mantic/amd64/libxcb-cursor0)
4747
Licensed under MIT (https://gitlab.freedesktop.org/xorg/lib/libxcb-cursor/-/blob/master/COPYING)
4848

49+
opencv-python (https://github.com/opencv/opencv-python)
50+
Copyright (c) Olli-Pekka Heinisuo
51+
License under MIT (https://github.com/opencv/opencv-python/blob/4.x/LICENSE.txt)
52+
4953
openpi (https://github.com/Physical-Intelligence/openpi)
5054
Licensed under Apache 2.0 (https://github.com/Physical-Intelligence/openpi/blob/main/LICENSE)
5155

@@ -81,6 +85,10 @@ torch (https://pypi.org/project/torch/)
8185
2016- Facebook, Inc (Adam Paszke); 2014- Facebook, Inc (Soumith Chintala); 2011-2014 Idiap Research Institute (Ronan Collobert); 2012-2014 Deepmind Technologies (Koray Kavukcuoglu); 2011-2012 NEC Laboratories America (Koray Kavukcuoglu); 2011-2013 NYU (Clement Farabet); 2006-2010 NEC Laboratories America (Ronan Collobert, Leon Bottou, Iain Melvin, Jason Weston); 2006 Idiap Research Institute (Samy Bengio); 2001-2004 Idiap Research Institute (Ronan Collobert, Samy Bengio, Johnny Mariethoz); 2016 Facebook Inc.; 2015 Google Inc.; 2015 Yangqing Jia; 2019-2020 Kakao Brain; 2022 Cruise LLC.; 2024 Tri Dao.
8286
Licensed under BSD-3-Clause (https://github.com/pytorch/pytorch/blob/main/LICENSE)
8387

88+
v4l-utils (https://github.com/gjasny/v4l-utils)
89+
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
90+
Licensed under GPL-2.0 (https://github.com/gjasny/v4l-utils/blob/master/COPYING)
91+
8492
x11-utils (https://launchpad.net/ubuntu/+source/x11-utils)
8593
2011 Gaetan Nadon; 1994-2003 The XFree86 Project, Inc. All Rights Reserved.; 1993
8694
The Regents of the University of California. All rights reserved.; 2003 The NetBSD Foundation, Inc.; 2001-2002 Damien Miller. All rights reserved.; 1998 Todd C. Miller &lt;[email protected]&gt;; 2001-2004 Thomas Winischhofer; 1991-2000 Silicon Graphics, Inc. All Rights Reserved.; 2001 by Bigelow &amp; Holmes Inc. Luxi font; 2001 by URW++ GmbH. All Rights

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ For everything you need to get started, including detailed tutorials and step-by
6262
### Workflows
6363
- [Robotic ultrasound](./workflows/robotic_ultrasound/README.md)
6464
- [Robotic surgery](./workflows/robotic_surgery/README.md)
65+
- [Telesurgery](./workflows/telesurgery/README.md)
6566

6667
### Tutorials
6768
- [Bring your own patient](./tutorials/assets/bring_your_own_patient/README.md)
106 KB
Loading

pyproject.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,13 @@ known_third_party = ["openpi", "i4h_asset_helper"]
1212
[tool.ruff]
1313
line-length = 120
1414
target-version = "py310"
15+
exclude = [
16+
"workflows/telesurgery/cmake/pybind11/"
17+
]
1518

1619
[tool.ruff.lint]
1720
extend-select = ["E501"]
1821
extend-ignore = ["E402"]
1922

2023
[tool.codespell]
21-
ignore-words-list = "solum"
24+
ignore-words-list = "solum, ptd"

tools/env_setup/install_haply.sh

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/bin/bash
2+
3+
# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
4+
# SPDX-License-Identifier: Apache-2.0
5+
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
18+
set -e
19+
20+
VERSION=3.3.2
21+
PLATFORM=amd64
22+
OS_VERSION=$(lsb_release -rs)
23+
24+
# ---- Install Haply Inverse Service
25+
if command -v "haply-inverse-service" &> /dev/null; then
26+
echo "Haply Inverse Service already installed, skipping."
27+
exit 0
28+
fi
29+
30+
if [[ "$(uname -m)" != x86_64 ]]; then
31+
echo "Skipping for non-x86_64 arch."
32+
exit 1
33+
fi
34+
35+
# Download the deb package
36+
if [[ "$OS_VERSION" == "24.04" ]]; then
37+
echo "Detected Ubuntu 24.04"
38+
wget -O haply-inverse-service.deb https://cdn.haply.co/r/38736259/haply-inverse-service_3.3.2_amd64.deb
39+
elif [[ "$OS_VERSION" == "22.04" ]]; then
40+
echo "Detected Ubuntu 22.04"
41+
wget -O haply-inverse-service.deb https://cdn.haply.co/r/38736259/haply-inverse-service_3.3.2_2204_amd64.deb
42+
else
43+
echo "Unsupported version of Ubuntu: $OS_VERSION"
44+
exit 1
45+
fi
46+
47+
48+
# Install debian
49+
sudo apt-get install -y ./haply-inverse-service.deb
50+
rm haply-inverse-service.deb
51+
52+
echo "Haply Inverse Service installed!"

tools/env_setup_telesurgery.sh

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#!/bin/bash
2+
3+
# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
4+
# SPDX-License-Identifier: Apache-2.0
5+
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
18+
set -e
19+
20+
# --- Setup Steps ---
21+
# Get the parent directory of the current script
22+
PROJECT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && cd .. && pwd)"
23+
source "$PROJECT_ROOT/tools/env_setup/bash_utils.sh"
24+
25+
# Check if running in a conda environment
26+
check_conda_env
27+
28+
# Check if NVIDIA GPU is available
29+
check_nvidia_gpu
30+
31+
# Check if the third_party directory exists
32+
ensure_fresh_third_party_dir
33+
34+
35+
# ---- Install build tools (Common) ----
36+
echo "Installing build tools..."
37+
if [ "$EUID" -ne 0 ]; then
38+
sudo apt-get install -y git cmake build-essential pybind11-dev v4l-utils lsb-release
39+
else
40+
apt-get install -y git cmake build-essential pybind11-dev v4l-utils lsb-release
41+
fi
42+
43+
# ---- Install IsaacSim and IsaacLab (Common) ----
44+
# Check if IsaacLab is already cloned
45+
if [[ "$(uname -m)" == x86_64 ]]; then
46+
echo "Installing IsaacSim and IsaacLab... (only for x86)"
47+
bash $PROJECT_ROOT/tools/env_setup/install_isaac.sh
48+
else
49+
echo "Platform is not x86_64; Skip IsaacSim/IsaacLab"
50+
fi
51+
52+
# ---- Install necessary dependencies (Common) ----
53+
echo "Installing necessary dependencies..."
54+
pip install numpy
55+
conda install -c conda-forge libstdcxx-ng -y
56+
57+
# ---- Install Haply Inverse Service (Telesurgery) ----
58+
if [[ "$(uname -m)" == x86_64 ]]; then
59+
echo "Installing Haply Inverse Service... (only for x86)"
60+
bash $PROJECT_ROOT/tools/env_setup/install_haply.sh
61+
else
62+
echo "Platform is not x86_64; Skip Haply Inverse Service Installation"
63+
fi
64+
65+
66+
# ---- Install necessary dependencies (Telesurgery) ----
67+
echo "Installing necessary dependencies..."
68+
pip install -r $PROJECT_ROOT/workflows/telesurgery/requirements.txt
69+
70+
echo "=========================================="
71+
echo "Environment setup script finished."
72+
echo "=========================================="

workflows/telesurgery/README.md

Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
# Telesurgery Workflow
2+
3+
![Telesurgery Workflow](../../docs/source/telesurgery_workflow.jpg)
4+
5+
## Table of Contents
6+
- [System Requirements](#system-requirements)
7+
- [Quick Start](#quick-start)
8+
- [Running the Workflow](#running-the-workflow)
9+
- [Licensing](#licensing)
10+
11+
## System Requirements
12+
13+
### Hardware Requirements
14+
- Ubuntu 22.04
15+
- NVIDIA GPU with compute capability 8.6 and 32GB of memory
16+
- GPUs without RT Cores, such as A100 and H100, are not supported
17+
- 50GB of disk space
18+
19+
### Software Requirements
20+
- NVIDIA Driver Version >= 555
21+
- CUDA Version >= 12.6
22+
- Python 3.10
23+
- RTI DDS License
24+
25+
## Quick Start
26+
27+
### x86 & AARCH64 (IGX) Setup
28+
29+
1. **Set up a Docker environment with CUDA enabled (IGX only):**
30+
```bash
31+
cd <path-to-i4h-workflows>
32+
xhost +
33+
workflows/telesurgery/docker/setup.sh run
34+
35+
# Inside Docker
36+
workflows/telesurgery/docker/setup.sh init
37+
```
38+
39+
2. **Set up the x86 environment with CUDA enabled:**
40+
```bash
41+
cd <path-to-i4h-workflows>
42+
xhost +
43+
workflows/telesurgery/docker/setup.sh init
44+
```
45+
46+
3. **Create and activate a [conda](https://www.anaconda.com/docs/getting-started/miniconda/install#quickstart-install-instructions) environment:**
47+
```bash
48+
source ~/miniconda3/bin/activate
49+
conda create -n telesurgery python=3.10 -y
50+
conda activate telesurgery
51+
```
52+
53+
4. **Run the setup script:**
54+
```bash
55+
cd <path-to-i4h-workflows>
56+
bash tools/env_setup_telesurgery.sh
57+
```
58+
59+
> Make sure your public key is added to the github account if the git authentication fails.
60+
61+
### Obtain RTI DDS License
62+
63+
RTI DDS is the communication package used by all scripts. Please refer to the [DDS website](https://www.rti.com/products) for registration. You will need to obtain a license file and set the `RTI_LICENSE_FILE` environment variable to its path.
64+
65+
### NTP Server (Optional)
66+
67+
An NTP (Network Time Protocol) server provides accurate time information to clients over a computer network. NTP is designed to synchronize the clocks of computers to a reference time source, ensuring all devices on the network maintain the same time.
68+
69+
```bash
70+
# Run your own NTP server in the background
71+
docker run -d --name ntp-server --restart=always -p 123:123/udp cturra/ntp
72+
73+
# Check if it's running
74+
docker logs ntp-server
75+
76+
# fix server ip in env.sh for NTP Server
77+
export NTP_SERVER_HOST=<NTP server address>
78+
79+
# To stop the server
80+
# docker stop ntp-server && docker rm ntp-server
81+
```
82+
83+
### Environment Variables
84+
85+
Before running any scripts, set up the following environment variables:
86+
87+
1. **PYTHONPATH**: Set this to point to the **scripts** directory:
88+
```bash
89+
export PYTHONPATH=<path-to-i4h-workflows>/workflows/telesurgery/scripts
90+
```
91+
This ensures Python can find the modules under the [`scripts`](./scripts) directory.
92+
93+
2. **RTI_LICENSE_FILE**: Set this to point to your RTI DDS license file:
94+
```bash
95+
export RTI_LICENSE_FILE=<path-to-rti-license-file>
96+
```
97+
This is required for the DDS communication package to function properly.
98+
99+
3. **NDDS_DISCOVERY_PEERS**: Set this to the IP address receiving camera data:
100+
```bash
101+
export NDDS_DISCOVERY_PEERS="surgeon IP address"
102+
```
103+
More recommended variables can be found in [env.sh](./scripts/env.sh).
104+
105+
## Running the Workflow
106+
107+
```bash
108+
cd <path-to-i4h-workflows>/workflows/telesurgery/scripts
109+
source env.sh # Make sure all env variables are correctly set in env.sh
110+
111+
export PATIENT_IP=<patient IP address>
112+
export SURGEON_IP=<surgeon IP address>
113+
```
114+
> Make sure the MIRA API Server is up and running (port: 8081) in the case of a physical world setup.
115+
116+
### [Option 1] Patient in Physical World _(x86 / aarch64)_
117+
118+
When running on IGX (aarch64), ensure you are in the Docker environment set up previously.
119+
120+
```bash
121+
# Stream camera output
122+
python patient/physical/camera.py --camera realsense --name room --width 1280 --height 720
123+
python patient/physical/camera.py --camera cv2 --name robot --width 1920 --height 1080
124+
```
125+
126+
### [Option 2] Patient in Simulation World _(x86)_
127+
128+
```bash
129+
# Download the assets
130+
i4h-asset-retrieve
131+
132+
python patient/simulation/main.py [--encoder nvc]
133+
```
134+
135+
### Surgeon Connecting to Patient _(x86 / aarch64)_
136+
137+
# capture robot camera stream
138+
NDDS_DISCOVERY_PEERS=${PATIENT_IP} python surgeon/camera.py --name robot --width 1280 --height 720 [--decoder nvc]
139+
140+
# capture room camera stream (optional)
141+
NDDS_DISCOVERY_PEERS=${PATIENT_IP} python surgeon/camera.py --name room --width 1280 --height 720 [--decoder nvc]
142+
143+
# Connect to gamepad controller and send commands to API Server
144+
python surgeon/gamepad.py --api_host ${PATIENT_IP} --api_port 8081
145+
```
146+
147+
### Using H.264/HEVC Encoder/Decoder from NVIDIA Video Codec
148+
149+
Camera data can be streamed using either the H.264 or HEVC (H.265) codecs. To enable this for the Patient and Surgeon applications, use the `--encoder nvc` or `--decoder nvc` argument, respectively.
150+
151+
Encoding parameters can be customized in the Patient application using the `--encoder_params` argument, as shown below:
152+
153+
```bash
154+
python patient/simulation/main.py --encoder nvc --encoder_params patient/nvc_encoder_params.json
155+
```
156+
157+
#### Sample Encoding Parameters for the NVIDIA Video Codec
158+
159+
Here’s an example of encoding parameters in JSON format:
160+
161+
```json
162+
{
163+
"codec": "H264", // Possible values: H264 or HEVC
164+
"preset": "P3", // Options include P3, P4, P5, P6, P7
165+
"bitrate": 10000000,
166+
"frame_rate": 60,
167+
"rate_control_mode": 1, // Options: 0 for Constant QP, 1 for Variable bitrate, 2 for Constant bitrate
168+
"multi_pass_encoding": 0 // Options: 0 to disable, 1 for Quarter resolution, 2 for Full resolution
169+
}
170+
```
171+
172+
> [!NOTE]
173+
> H.264 or HEVC (H.265) codecs are available on x86 platform only.
174+
175+
### Important Notes
176+
1. You may need to run multiple scripts simultaneously in different terminals or run in background (in case of docker)
177+
2. A typical setup requires multiple terminals running:
178+
- Patient: Camera1, Camera2, Controller, etc.
179+
- Surgeon: Camera1, Camera2, Controller, etc.
180+
181+
If you encounter issues not covered in the notes above, please check the documentation for each component or open a new issue on GitHub.
182+
183+
## Licensing
184+
185+
By using the Telesurgery workflow and NVIDIA Video Codec, you are implicitly agreeing to the [NVIDIA Software License Agreement](https://www.nvidia.com/en-us/agreements/enterprise-software/nvidia-software-license-agreement/) and [NVIDIA Software Developer License Agreement](https://developer.download.nvidia.com/designworks/DesignWorks_SDKs_Samples_Tools_License_distrib_use_rights_2017_06_13.pdf?t=eyJscyI6InJlZiIsImxzZCI6IlJFRi1zZWFyY2guYnJhdmUuY29tLyJ9). If you do not agree to the EULA, do not run this container.

0 commit comments

Comments
 (0)