Skip to content
Merged
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
8 changes: 5 additions & 3 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ jobs:
fail-fast: false
matrix:
env:
- {UPSTREAM_WORKSPACE: liboculus.repos, ROS_DISTRO: noetic}
- {UPSTREAM_WORKSPACE: liboculus.repos, ROS_DISTRO: kilted}
- {UPSTREAM_WORKSPACE: liboculus.repos, ROS_DISTRO: rolling}
- {ROS_DISTRO: noetic}
# We include humble because there are still 22.04 systems (Jetson) out there
- {ROS_DISTRO: humble}
- {ROS_DISTRO: kilted}
- {ROS_DISTRO: rolling}

steps:
- name: Checkout repository
Expand Down
115 changes: 15 additions & 100 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.8)
cmake_minimum_required(VERSION 3.14.4)
project(liboculus)

set(CMAKE_CXX_STANDARD 17)
Expand All @@ -9,113 +9,28 @@ add_compile_options(-std=c++17)
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)

set(oculus_SRCS
lib/DataRx.cpp
lib/SonarConfiguration.cpp
lib/SonarStatus.cpp
lib/StatusRx.cpp
lib/SonarPlayer.cpp
lib/OculusMessageHandler.cpp
lib/SimpleFireMessage.cpp
lib/IoServiceThread.cpp
src/DataRx.cpp
src/SonarConfiguration.cpp
src/SonarStatus.cpp
src/StatusRx.cpp
src/SonarPlayer.cpp
src/OculusMessageHandler.cpp
src/SimpleFireMessage.cpp
src/IoServiceThread.cpp
)

# ROS build, determine which version...
# QUIET will squelch the warning if the package isn't found
find_package(ros_environment QUIET)
if(DEFINED ENV{ROS_DISTRO})
find_package(ros_environment)

if(${ros_environment_FOUND})
set(ROS_VERSION $ENV{ROS_VERSION})

if(${ROS_VERSION} EQUAL 2)
# == ament/ROS2 section =================================

find_package(ament_cmake REQUIRED)
find_package(Boost REQUIRED COMPONENTS system)
find_package(g3log_ros REQUIRED)

add_library(oculus SHARED ${oculus_SRCS})
target_link_libraries(oculus PUBLIC Boost::system g3log_ros::g3log)

target_include_directories(
oculus
PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
"$<INSTALL_INTERFACE:include/>"
)

install(
TARGETS oculus
EXPORT export_${PROJECT_NAME}
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
)

install(
DIRECTORY include/
DESTINATION include
FILES_MATCHING
PATTERN "*.hpp"
PATTERN "*.h"
PATTERN ".git" EXCLUDE
)

ament_export_dependencies(g3log_ros)
ament_export_targets(export_${PROJECT_NAME} HAS_LIBRARY_TARGET)
ament_export_libraries(oculus)

ament_package()
message(NOTICE "!! Performing ROS2 build !!")
include(cmake/BuildROS2.cmake)
elseif(${ROS_VERSION} EQUAL 1)
# Catkin/ROS1 section =====
find_package(catkin REQUIRED COMPONENTS g3log_ros)
find_package(Boost REQUIRED COMPONENTS system)

catkin_package(
CATKIN_DEPENDS g3log_ros
INCLUDE_DIRS include
LIBRARIES liboculus
)

add_library(liboculus ${oculus_SRCS})

include_directories(liboculus include ${catkin_INCLUDE_DIRS})

target_link_libraries(liboculus ${catkin_LIBRARIES})

install(
TARGETS liboculus
ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
RUNTIME DESTINATION ${CATKIN_GLOBAL_BIN_DESTINATION}
)

## Install headers
install(
DIRECTORY include/${PROJECT_NAME}/
DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
FILES_MATCHING
PATTERN "*.hpp"
PATTERN "*.h"
PATTERN ".git" EXCLUDE
)

if(CATKIN_ENABLE_TESTING)
add_definitions(
-DTEST_DATA_PATH="${CMAKE_CURRENT_SOURCE_DIR}/test/data"
)
include_directories(test/data/)

