Skip to content

Commit d38563c

Browse files
committed
Imported upstream version '2.0.0' of 'upstream'
1 parent 91bede1 commit d38563c

17 files changed

+652
-238
lines changed

.clang-format

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
---
2+
BasedOnStyle: Google
3+
ColumnLimit: 120
4+
MaxEmptyLinesToKeep: 1
5+
SortIncludes: false
6+
7+
Standard: Auto
8+
IndentWidth: 2
9+
TabWidth: 2
10+
UseTab: Never
11+
AccessModifierOffset: -2
12+
ConstructorInitializerIndentWidth: 2
13+
NamespaceIndentation: None
14+
ContinuationIndentWidth: 4
15+
IndentCaseLabels: true
16+
IndentFunctionDeclarationAfterType: false
17+
18+
AlignEscapedNewlinesLeft: false
19+
AlignTrailingComments: true
20+
21+
AllowAllParametersOfDeclarationOnNextLine: false
22+
ExperimentalAutoDetectBinPacking: false
23+
ObjCSpaceBeforeProtocolList: true
24+
Cpp11BracedListStyle: false
25+
26+
AllowShortBlocksOnASingleLine: true
27+
AllowShortIfStatementsOnASingleLine: false
28+
AllowShortLoopsOnASingleLine: false
29+
AllowShortFunctionsOnASingleLine: None
30+
AllowShortCaseLabelsOnASingleLine: false
31+
32+
AlwaysBreakTemplateDeclarations: true
33+
AlwaysBreakBeforeMultilineStrings: false
34+
BreakBeforeBinaryOperators: false
35+
BreakBeforeTernaryOperators: false
36+
BreakConstructorInitializersBeforeComma: true
37+
38+
BinPackParameters: true
39+
ConstructorInitializerAllOnOneLineOrOnePerLine: true
40+
DerivePointerBinding: false
41+
PointerBindsToType: true
42+
43+
PenaltyExcessCharacter: 50
44+
PenaltyBreakBeforeFirstCallParameter: 30
45+
PenaltyBreakComment: 1000
46+
PenaltyBreakFirstLessLess: 10
47+
PenaltyBreakString: 100
48+
PenaltyReturnTypeOnItsOwnLine: 50
49+
50+
SpacesBeforeTrailingComments: 2
51+
SpacesInParentheses: false
52+
SpacesInAngles: false
53+
SpaceInEmptyParentheses: false
54+
SpacesInCStyleCastParentheses: false
55+
SpaceAfterCStyleCast: false
56+
SpaceAfterControlStatementKeyword: true
57+
SpaceBeforeAssignmentOperators: true
58+
59+
# Configure each individual brace in BraceWrapping
60+
BreakBeforeBraces: Custom
61+
62+
# Control of individual brace wrapping cases
63+
BraceWrapping:
64+
AfterCaseLabel: true
65+
AfterClass: true
66+
AfterControlStatement: true
67+
AfterEnum: true
68+
AfterFunction: true
69+
AfterNamespace: true
70+
AfterStruct: true
71+
AfterUnion: true
72+
BeforeCatch: true
73+
BeforeElse: true
74+
IndentBraces: false
75+
...

