Skip to content

[Draft] enable ROS example for COMPASS policy #14

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions ros2_deployment/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,24 @@ That's it! If everything worked, you should see the robot moving towards the go

https://github.com/user-attachments/assets/32931225-60b1-4fbb-8f17-1b7e7641808f


# COMPASS Integration

To run this navigator example with the COMPASS policy, you can follow the following steps:

1. Clone the COMPASS repo (https://github.com/NVlabs/COMPASS) and download the generalist checkpoint from: https://huggingface.co/nvidia/COMPASS/blob/main/compass_generalist.ckpt

2. Follow the instructions in COMPASS [README](https://github.com/NVlabs/COMPASS?tab=readme-ov-file#model-export) to setup the environment and export the ONNX file from the generalist checkpoint:
```
python3 onnx_conversion.py -b <x-mobility-ckpt> -g <downloaded-generalist-ckpt> -e carter -o <onnx-output-path>
```
NOTE: Update the image size in the `onnx_conversion.py` to match the camera resolution.

3. Follow the instructions in Step 5 to build the TensorRT engine.

4. Point the `runtime_path` parameter in the `x_mobility_navigator.launch.py` to the newly built engine.

5. Launch the X-Mobility navigator with the COMPASS policy:
```
ros2 launch x_mobility_navigator x_mobility_navigator.launch.py
```
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def generate_launch_description():
LaunchConfiguration("is_mapless", default="True"),
'runtime_path':
LaunchConfiguration("runtime_path",
default="/tmp/x_mobility.engine"),
default="/tmp/compass_carter.engine"),
}],
),
Node(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
RUNTIME_PATH = 'runtime_path'
MAPLESS_FLAG = 'is_mapless'

NUM_ROUTE_POINTS = 20
NUM_ROUTE_POINTS = 10
# Route vector with 4 values representing start and end positions
ROUTE_VECTOR_SIZE = 4
ROBOT_FRAME = 'base_link'
Expand Down Expand Up @@ -121,6 +121,11 @@ def load_model(self):
runtime = trt.Runtime(trt.Logger(trt.Logger.INFO))
engine = runtime.deserialize_cuda_engine(engine_data)
self.runtime_context = engine.create_execution_context()
for idx in range(engine.num_io_tensors):
name = engine.get_tensor_name(idx)
print(name)
print(engine.get_tensor_dtype(name))
print(engine.get_tensor_shape(name))

def image_callback(self, image_msg):
self.camera_image = self.process_image_msg(image_msg)
Expand Down Expand Up @@ -231,7 +236,7 @@ def _trt_inference(self):
history_input = cuda.mem_alloc(self.history.nbytes)
sample_input = cuda.mem_alloc(self.sample.nbytes)
action_output = cuda.mem_alloc(self.action.nbytes)
path_output = cuda.mem_alloc(self.path.nbytes)
# path_output = cuda.mem_alloc(self.path.nbytes)
history_output = cuda.mem_alloc(self.history.nbytes)
sample_ouput = cuda.mem_alloc(self.sample.nbytes)

Expand All @@ -253,7 +258,7 @@ def _trt_inference(self):
int(history_input),
int(sample_input),
int(action_output),
int(path_output),
# int(path_output),
int(history_output),
int(sample_ouput),
]
Expand All @@ -263,7 +268,7 @@ def _trt_inference(self):

# Copy action back to host and publish
cuda.memcpy_dtoh(self.action, action_output)
cuda.memcpy_dtoh(self.path, path_output)
# cuda.memcpy_dtoh(self.path, path_output)
cuda.memcpy_dtoh(self.history, history_output)
cuda.memcpy_dtoh(self.sample, sample_ouput)

Expand Down