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
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "extern/spot-cpp-sdk"]
path = extern/spot-cpp-sdk
url = https://github.com/boston-dynamics/spot-cpp-sdk
[submodule "install"]
path = install
url = https://github.com/fmz/SpotObserver-release.git
9 changes: 5 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ if (NOT CUDAToolkit_FOUND)
endif()
message(STATUS "CUDAToolkit found: ${CUDAToolkit_VERSION}")

set(SPOT_SDK_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/extern/spot-sdk-install)
set(SPOT_SDK_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/extern/spot-cpp-sdk) # changed from sdk-install
set(OpenCV_INCLUDES ${CMAKE_CURRENT_SOURCE_DIR}/extern/opencv/include)
set(OpenCV_LIBS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/extern/opencv/x64/vc16/lib)
set(OpenCV_LIBS opencv_world4110.lib)
set(OpenCV_LIBS opencv_world4120.lib) # change from 4110

# Force protobuf to come from vcpkg, not libtorch
find_package(Protobuf REQUIRED PATHS "${Protobuf_ROOT}" NO_DEFAULT_PATH)
Expand All @@ -51,7 +51,7 @@ endif()
message(STATUS "Found libtorch: ${TORCH_LIBRARIES}")
message(STATUS "Torch install prefix: ${TORCH_INSTALL_PREFIX}")

set(ONNX_DIR ${CMAKE_CURRENT_SOURCE_DIR}/extern/onnxruntime-win-x64-gpu-1.22.0)
set(ONNX_DIR ${CMAKE_CURRENT_SOURCE_DIR}/extern/onnxruntime-win-x64-gpu-1.23.0) # changed from 1.22.0
# Check if ONNX_DIR exists
if(NOT EXISTS ${ONNX_DIR})
message(FATAL_ERROR "ONNX directory not found: ${ONNX_DIR}. Please ensure ONNX Runtime is correctly extracted.")
Expand Down Expand Up @@ -182,8 +182,9 @@ if(COPY_DLLS)
)

# List of required OpenCV DLLs
# changed from 4110
set(OPENCV_DLLS
"opencv_world4110.dll"
"opencv_world4120.dll"
)