.github/workflows/ci.yaml

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# This config uses industrial_ci (https://github.com/ros-industrial/industrial_ci.git).
2+
# For troubleshooting, see readme (https://github.com/ros-industrial/industrial_ci/blob/master/README.rst)
3+
4+
name: CI
5+
6+
on:
7+
workflow_dispatch:
8+
pull_request:
9+
push:
10+
11+
permissions:
12+
contents: read
13+
pages: write
14+
id-token: write
15+
16+
jobs:
17+
ici:
18+
strategy:
19+
fail-fast: false
20+
matrix:
21+
distro: [humble, rolling]
22+
include:
23+
- distro: humble
24+
env:
25+
CLANG_TIDY: true
26+
TARGET_CMAKE_ARGS: >-
27+
-DCMAKE_BUILD_TYPE=Release
28+
-DCMAKE_CXX_FLAGS="-Werror -Wall -Wextra -Wwrite-strings -Wunreachable-code -Wpointer-arith -Wredundant-decls -Wold-style-cast"
29+
30+
env:
31+
ROS_DISTRO: ${{ matrix.distro }}
32+
CLANG_TIDY_ARGS: -quiet -export-fixes ${{ github.workspace }}/.work/clang-tidy-fixes.yaml
33+
CCACHE_DIR: ${{ github.workspace }}/.ccache
34+
BASEDIR: ${{ github.workspace }}/.work
35+
CACHE_PREFIX: "${{ matrix.distro }}${{ contains(matrix.env.TARGET_CMAKE_ARGS, '--coverage') && '-ccov' || '' }}"
36+
# perform full clang-tidy check only on manual trigger (workflow_dispatch), PRs do check changed files, otherwise nothing
37+
CLANG_TIDY_BASE_REF: ${{ github.event_name != 'workflow_dispatch' && (github.base_ref || github.ref) || '' }}
38+
CC: ${{ matrix.env.CLANG_TIDY && 'clang' }}
39+
CXX: ${{ matrix.env.CLANG_TIDY && 'clang++' }}
40+
ADDITIONAL_DEBS: ${{ matrix.env.CLANG_TIDY && 'clang' }}
41+
CLANG_TIDY: ${{ matrix.env.CLANG_TIDY }}
42+
TARGET_CMAKE_ARGS: ${{ matrix.env.TARGET_CMAKE_ARGS }}
43+
44+
name: "${{ matrix.distro }}${{ matrix.env.NAME && ' • ' || ''}}${{ matrix.env.NAME }}${{ matrix.env.CLANG_TIDY && ' • clang-tidy' || '' }}"
45+
runs-on: ubuntu-latest
46+
steps:
47+
- uses: actions/checkout@v4
48+
49+
- name: Cache ccache
50+
uses: rhaschke/cache@main
51+
with:
52+
path: ${{ env.CCACHE_DIR }}
53+
key: ccache-${{ env.CACHE_PREFIX }}-${{ github.sha }}-${{ github.run_id }}
54+
restore-keys: |
55+
ccache-${{ env.CACHE_PREFIX }}-${{ github.sha }}
56+
ccache-${{ env.CACHE_PREFIX }}
57+
env:
58+
GHA_CACHE_SAVE: always
59+
60+
- id: ici
61+
name: Run industrial_ci
62+
uses: rhaschke/industrial_ci@master
63+
64+
- name: Upload clang-tidy fixes (on failure)
65+
uses: actions/upload-artifact@v4
66+
if: failure() && steps.ici.outputs.clang_tidy_checks
67+
with:
68+
name: clang-tidy-fixes.yaml
69+
path: ${{ env.BASEDIR }}/clang-tidy-fixes.yaml

.github/workflows/format.yaml

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# This is a format job. Pre-commit has a first-party GitHub action, so we use
2+
# that: https://github.com/pre-commit/action
3+
4+
name: Format
5+
6+
on:
7+
workflow_dispatch:
8+
pull_request:
9+
push:
10+
11+
jobs:
12+
pre-commit:
13+
name: pre-commit
14+
runs-on: ubuntu-20.04
15+
steps:
16+
- uses: actions/checkout@v4
17+
with:
18+
submodules: recursive
19+
- name: Install clang-format
20+
run: sudo apt-get install clang-format
21+
- uses: pre-commit/[email protected]
22+
id: precommit
23+
- name: Upload pre-commit changes
24+
if: failure() && steps.precommit.outcome == 'failure'
25+
uses: rhaschke/upload-git-patch-action@main
26+
with:
27+
name: pre-commit

.pre-commit-config.yaml

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# To use:
2+
#
3+
# pre-commit run -a
4+
#
5+
# Or:
6+
#
7+
# pre-commit install # (runs every time you commit in git)
8+
#
9+
# To update this file:
10+
#
11+
# pre-commit autoupdate
12+
#
13+
# See https://github.com/pre-commit/pre-commit
14+
15+
repos:
16+
# Standard hooks
17+
- repo: https://github.com/pre-commit/pre-commit-hooks
18+
rev: v4.6.0
19+
hooks:
20+
- id: check-added-large-files
21+
- id: check-case-conflict
22+
- id: check-merge-conflict
23+
- id: check-symlinks
24+
- id: check-xml
25+
- id: check-yaml
26+
- id: debug-statements
27+
- id: end-of-file-fixer
28+
- id: mixed-line-ending
29+
- id: trailing-whitespace
30+
31+
- repo: https://github.com/psf/black
32+
rev: 24.4.2
33+
hooks:
34+
- id: black
35+
args: ["--line-length", "100"]
36+
37+
- repo: local
38+
hooks:
39+
- id: clang-format
40+
name: clang-format
41+
description: Format files with ClangFormat.
42+
entry: clang-format
43+
language: system
44+
files: \.(c|cc|cxx|cpp|frag|glsl|h|hpp|hxx|ih|ispc|ipp|java|js|m|proto|vert)$
45+
args: ["-fallback-style=none", "-i"]