file(GLOB oculus_test_SRCS test/unit/*cpp)

catkin_add_gtest(oculus_test ${oculus_test_SRCS})

target_link_libraries(
oculus_test
${catkin_LIBRARIES}
liboculus
Boost::system
)
endif()
message(NOTICE "!! Performing ROS1 build !!")
include(cmake/BuildROS1.cmake)
else()
message(
"Unsure what sort of build to do. Not in a ROS1 or ROS2 environment"
Expand Down
40 changes: 28 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
>
> January 2026
>
> This is the primary, 'v3' [`main` branch](https://github.com/apl-ocean-engineering/liboculus), which replaces G3Log with [`spdlog`](https://github.com/gabime/spdlog) along with other changes under the good.
> This is the [main/`v3` branch](https://github.com/apl-ocean-engineering/liboculus), which replaces G3Log with [`spdlog`](https://github.com/gabime/spdlog) along with other changes under the good.
>
> The 'v2' branch of this liboculus; with a matching 'v2' branch for [oculus_sonar_driver](https://gitlab.com/apl-ocean-engineering/oculus_sonar_driver/-/commits/v2) includes a hybrid CMakeLists.txt which can build for ROS1, ROS2 or in a plain CMake environment. G3Log is still used as the main logger.
>
Expand Down Expand Up @@ -39,17 +39,6 @@ This is a hybrid repository which builds in either ROS1 or ROS2, though there ar

We hope the code is still useful for others looking to talk to the Oculus.

> [!NOTE] [fips](http://floooh.github.io/fips/) support has been removed from this branch.

The primary dependency is on [g3log](https://github.com/KjellKod/g3log).
* If using either ROS1 or ROS2, use the provided `liboculus.rosinstall` file:

```
cd <catkin_ws>/src`; `vcs import --recursive --input liboculus/liboculus.repos
```

The `main` branch of `g3log_ros` is also a ROS1-ROS2 hybrid.

The (optional) test suite also requires Googletest and the (also optional)
binary `oc_client` requires [CLI11](https://github.com/CLIUtils/CLI11).

Expand All @@ -68,6 +57,29 @@ make

Note the `CMakelists.txt` attempts to auto-detect ROS. Cmake build should be done in a session where ROS has not been loaded.

## Logging

> [!NOTE] [fips](http://floooh.github.io/fips/) support has been removed from this version.
> [!NOTE] The dependency on [g3log](https://github.com/KjellKod/g3log) has been removed.

Internally the library uses [spdlog](https://github.com/gabime/spdlog). By default logger `"liboculus"` does not have any registered sinks and does not output to the console.

If the calling application uses spdlog, either the library's logger can be reset:

```
liboculus::Logger::set_logger( spdlog::default_logger() );
```

or a sink can be added to the library's logger:

```
auto stdout_sink = std::make_shared<spdlog::sinks::stdout_color_sink_mt >(); liboculus::Logger::add_sink( stdout_sink );
```





---
## oc_client binary

Expand Down Expand Up @@ -149,3 +161,7 @@ Other files/classes:
This code is released under the [BSD 3-clause license](LICENSE).

This repository contains one file provided by Blueprint as part of their free "Oculus Viewer" sample application: ([include/liboculus/thirdparty/Oculus/Oculus.h](thirdpart/Oculus/Oculus.h)). It describes their protocol and data formats. This file is distributed under [GPLv3](https://www.gnu.org/licenses/gpl-3.0.en.html).

It includes the header-only version of [CLI11](https://github.com/CLIUtils/CLI11) at [`include/liboculus/thirdparty/CLI11/`](include/liboculus/thirdparty/CLI11/)

It includes the header-only version of TartanLlama's [`expected` implementation](https://github.com/TartanLlama/expected) at [`include/liboculus/thirdparty/expected.hpp`](include/liboculus/thirdparty/expected.hpp)
34 changes: 9 additions & 25 deletions cmake/BuildNonROS.cmake
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# Specify the minimum version for CMake
cmake_minimum_required(VERSION 3.8)

# Project's name
project(liboculus)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -march=native -Wl,--no-as-needed")
Expand All @@ -13,36 +11,18 @@ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib)
# ###########################################
# The following folders will be included #
# ###########################################
include_directories(
"${PROJECT_SOURCE_DIR}/include/"
"${PROJECT_SOURCE_DIR}/thirdparty/"
)
include_directories("${PROJECT_SOURCE_DIR}/include/")

# Threading
find_package(Threads)
find_package(spdlog)
find_package(fmt)

# Boost
find_package(Boost 1.57 REQUIRED COMPONENTS system)
include_directories(${Boost_INCLUDE_DIR})
message("Boost_INCLUDE_DIR: " ${Boost_INCLUDE_DIR})

# Install g3log as an external package
include(cmake/IncludeProject.cmake)

if(NOT GIT_TAG)
set(GIT_TAG "2.6")
endif()

include(ExternalProject)
ExternalProject_Add(
g3log
GIT_REPOSITORY https://github.com/KjellKod/g3log
GIT_TAG ${GIT_TAG}
INSTALL_DIR "${CMAKE_CURRENT_BINARY_DIR}/install/g3log"
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>
)

ExternalProject_Get_Property(g3log install_dir)
include_directories(${install_dir}/include/)

# #####################
Expand All @@ -53,13 +33,17 @@ link_directories(${Boost_LIBRARY_DIRS})
# Create Library
add_library(oculus SHARED ${oculus_SRCS})
set_target_properties(oculus PROPERTIES LIBRARY_OUTPUT_NAME oculus)
target_link_libraries(oculus PUBLIC fmt::fmt spdlog::spdlog)

add_executable(occlient ${PROJECT_SOURCE_DIR}/tools/oculus_client.cpp)
target_link_libraries(occlient oculus)

# =============================================
# to allow find_package()
# =============================================
#
# The following is borrowed heavily from:
# https://github.com/RossHartley/invariant-ekf
# https://github.com/RossHartley/invariant-ekf
# I am responsible for all mistakes
#
# the following case be used in an external project requiring oculus:
Expand Down Expand Up @@ -102,7 +86,7 @@ configure_file(

message("PROJECT_BINARY_DIR: " ${PROJECT_BINARY_DIR})

# # 2- installation build #
# 2- installation build #

# Change the include location for the case of an install location
set(oculus_include_dirs ${CMAKE_INSTALL_PREFIX}/include ${EIGEN_INCLUDE_DIR})
Expand Down
46 changes: 46 additions & 0 deletions cmake/BuildROS1.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Catkin/ROS1 section =====
find_package(Boost REQUIRED COMPONENTS system)

catkin_package(
INCLUDE_DIRS include
LIBRARIES liboculus
)

add_library(liboculus ${oculus_SRCS})

include_directories(liboculus include ${catkin_INCLUDE_DIRS})

target_link_libraries(liboculus ${catkin_LIBRARIES})

install(
TARGETS liboculus
ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
RUNTIME DESTINATION ${CATKIN_GLOBAL_BIN_DESTINATION}
)

## Install headers
install(
DIRECTORY include/${PROJECT_NAME}/
DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
FILES_MATCHING
PATTERN "*.hpp"
PATTERN "*.h"
PATTERN ".git" EXCLUDE
)

if(CATKIN_ENABLE_TESTING)
add_definitions(-DTEST_DATA_PATH="${CMAKE_CURRENT_SOURCE_DIR}/test/data")
include_directories(test/data/)

file(GLOB oculus_test_SRCS test/unit/*cpp)

catkin_add_gtest(oculus_test ${oculus_test_SRCS})

target_link_libraries(
oculus_test
${catkin_LIBRARIES}
liboculus
Boost::system
)
endif()
36 changes: 36 additions & 0 deletions cmake/BuildROS2.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# == ament/ROS2 section =================================

find_package(ament_cmake REQUIRED)
find_package(Boost REQUIRED COMPONENTS system)

add_library(oculus SHARED ${oculus_SRCS})
target_link_libraries(oculus PUBLIC Boost::system)

target_include_directories(
oculus
PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
"$<INSTALL_INTERFACE:include/>"
)

install(
TARGETS oculus
EXPORT export_${PROJECT_NAME}
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
)

install(
DIRECTORY include/
DESTINATION include
FILES_MATCHING
PATTERN "*.hpp"
PATTERN "*.h"
PATTERN ".git" EXCLUDE
)

ament_export_targets(export_${PROJECT_NAME} HAS_LIBRARY_TARGET)
ament_export_libraries(oculus)

ament_package()
Loading
Loading