Skip to content

Commit 09ac187

Browse files
committed
First cut at ROS1-ROS2 hybrid
1 parent 7832937 commit 09ac187

File tree

11 files changed

+194
-127
lines changed

11 files changed

+194
-127
lines changed

.drone.yml

Lines changed: 0 additions & 84 deletions
This file was deleted.

.github/dependabot.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: github-actions
4+
directory: "/"
5+
schedule:
6+
interval: "weekly"

.github/mergify.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
pull_request_rules:
2+
3+
- name: ask to resolve conflict
4+
conditions:
5+
- conflict
6+
- author!=mergify[bot]
7+
actions:
8+
comment:
9+
message: This pull request is in conflict. Could you fix it @{{author}}?
10+
11+
- name: development targets main branch
12+
conditions:
13+
- base!=main
14+
- author!=mergify[bot]
15+
actions:
16+
comment:
17+
message: |
18+
Please target the `main` branch for development, we will backport the changes to {{base}} for you if approved and if they don't break API.

.github/workflows/ci.yaml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: ROS Industrial CI
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
workflow_dispatch:
9+
10+
jobs:
11+
industrial-ci:
12+
name: Run Industrial CI
13+
14+
strategy:
15+
fail-fast: false
16+
matrix:
17+
ros_distro: ["noetic", "jazzy", "rolling"]
18+
19+
steps:
20+
- name: Checkout repository
21+
uses: actions/checkout@v4
22+
with:
23+
submodules: recursive
24+
25+
- name: Run ROS Industrial CI
26+
uses: ros-industrial/industrial_ci@master
27+
environment:
28+
CI_ROS_DISTRO: ${{ matrix.ros_distro }}
29+
UPSTREAM_WORKSPACE: liboculus.repos

.github/workflows/format.yaml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Formatting (pre-commit)
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- main
8+
workflow_dispatch:
9+
10+
jobs:
11+
pre-commit:
12+
name: Format
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout repository
16+
uses: actions/checkout@v4
17+
18+
- name: Setup Python
19+
uses: actions/setup-python@v5
20+
with:
21+
python-version: "3.10"
22+
23+
- name: Install clang-format-14
24+
run: sudo apt-get install clang-format-14
25+
26+
- name: Run pre-commit
27+
uses: pre-commit/[email protected]
28+
id: precommit
29+
30+
- name: Upload pre-commit changes
31+
if: failure() && steps.precommit.outcome == 'failure'
32+
uses: rhaschke/upload-git-patch-action@main
33+
with:
34+
name: pre-commit

CMakeLists.txt

Lines changed: 87 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,18 @@
11
cmake_minimum_required(VERSION 3.5)
22
project(liboculus)
33

4+
# == Code common to all builds =======================================
5+
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
6+
47
if( FIPS_CONFIG AND NOT FIPS_IMPORT )
58
get_filename_component(FIPS_ROOT_DIR "../fips" ABSOLUTE)
69
include("${FIPS_ROOT_DIR}/cmake/fips.cmake")
710

811
fips_setup()
9-
else()
10-
find_package(catkin QUIET)
11-
endif()
12-
13-
# == Code common to all builds =======================================
14-
15-
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
16-
17-
find_package( Boost REQUIRED COMPONENTS system )
18-
find_package(g3log REQUIRED)
1912

20-
# Actually not using full SDK, just the header files
21-
# in thirdparty/Oculus
22-
#find_package( OculusSDK REQUIRED )
13+
find_package( Boost REQUIRED COMPONENTS system )
14+
find_package( g3log REQUIRED)
2315

24-
if (FIPS_CONFIG)
2516
#== fips-specific section ==========================================
2617
add_compile_options(-std=c++17)
2718

@@ -47,8 +38,25 @@ if (FIPS_CONFIG)
4738
fips_finish()
4839

4940
else()
50-
# == ament/ROS2 section =================================
51-
if(NOT FIPS_CONFIG)
41+
42+
# ROS build, determine which version...
43+
find_package(ros_environment REQUIRED)
44+
set(ROS_VERSION $ENV{ROS_VERSION})
45+
46+
set(oculus_SRCS
47+
lib/DataRx.cpp
48+
lib/SonarConfiguration.cpp
49+
lib/SonarStatus.cpp
50+
lib/StatusRx.cpp
51+
lib/SonarPlayer.cpp
52+
lib/OculusMessageHandler.cpp
53+
lib/SimpleFireMessage.cpp
54+
lib/IoServiceThread.cpp )
55+
56+
57+
if(${ROS_VERSION} EQUAL 2)
58+
# == ament/ROS2 section =================================
59+
5260
find_package(ament_cmake REQUIRED)
5361
find_package(Boost REQUIRED COMPONENTS system)
5462
find_package(g3log_ros REQUIRED)
@@ -60,31 +68,18 @@ else()
6068
include_directories(
6169
include
6270
thirdparty
63-
${CMAKE_INSTALL_PREFIX}/include/g3log
64-
)
65-
66-
set(oculus_SRCS
67-
lib/DataRx.cpp
68-
lib/SonarConfiguration.cpp
69-
lib/SonarStatus.cpp
70-
lib/StatusRx.cpp
71-
lib/SonarPlayer.cpp
72-
lib/OculusMessageHandler.cpp
73-
lib/SimpleFireMessage.cpp
74-
lib/IoServiceThread.cpp
7571
)
7672

7773
add_library(oculus SHARED ${oculus_SRCS})
7874
target_link_libraries(oculus
7975
Boost::system
80-
g3log_ros::g3log_ros
81-
g3log
76+
g3log_ros::g3log
8277
)
8378
ament_target_dependencies(oculus Boost g3log_ros)
8479