CHANGELOG.rst

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
Changelog for package py_binding_tools
33
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
44

5+
2.0.0 (2024-05-25)
6+
------------------
7+
* ROS2 migration
8+
* Contributors: Robert Haschke
9+
510
1.0.0 (2024-03-05)
611
------------------
712
* Initial release factored out from https://github.com/ros-planning/moveit/pull/2910

CMakeLists.txt

+42-33
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,56 @@
1-
cmake_minimum_required(VERSION 3.0.2)
1+
cmake_minimum_required(VERSION 3.5)
22
project(py_binding_tools)
33

4-
find_package(catkin REQUIRED
5-
COMPONENTS
6-
geometry_msgs
7-
pybind11_catkin
8-
roscpp
9-
)
10-
11-
# catkin_python_setup()
12-
13-
catkin_package(
14-
INCLUDE_DIRS include
15-
LIBRARIES ${PROJECT_NAME}
16-
CATKIN_DEPENDS geometry_msgs roscpp
17-
)
18-
19-
include_directories(include ${catkin_INCLUDE_DIRS})
4+
find_package(ament_cmake REQUIRED)
5+
find_package(ament_cmake_python REQUIRED)
6+
find_package(rclcpp REQUIRED)
7+
find_package(geometry_msgs REQUIRED)
8+
find_package(Python3 REQUIRED COMPONENTS Interpreter Development)
9+
find_package(pybind11_vendor REQUIRED)
10+
find_package(pybind11 REQUIRED)
2011

