Skip to content
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
80 changes: 80 additions & 0 deletions VisionPilot/Iceoryx/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
cmake_minimum_required(VERSION 3.16)
project(iceoryx_demo)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# Find dependencies
find_package(iceoryx_posh REQUIRED)
find_package(iceoryx_binding_c REQUIRED)
find_package(OpenCV REQUIRED COMPONENTS core highgui imgproc)
find_package(CUDA REQUIRED)

# Add our common libraries from the VisionPilot project
# Adjust the relative paths if necessary
set(COMMON_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../common)

# GStreamer Engine Library
add_library(gstreamer_engine STATIC
${COMMON_DIR}/sensors/gstreamer_engine.cpp
)
target_include_directories(gstreamer_engine PUBLIC
${COMMON_DIR}/include
${OpenCV_INCLUDE_DIRS}
)
# GStreamer requires pkg-config to find its libraries
find_package(PkgConfig REQUIRED)
pkg_check_modules(GSTREAMER REQUIRED gstreamer-1.0 gstreamer-app-1.0)
target_include_directories(gstreamer_engine PUBLIC ${GSTREAMER_INCLUDE_DIRS})
target_link_libraries(gstreamer_engine PUBLIC
${GSTREAMER_LIBRARIES}
${OpenCV_LIBS}
)
target_compile_definitions(gstreamer_engine PUBLIC LOG_TYPE=0) # Use printf for logging

# AutoSpeed TensorRT Backend Library
add_library(autospeed_backend STATIC
${COMMON_DIR}/backends/autospeed/tensorrt_engine.cpp
)
target_include_directories(autospeed_backend PUBLIC
${COMMON_DIR}/include
${CUDA_INCLUDE_DIRS}
/usr/include/x86_64-linux-gnu/ # For TensorRT headers
)
target_link_libraries(autospeed_backend PUBLIC
gstreamer_engine
${CUDA_LIBRARIES}
nvinfer
nvonnxparser
)
target_compile_definitions(autospeed_backend PUBLIC LOG_TYPE=0) # Use printf for logging

# Set include directory for the topic header
include_directories(include)

# Publisher Executable
add_executable(publisher src/publisher_node.cpp)
target_link_libraries(publisher
PRIVATE
autospeed_backend
gstreamer_engine
iceoryx_posh::iceoryx_posh
iceoryx_binding_c::iceoryx_binding_c
${OpenCV_LIBS}
)
target_compile_options(publisher PRIVATE "-Wno-unused-parameter")

# Subscriber Executable
add_executable(subscriber src/subscriber_node.cpp)
target_link_libraries(subscriber
PRIVATE
iceoryx_posh::iceoryx_posh
iceoryx_binding_c::iceoryx_binding_c
${OpenCV_LIBS}
)
target_compile_options(subscriber PRIVATE "-Wno-unused-parameter")

# Install executables
install(TARGETS publisher subscriber
RUNTIME DESTINATION bin
)
47 changes: 47 additions & 0 deletions VisionPilot/Iceoryx/include/iceoryx_topic.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@

#include <cstdint>

// Define a POD (Plain Old Data) struct for a single detection.
// This is necessary for sending data through Iceoryx, which works with raw memory.
struct DetectionPOD {
float x1, y1, x2, y2;
float score;
int32_t class_id;
};

// The main data structure (topic) to be sent over Iceoryx.
// This struct lives in shared memory - both publisher and subscriber work
// directly with this memory (zero-copy IPC).
//
// Publisher workflow:
// 1. Loan this struct from Iceoryx shared memory
// 2. Write frame data directly into frame_data[] buffer
// 3. Run inference on cv::Mat wrapper pointing to frame_data[]
// 4. Publish (no copy - just memory ownership transfer)
//
// Subscriber workflow:
// 1. Receive reference to this struct in shared memory
// 2. Create cv::Mat wrapper around frame_data[] (no copy)
// 3. Process/visualize directly from shared memory
struct FrameDetectionsTopic {
// Timestamps for latency measurement (e.g., from std::chrono::steady_clock)
uint64_t capture_timestamp_ns; // When the frame was grabbed from the source
uint64_t publish_timestamp_ns; // When the packet is sent by the publisher

// Frame metadata
uint32_t frame_width;
uint32_t frame_height;
uint32_t frame_channels;
uint64_t frame_data_size; // Actual size of data in the buffer

// Detection metadata
uint32_t num_detections;

// Fixed-size buffers for performance.
// Ensure these are large enough for your use case.
static constexpr uint32_t MAX_DETECTIONS = 100;
static constexpr uint64_t MAX_FRAME_SIZE = 3840 * 2160 * 3; // 4K UHD RGB (24,883,200 bytes)

DetectionPOD detections[MAX_DETECTIONS];
uint8_t frame_data[MAX_FRAME_SIZE];
};
43 changes: 43 additions & 0 deletions VisionPilot/Iceoryx/roudi_config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
[general]
version = 1