8580
install(
8681
TARGETS oculus
87-
EXPORT oculus
82+
EXPORT export_${PROJECT_NAME}
8883
ARCHIVE DESTINATION lib
8984
LIBRARY DESTINATION lib
9085
RUNTIME DESTINATION bin
@@ -97,11 +92,69 @@ else()
9792
PATTERN ".git" EXCLUDE
9893
)
9994

100-
ament_export_targets(oculus HAS_LIBRARY_TARGET)
95+
ament_export_targets(export_${PROJECT_NAME} HAS_LIBRARY_TARGET)
10196
ament_export_include_directories(include)
10297
ament_export_libraries(oculus)
10398

10499
ament_package()
105-
return()
100+
101+
elseif(${ROS_VERSION} EQUAL 1)
102+
103+
# Catkin/ROS1 section =====
104+
find_package( catkin REQUIRED COMPONENTS
105+
g3log_ros )
106+
find_package( Boost REQUIRED COMPONENTS system)
107+
108+
catkin_package(
109+
CATKIN_DEPENDS g3log_ros
110+
INCLUDE_DIRS include thirdparty
111+
LIBRARIES liboculus
112+
)
113+
114+
add_compile_options(-std=c++14)
115+
116+
add_library(liboculus
117+
${oculus_SRCS})
118+
119+
include_directories(liboculus
120+
include
121+
thirdparty
122+
${catkin_INCLUDE_DIRS}
123+
)
124+
125+
target_link_libraries(liboculus
126+
${catkin_LIBRARIES}
127+
)
128+
129+
install(TARGETS liboculus
130+
ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
131+
LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
132+
RUNTIME DESTINATION ${CATKIN_GLOBAL_BIN_DESTINATION}
133+
)
134+
135+
## Install headers
136+
install(DIRECTORY include/${PROJECT_NAME}/ thirdparty/
137+
DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
138+
FILES_MATCHING PATTERN "*.hpp" PATTERN "*.h"
139+
PATTERN ".git" EXCLUDE)
140+
141+
if (CATKIN_ENABLE_TESTING)
142+
add_definitions(-DTEST_DATA_PATH="${CMAKE_CURRENT_SOURCE_DIR}/test/data")
143+
include_directories( test/data/ )
144+
145+
file(GLOB oculus_test_SRCS
146+
test/unit/*cpp )
147+
148+
catkin_add_gtest(oculus_test ${oculus_test_SRCS})
149+
150+
target_link_libraries(oculus_test ${catkin_LIBRARIES}
151+
liboculus
152+
Boost::system )
153+
endif()
154+
155+
else()
156+
message("Unsure what sort of build to do. Not in a FIPS, ROS1 or ROS2 environment")
106157
endif()
107-
endif()
158+
159+
160+
endif()

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ This library contains code for:
1313
- Decoding and parsing fields from the resulting ping messages from the sonar.
1414
- Loading and parsing sonar data recorded as either:
1515
- Raw streams of binary packets.
16-
- **Note:** This repo includes scaffold code for reading `.oculus` files saved from the Blueprint GUI, but that format is proprietary and undocumented **we cannot parse `.oculus` files.**
16+
- **Note:** This repo includes scaffold code for reading `.oculus` files saved from the Blueprint GUI, but that format is proprietary and undocumented. **We cannot parse `.oculus` files!!**
1717

1818
The library contains no special provisions for *saving* sonar data,
1919
but it's straightforward to write packets as a raw binary stream
@@ -25,12 +25,12 @@ but it's straightforward to write packets as a raw binary stream
2525

2626
This is a hybrid repository:
2727

28-
* We primarily build using catkin, though there are no ROS dependencies in the code. We hope the code is still useful for others looking to talk to the Oculus.
28+
* We primarily build in ROS1 or ROS2, though there are no ROS dependencies in the code. We hope the code is still useful for others looking to talk to the Oculus. It is implemented as a hybrid package which should build successfully in either a ROS1 "catkin" or ROS2 "colcon" workspace.
2929

3030
* Historically, the repo has also supported the [fips](http://floooh.github.io/fips/) C++ dependency management tool. To build with fips: `./fips build`
3131

3232
The primary dependency is on [g3log](https://github.com/KjellKod/g3log).
33-
* If using catkin, there are two options:
33+
* If using ROS1 or ROS2, there are two options:
3434
* clone [g3log_ros](https://gitlab.com/apl-ocean-engineering/g3log_ros) into your workspace's `src/` directory
3535
* use the provided `liboculus.rosinstall` file: `cd <catkin_ws>/src`; `vcs import --input liboculus/liboculus.repos`
3636
* It will be handled automagically if using fips.
@@ -119,4 +119,4 @@ Other files/classes:
119119

120120
This code is released under the [BSD 3-clause license](LICENSE).
121121

122-
This repository contains one file provided by Blueprint as part of their free "Oculus Viewer" sample application ([thirdparty/Oculus/Oculus.h](thirdpart/Oculus/Oculus.h)), which describes their protocol and data formats. This file is distributed under [GPLv3](https://www.gnu.org/licenses/gpl-3.0.en.html).
122+
This repository contains one file provided by Blueprint as part of their free "Oculus Viewer" sample application: ([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).

include/liboculus/DataRx.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ class DataRx : public OculusMessageHandler {
108108

109109
}; // class DataRx
110110

111-
template <typename FireMsg_t = OculusSimpleFireMessage2>
111+
template <typename FireMsg_t>
112112
void DataRx::sendSimpleFireMessage(const SonarConfiguration &config) {
113113
if (!isConnected()) {
114114
LOG(WARNING) << "Can't send to sonar, not connected";

liboculus.repos

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
repositories:
2+
g3log_ros:
3+
type: git
4+
url: https://gitlab.com/apl-ocean-engineering/g3log_ros.git
5+
version: main

liboculus.rosinstall

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)