21-
add_library(${PROJECT_NAME}
12+
add_library(${PROJECT_NAME} SHARED
2213
src/ros_msg_typecasters.cpp
23-
src/roscpp_initializer.cpp
14+
src/initializer.cpp
2415
)
25-
add_dependencies(${PROJECT_NAME} ${catkin_EXPORTED_TARGETS})
26-
target_link_libraries(${PROJECT_NAME} ${catkin_LIBRARIES} ${PYTHON_LIBRARIES})
16+
target_include_directories(${PROJECT_NAME}
17+
PUBLIC
18+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
19+
$<INSTALL_INTERFACE:include/${PROJECT_NAME}>)
20+
ament_target_dependencies(${PROJECT_NAME} rclcpp geometry_msgs pybind11)
21+
22+
ament_export_targets(${PROJECT_NAME}Targets HAS_LIBRARY_TARGET)
2723

2824
install(
2925
TARGETS ${PROJECT_NAME}
30-
LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
31-
ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
32-
RUNTIME DESTINATION ${CATKIN_GLOBAL_BIN_DESTINATION}
26+
EXPORT ${PROJECT_NAME}Targets
27+
LIBRARY DESTINATION lib
28+
ARCHIVE DESTINATION lib
29+
RUNTIME DESTINATION bin
3330
)
3431

35-
install(DIRECTORY include/${PROJECT_NAME}/
36-
DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
32+
install(
33+
DIRECTORY include/
34+
DESTINATION include/${PROJECT_NAME}
3735
)
3836

39-
#catkin_lint cannot detect target declarations in functions, here in pybind11_add_module
40-
#catkin_lint: ignore undefined_target
37+
_ament_cmake_python_register_environment_hook()
38+
39+
pybind11_add_module(rclcpp src/rclcpp.cpp)
40+
target_link_libraries(rclcpp PRIVATE ${PROJECT_NAME})
41+
install(TARGETS rclcpp LIBRARY DESTINATION "${PYTHON_INSTALL_DIR}")
42+
43+
if(BUILD_TESTING)
44+
find_package(ament_cmake_pytest REQUIRED)
45+
find_package(std_msgs REQUIRED)
46+
47+
pybind11_add_module(${PROJECT_NAME}_test test/test.cpp)
48+
target_link_libraries(${PROJECT_NAME}_test PRIVATE ${PROJECT_NAME} ${std_msgs_TARGETS})
49+
install(TARGETS ${PROJECT_NAME}_test LIBRARY DESTINATION "${PYTHON_INSTALL_DIR}")
4150

42-
pybind_add_module(${PROJECT_NAME}_module src/${PROJECT_NAME}.cpp)
43-
set_target_properties(${PROJECT_NAME}_module PROPERTIES OUTPUT_NAME ${PROJECT_NAME})
44-
target_link_libraries(${PROJECT_NAME}_module PRIVATE ${PROJECT_NAME})
51+
ament_add_pytest_test(basic test/test_basic.py)
52+
endif()
4553

46-
install(TARGETS ${PROJECT_NAME}_module
47-
LIBRARY DESTINATION ${CATKIN_GLOBAL_PYTHON_DESTINATION})
54+
ament_export_dependencies(rclcpp)
55+
ament_export_dependencies(geometry_msgs)
56+
ament_package()

README.md

+4-6
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,14 @@ In this case, the string is interpreted as the `header.frame_id` field of the me
1919

2020
### C++ ROS initialization
2121

22-
C++ and Python use their own ROS implementations (`rospy` and `roscpp`).
22+
C++ and Python use their own RCL implementations (`rclpy` and `rclcpp`).
2323
Thus, it is necessary to initialize ROS in the C++ domain additionally to the Python domain before calling any ROS-related functions from wrapped C++ functions or classes.
24-
To this end, the package provides the python function `roscpp_init()` and the C++ class `ROScppInitializer`. The latter is intended to be used as a base class for your python wrapper classes:
24+
To this end, the package provides the python function `rclcpp.init()` and the C++ class `RCLInitializer`. The latter is intended to be used as a base class for your python wrapper classes:
2525

2626
```cpp
27-
class FooWrapper : protected ROScppInitializer, public Foo {
27+
class FooWrapper : protected RCLInitializer, public Foo {
2828
// ...
2929
};
3030
```
3131
32-
to ensure that the ROS infrastructure is initialized before usage in the wrapped C++ class. Ensure to list `ROScppInitializer` as the _first_ base class, if ROS functionality is required in the constructor already!
33-
34-
`ROScppInitializer` registers an anonymous C++ ROS node named `python_wrapper_xxx`. If you need a specific node name or if you want to pass remappings, use the manual initialization function `roscpp_init(name="", remappings={}, options=0)` instead, which effectively calls `ros::init` with the given arguments. Note, that an empty name will map to the above-mentioned node name `python_wrapper_xxx`.
32+
to ensure that the ROS infrastructure is initialized before usage in the wrapped C++ class. Ensure to list `RCLInitializer` as the _first_ base class, if ROS functionality is required in the constructor already!

include/py_binding_tools/geometry_msg_typecasters.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ namespace detail
4545
{
4646
/** Convienency type caster, also allowing to initialize PoseStamped from a string */
4747
template <>
48-
struct type_caster<geometry_msgs::PoseStamped> : RosMsgTypeCaster<geometry_msgs::PoseStamped>
48+
struct type_caster<geometry_msgs::msg::PoseStamped> : RosMsgTypeCaster<geometry_msgs::msg::PoseStamped>
4949
{
5050
// Python -> C++
5151
bool load(handle src, bool convert)
@@ -57,7 +57,7 @@ struct type_caster<geometry_msgs::PoseStamped> : RosMsgTypeCaster<geometry_msgs:
5757
value.pose.orientation.w = 1.0;
5858
return true;
5959
}
60-
return RosMsgTypeCaster<geometry_msgs::PoseStamped>::load(src, convert);
60+
return RosMsgTypeCaster<geometry_msgs::msg::PoseStamped>::load(src, convert);
6161
}
6262
};
6363

include/py_binding_tools/roscpp_initializer.h renamed to include/py_binding_tools/initializer.h

+9-13
Original file line numberDiff line numberDiff line change
@@ -33,26 +33,22 @@
3333
*********************************************************************/
3434
#pragma once
3535

36-
#include <ros/init.h>
36+
#include <string>
37+
#include <vector>
3738

3839
namespace py_binding_tools
3940
{
40-
/** The constructor of this class ensures that ros::init() has been called.
41+
/** The constructor of this class ensures that rclcpp::init() has been called.
4142
*
42-
* Thread safety and multiple initialization is properly handled.
43-
* The default node name is "python_wrapper".
44-
* If you like to have a custom name, use the roscpp_init() function before. */
45-
class ROScppInitializer
43+
* Thread safety and multiple initialization is properly handled. */
44+
class RCLInitializer
4645
{
4746
public:
48-
ROScppInitializer();
49-
~ROScppInitializer();
47+
RCLInitializer();
48+
~RCLInitializer();
5049
};
5150

52-
void roscpp_init(const std::string& node_name,
53-
const std::map<std::string, std::string>& remappings,
54-
uint32_t options);
55-
56-
void roscpp_shutdown();
51+
void init(const std::vector<std::string>& args);
52+
void shutdown();
5753

5854
} // namespace py_binding_tools

0 commit comments

Comments
 (0)