[[segment]]

[[segment.mempool]]
size = 128
count = 10000

[[segment.mempool]]
size = 1024
count = 5000

[[segment.mempool]]
size = 16384
count = 1000

[[segment.mempool]]
size = 131072
count = 200

[[segment.mempool]]
size = 524288
count = 50

[[segment.mempool]]
size = 1048576
count = 30

[[segment.mempool]]
size = 4194304
count = 10

# Custom large memory pools for vision data
[[segment.mempool]]
size = 8388608
count = 10

# Extra-large pool for 4K video frames (32 MB chunks)
[[segment.mempool]]
size = 33554432
count = 10

91 changes: 91 additions & 0 deletions VisionPilot/Iceoryx/run_iceoryx_demo.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#!/bin/bash
#
# Script to build and run the full Iceoryx publisher/subscriber demo pipeline.
#
# It performs the following steps:
# 1. Builds the publisher and subscriber executables using CMake.
# 2. Starts the Iceoryx router (iox-roudi) in the background.
# 3. Starts the subscriber application in the background.
# 4. Starts the publisher application in the foreground.
# 5. Cleans up all background processes on exit (e.g., via Ctrl+C).
#

# --- Configuration ---
VIDEO_PATH="/home/pranavdoma/Downloads/autoware.privately-owned-vehicles/VisionPilot/ROS2/data/Road_Driving_Scenes_Normal.mp4"
MODEL_PATH="/home/pranavdoma/Downloads/autoware.privately-owned-vehicles/VisionPilot/ROS2/data/models/AutoSpeed_n.onnx"
PRECISION="fp16"
# ---------------------

# Exit immediately if a command exits with a non-zero status.
set -e

# Function to clean up background processes
cleanup() {
echo -e "\n\nShutting down Iceoryx demo..."
# Kill all background jobs of this script
# The negative PID kills the entire process group
if [ -n "$ROUDI_PID" ]; then
kill $ROUDI_PID 2>/dev/null && echo "Stopped iox-roudi (PID $ROUDI_PID)."
fi
if [ -n "$SUBSCRIBER_PID" ]; then
kill $SUBSCRIBER_PID 2>/dev/null && echo "Stopped subscriber (PID $SUBSCRIBER_PID)."
fi
echo "Cleanup complete."
}

# Trap the EXIT signal to ensure cleanup runs, even on Ctrl+C
trap cleanup EXIT

# --- Main Script ---

# Check if required files exist
if [ ! -f "$VIDEO_PATH" ]; then
echo "Error: Video file not found: $VIDEO_PATH"
exit 1
fi
if [ ! -f "$MODEL_PATH" ]; then
echo "Error: Model file not found: $MODEL_PATH"
exit 1
fi

# Get the directory of this script
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
cd "$SCRIPT_DIR"

# 1. Start Iceoryx Router (roudi) with custom configuration
echo "--- Starting Iceoryx router (iox-roudi) in the background ---"
# Check if roudi is already running to avoid errors
if ! pgrep -x "iox-roudi" > /dev/null
then
iox-roudi -c "$SCRIPT_DIR/roudi_config.toml" > /dev/null 2>&1 &
ROUDI_PID=$!
# Give roudi a moment to initialize
sleep 1
echo "iox-roudi started with PID $ROUDI_PID (using custom config for large frames)."
else
echo "iox-roudi is already running."
fi
echo ""

# 2. Start the Subscriber in the background
echo "--- Starting subscriber in the background ---"
./build/subscriber &
SUBSCRIBER_PID=$!
echo "Subscriber started with PID $SUBSCRIBER_PID."
echo "An OpenCV window from the subscriber should appear shortly."
echo "Subscriber metrics will be printed to this terminal."
echo ""

# 3. Start the Publisher in the foreground
echo "--- Starting publisher in the foreground ---"
echo "Video: $VIDEO_PATH"
echo "Model: $MODEL_PATH"
echo "Precision: $PRECISION"
echo "--------------------------------------------"
echo "Press Ctrl+C to stop the publisher and clean up all processes."
echo ""

# The script will wait here until the publisher finishes or is interrupted
./build/publisher "$VIDEO_PATH" "$MODEL_PATH" "$PRECISION"

echo "Publisher finished."
Loading