set(PLUGIN_DLLS
Expand Down
44 changes: 38 additions & 6 deletions include/spot-observer.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,25 @@

#include "IUnityInterface.h"

#ifdef __cplusplus
extern "C" {
#endif

// Make dummy available to other files in namespace
// change so all files use getter func?
namespace SOb {
extern bool dummy;
extern int taken_from_dummy;
extern bool going_up;
}

// Make avaiable to integ-test

UNITY_INTERFACE_EXPORT
bool UNITY_INTERFACE_API getDummy();
UNITY_INTERFACE_EXPORT
void UNITY_INTERFACE_API setDummy(bool val);


// Define a function pointer type for logging
typedef void (*SOb_LogCallback)(const char* message);
Expand All @@ -26,6 +44,7 @@ enum SpotCamera {
NUM_CAMERAS = 0x40,
};


// Unity Stuff
void UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API UnityPluginLoad(IUnityInterfaces* unity);
void UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API UnityPluginUnload();
Expand All @@ -39,11 +58,16 @@ bool UNITY_INTERFACE_API SOb_DisconnectFromSpot(int32_t robot_id);

// Start reading spot camera feeds. Runs in a separate threads.
UNITY_INTERFACE_EXPORT
bool UNITY_INTERFACE_API SOb_ReadCameraFeeds(int32_t robot_id, uint32_t cam_bitmask);
int32_t UNITY_INTERFACE_API SOb_CreateCameraStream(int32_t robot_id, uint32_t cam_bitmask);

UNITY_INTERFACE_EXPORT
bool UNITY_INTERFACE_API SOb_DestroyCameraStream(int32_t robot_id, int32_t cam_stream_id);


UNITY_INTERFACE_EXPORT
bool UNITY_INTERFACE_API SOb_GetNextImageSet(
int32_t robot_id,
int32_t cam_stream_id,
int32_t n_images_requested,
uint8_t** images,
float** depths
Expand All @@ -52,6 +76,7 @@ bool UNITY_INTERFACE_API SOb_GetNextImageSet(
UNITY_INTERFACE_EXPORT
bool UNITY_INTERFACE_API SOb_RegisterUnityReadbackBuffers(
int32_t robot_id,
int32_t cam_stream_id,
uint32_t cam_bit, // Single bit only
void* out_img_buf, // ID3D12Resource* (aka tensor)
void* out_depth_buf, // ID3D12Resource* (aka tensor)
Expand All @@ -63,22 +88,27 @@ UNITY_INTERFACE_EXPORT
bool UNITY_INTERFACE_API SOb_ClearUnityReadbackBuffers(int32_t robot_id);

UNITY_INTERFACE_EXPORT
bool UNITY_INTERFACE_API SOb_LaunchVisionPipeline(int32_t robot_id, SObModel model);
bool UNITY_INTERFACE_API SOb_LaunchVisionPipeline(
int32_t robot_id,
int32_t cam_stream_id,
SObModel model
);
UNITY_INTERFACE_EXPORT
bool UNITY_INTERFACE_API SOb_StopVisionPipeline(int32_t robot_id);
bool UNITY_INTERFACE_API SOb_StopVisionPipeline(int32_t robot_id, int32_t cam_stream_id);
UNITY_INTERFACE_EXPORT
bool UNITY_INTERFACE_API SOb_GetNextVisionPipelineImageSet(
int32_t robot_id,
int32_t cam_stream_id,
int32_t n_images_requested,
uint8_t** images,
float** depths
);

UNITY_INTERFACE_EXPORT
bool UNITY_INTERFACE_API SOb_PushNextImageSetToUnityBuffers(int32_t robot_id);
bool UNITY_INTERFACE_API SOb_PushNextImageSetToUnityBuffers(int32_t robot_id, int32_t cam_stream_id);

UNITY_INTERFACE_EXPORT
bool UNITY_INTERFACE_API SOb_PushNextVisionPipelineImageSetToUnityBuffers(int32_t robot_id);
bool UNITY_INTERFACE_API SOb_PushNextVisionPipelineImageSetToUnityBuffers(int32_t robot_id, int32_t cam_stream_id);

// Model stuff
UNITY_INTERFACE_EXPORT
Expand All @@ -103,6 +133,8 @@ bool UNITY_INTERFACE_API SOb_SetUnityLogCallback(const SOb_LogCallback callback)
UNITY_INTERFACE_EXPORT
void UNITY_INTERFACE_API SOb_ToggleDebugDumps(const char* dump_path);

}
#ifdef __cplusplus
} // extern "C"
#endif

#endif //SPOT_OBSERVER_H
1 change: 1 addition & 0 deletions install
Submodule install added at 440ce5
Binary file added saved_images/spot_depth1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added saved_images/spot_depth10.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added saved_images/spot_depth11.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added saved_images/spot_depth12.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added saved_images/spot_depth13.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added saved_images/spot_depth14.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added saved_images/spot_depth15.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added saved_images/spot_depth16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added saved_images/spot_depth17.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added saved_images/spot_depth18.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added saved_images/spot_depth19.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added saved_images/spot_depth2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added saved_images/spot_depth20.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added saved_images/spot_depth21.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added saved_images/spot_depth22.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added saved_images/spot_depth23.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added saved_images/spot_depth24.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added saved_images/spot_depth25.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added saved_images/spot_depth26.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added saved_images/spot_depth27.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added saved_images/spot_depth28.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added saved_images/spot_depth29.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added saved_images/spot_depth3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added saved_images/spot_depth30.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added saved_images/spot_depth31.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added saved_images/spot_depth32.png
Binary file added saved_images/spot_depth33.png
Binary file added saved_images/spot_depth34.png
Binary file added saved_images/spot_depth35.png
Binary file added saved_images/spot_depth36.png
Binary file added saved_images/spot_depth37.png
Binary file added saved_images/spot_depth38.png
Binary file added saved_images/spot_depth39.png
Binary file added saved_images/spot_depth4.png
Binary file added saved_images/spot_depth40.png
Binary file added saved_images/spot_depth41.png
Binary file added saved_images/spot_depth42.png
Binary file added saved_images/spot_depth43.png
Binary file added saved_images/spot_depth44.png
Binary file added saved_images/spot_depth45.png
Binary file added saved_images/spot_depth46.png
Binary file added saved_images/spot_depth47.png
Binary file added saved_images/spot_depth48.png
Binary file added saved_images/spot_depth49.png
Binary file added saved_images/spot_depth5.png
Binary file added saved_images/spot_depth50.png
Binary file added saved_images/spot_depth6.png
Binary file added saved_images/spot_depth7.png
Binary file added saved_images/spot_depth8.png
Binary file added saved_images/spot_depth9.png
Binary file added saved_images/spot_rgb1.png
Binary file added saved_images/spot_rgb10.png
Binary file added saved_images/spot_rgb11.png
Binary file added saved_images/spot_rgb12.png
Binary file added saved_images/spot_rgb13.png
Binary file added saved_images/spot_rgb14.png
Binary file added saved_images/spot_rgb15.png
Binary file added saved_images/spot_rgb16.png
Binary file added saved_images/spot_rgb17.png
Binary file added saved_images/spot_rgb18.png
Binary file added saved_images/spot_rgb19.png
Binary file added saved_images/spot_rgb2.png
Binary file added saved_images/spot_rgb20.png
Binary file added saved_images/spot_rgb21.png
Binary file added saved_images/spot_rgb22.png
Binary file added saved_images/spot_rgb23.png
Binary file added saved_images/spot_rgb24.png
Binary file added saved_images/spot_rgb25.png
Binary file added saved_images/spot_rgb26.png
Binary file added saved_images/spot_rgb27.png
Binary file added saved_images/spot_rgb28.png
Binary file added saved_images/spot_rgb29.png
Binary file added saved_images/spot_rgb3.png
Binary file added saved_images/spot_rgb30.png
Binary file added saved_images/spot_rgb31.png
Binary file added saved_images/spot_rgb32.png
Binary file added saved_images/spot_rgb33.png
Binary file added saved_images/spot_rgb34.png
Binary file added saved_images/spot_rgb35.png
Binary file added saved_images/spot_rgb36.png
Binary file added saved_images/spot_rgb37.png
Binary file added saved_images/spot_rgb38.png
Binary file added saved_images/spot_rgb39.png
Binary file added saved_images/spot_rgb4.png
Binary file added saved_images/spot_rgb40.png
Binary file added saved_images/spot_rgb41.png
Binary file added saved_images/spot_rgb42.png
Binary file added saved_images/spot_rgb43.png
Binary file added saved_images/spot_rgb44.png
Binary file added saved_images/spot_rgb45.png
Binary file added saved_images/spot_rgb46.png
Binary file added saved_images/spot_rgb47.png
Binary file added saved_images/spot_rgb48.png
Binary file added saved_images/spot_rgb49.png
Binary file added saved_images/spot_rgb5.png
Binary file added saved_images/spot_rgb50.png
Binary file added saved_images/spot_rgb6.png
Binary file added saved_images/spot_rgb7.png
Binary file added saved_images/spot_rgb8.png
Binary file added saved_images/spot_rgb9.png
73 changes: 67 additions & 6 deletions src/cuda_kernels.cu
Original file line number Diff line number Diff line change
Expand Up @@ -864,6 +864,11 @@ cudaError_t preprocess_depth_image2(
err = cudaGetLastError();
if (err != cudaSuccess) return err;
}
// } else {
// // Just copy input to output buffer
// err = cudaMemcpyAsync(d_out, depth_image_in, N * sizeof(float), cudaMemcpyDeviceToDevice, stream);
// if (err != cudaSuccess) return err;
// }

if (downscale_factor > 1) {
if ((downscale_factor & (downscale_factor - 1)) != 0) {
Expand Down Expand Up @@ -1159,7 +1164,7 @@ __global__ void nhwc_to_nchw_rgb_float_kernel(

int out_p = out_y * out_W + out_x;
int base = n * 3 * out_pixels_per_img + out_p; // position of R plane element
out[base] = px.x * scale;
out[base] = px.x * scale;
out[base + out_pixels_per_img] = px.y * scale;
out[base + 2 * out_pixels_per_img] = px.z * scale;
}
Expand Down Expand Up @@ -1244,13 +1249,13 @@ __global__ void prefill_depth_from_cache(
if (x >= width || y >= height) return;

int idx = y * width + x;
float new_val = new_depth[idx];
float old_val = cached_depth[idx];
float new_val = new_depth[idx];
float cached_val = cached_depth[idx];

// Check if new depth value is valid
bool new_valid = (new_val >= min_valid_depth && new_val <= max_valid_depth);
// Update the new_depth buffer in-place to have gaps filled
output_depth[idx] = new_valid ? old_val : new_val;
output_depth[idx] = new_valid ? new_val : cached_val;
}

cudaError_t prefill_invalid_depth(
Expand All @@ -1276,6 +1281,53 @@ cudaError_t prefill_invalid_depth(
return cudaGetLastError();
}

// CUDA kernel for maintaining running cumulative input depth image
__global__ void prefill_depth_from_prev(
float* __restrict__ new_depth,
float* __restrict__ prev_depth,
int width,
int height,
float min_valid_depth,
float max_valid_depth
) {
int x = blockIdx.x * blockDim.x + threadIdx.x;
int y = blockIdx.y * blockDim.y + threadIdx.y;

if (x >= width || y >= height) return;

int idx = y * width + x;
float new_val = new_depth[idx];
float prev_val = prev_depth[idx];

// Check if new depth value is valid
bool new_valid = (new_val >= min_valid_depth && new_val <= max_valid_depth);
// Update the new_depth buffer in-place to have gaps filled
new_depth[idx] = new_valid ? new_val : prev_val;
}

cudaError_t prefill_input_depth(
float* d_depth_data,
float* d_depth_prev,
int width,
int height,
float min_valid_depth,
float max_valid_depth,
cudaStream_t stream
) {
dim3 block(32, 8);
dim3 grid((width + block.x - 1) / block.x,
(height + block.y - 1) / block.y);

prefill_depth_from_prev<<<grid, block, 0, stream>>>(
d_depth_data, d_depth_prev,
width, height,
min_valid_depth, max_valid_depth
);

return cudaGetLastError();
}


// CUDA kernel for maintaining running average of depth values
// new_depth: current frame depth values
// avg_depth: running average depth buffer (input/output)
Expand All @@ -1285,6 +1337,8 @@ __global__ void update_depth_cache_kernel(
const float* __restrict__ generated_depth,
const float* __restrict__ sparse_depth,
float* __restrict__ cached_depth,
float alpha_valid,
float alpha_invalid,
int width,
int height,
float min_valid_depth,
Expand All @@ -1305,9 +1359,13 @@ __global__ void update_depth_cache_kernel(
bool old_valid = (old_val >= min_valid_depth && old_val <= max_valid_depth);

if (new_valid) {
cached_depth[idx] = new_val;
if (old_valid) {
cached_depth[idx] = old_val * (1.f-alpha_valid) + new_val * alpha_valid;
} else {
cached_depth[idx] = new_val;
}
} else if (old_valid) {
cached_depth[idx] = old_val * 0.5f + generated_val * 0.5f;
cached_depth[idx] = old_val * (1.f-alpha_invalid) + generated_val * alpha_invalid;
} else {
cached_depth[idx] = generated_val;
}
Expand All @@ -1318,6 +1376,8 @@ cudaError_t update_depth_cache(
const float* generated_depth,
const float* sparse_depth,
float* cached_depth,
float alpha_valid,
float alpha_invalid,
int width,
int height,
float min_valid_depth,
Expand All @@ -1330,6 +1390,7 @@ cudaError_t update_depth_cache(

update_depth_cache_kernel<<<grid, block, 0, stream>>>(
generated_depth, sparse_depth, cached_depth,
alpha_valid, alpha_invalid,
width, height,
min_valid_depth, max_valid_depth
);
Expand Down
Loading