Skip to content

Commit

Permalink
Merge pull request #2 from VokunGahrotLaas/main
Browse files Browse the repository at this point in the history
auto generation of ros2_control_py
  • Loading branch information
olivier-stasse authored Oct 27, 2023
2 parents 5365f55 + 9c18b6a commit cbb9cb2
Show file tree
Hide file tree
Showing 38 changed files with 5,589 additions and 265 deletions.
1 change: 1 addition & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
BasedOnStyle: Google
20 changes: 20 additions & 0 deletions .github/workflows/humble.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: humble

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
build-humble:
runs-on: ubuntu-latest
container: ubuntu:jammy
steps:
- uses: ros-tooling/[email protected]
with:
required-ros-distributions: humble
- uses: ros-tooling/[email protected]
with:
package-name: ros2_control_py
target-ros2-distro: humble
20 changes: 20 additions & 0 deletions .github/workflows/rolling.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: rolling

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
build-rolling:
runs-on: ubuntu-latest
container: ubuntu:jammy
steps:
- uses: ros-tooling/[email protected]
with:
required-ros-distributions: rolling
- uses: ros-tooling/[email protected]
with:
package-name: ros2_control_py
target-ros2-distro: rolling
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
build
.cache
compile_commands.json
tmp
install
log
__pycache__
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "builder/cppparser"]
path = builder/cppparser
url = https://github.com/Gepetto/cppparser
20 changes: 9 additions & 11 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
repos:
# Standard hooks
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.5.0
hooks:
- id: check-added-large-files
- id: check-case-conflict
Expand All @@ -33,21 +33,19 @@ repos:
- id: trailing-whitespace

- repo: https://github.com/psf/black
rev: 23.3.0
rev: 23.10.0
hooks:
- id: black

- repo: local
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v17.0.3
hooks:
- id: clang-format
name: clang-format
description: Format files with ClangFormat.
entry: clang-format
language: system
files: \.(c|cc|cxx|cpp|frag|glsl|h|hpp|hxx|ih|ispc|ipp|java|js|m|proto|vert)$
args: ['-fallback-style=none', '-i']
- id: clang-format
args: [-i]
types_or: [c++]

- repo: https://github.com/codespell-project/codespell
rev: v2.2.4
rev: v2.2.6
hooks:
- id: codespell
args: ['--write-changes', '--ignore-words=.codespell_words', '--skip="*.eps"']
Expand Down
111 changes: 92 additions & 19 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,30 +1,103 @@
cmake_minimum_required(VERSION 3.5)
project(ros2_control_py)
cmake_minimum_required(VERSION 3.20)

project(ros2_control_py VERSION 0.0.2)

## default ros std versions/warnings
# Default to C++17
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
endif()
# Default to C11
if(NOT CMAKE_C_STANDARD)
set(CMAKE_C_STANDARD 11)
endif()
if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic)
endif()

## sanitize address gcc/clang
if(SANITIZE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-omit-frame-pointer -fsanitize=address,undefined,leak")
set(CMAKE_LINKER_FLAGS "${CMAKE_LINKER_FLAGS} -fno-omit-frame-pointer -fsanitize=address,undefined,leak")
endif()

# ROS deps
find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(rclcpp_lifecycle REQUIRED)
find_package(ament_cmake_python REQUIRED)
find_package(rclpy REQUIRED)
find_package(controller_interface REQUIRED)
find_package(controller_manager REQUIRED)
find_package(controller_manager_msgs REQUIRED)
find_package(hardware_interface REQUIRED)
# Python deps
find_package(Python3 REQUIRED COMPONENTS Interpreter Development)
find_package(pybind11_vendor REQUIRED)
find_package(pybind11 REQUIRED)

ament_python_install_package(ros2_control_py)
## compiles builder
add_subdirectory(builder)

## Vars
set(_ros2_py_modules
hardware_interface
controller_interface
ros2_control_test_assets
)

set(_ros2_py_src_dir ${CMAKE_CURRENT_BINARY_DIR}/src)

set(_ros2_py_src ${_ros2_py_modules})
list(TRANSFORM _ros2_py_src PREPEND ${_ros2_py_src_dir}/)
list(TRANSFORM _ros2_py_src APPEND _py.cpp)

add_custom_command(
OUTPUT ${_ros2_py_src}
COMMAND builder "${_ros2_py_src_dir}" "/opt/ros/$ENV{ROS_DISTRO}/include" "$ENV{ROS_DISTRO}" ${_ros2_py_modules}
DEPENDS builder
)
add_custom_target(run_builder
DEPENDS ${_ros2_py_src}
)

pybind11_add_module(ros2_control_py_core
src/ros2_control_py/core.cpp
src/ros2_control_py/hardware_interface/hardware_interface.cpp
)
# __init__ in build/ for tests
configure_file("${CMAKE_CURRENT_LIST_DIR}/python/${PROJECT_NAME}/__init__.py"
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}/__init__.py"
COPYONLY
)
# __init__ in install/
ament_python_install_package(${PROJECT_NAME}
PACKAGE_DIR "${CMAKE_CURRENT_LIST_DIR}/python/${PROJECT_NAME}"
)
# python modules
foreach(_module ${_ros2_py_modules})
find_package(${_module} REQUIRED)
pybind11_add_module(${_module}_py
"${_ros2_py_src_dir}/${_module}_py.cpp"
)
add_dependencies(${_module}_py run_builder)
set_target_properties(${_module}_py
PROPERTIES OUTPUT_NAME ${PROJECT_NAME}/${_module}
)
target_include_directories(${_module}_py PRIVATE
"${_ros2_py_src_dir}"
)
ament_target_dependencies(${_module}_py PUBLIC
rclpy
${_module}
)
# ${PYTHON_INSTALL_DIR} is exported by ament_python_install_package() above
install(TARGETS ${_module}_py
DESTINATION "${PYTHON_INSTALL_DIR}/${PROJECT_NAME}"
)
endforeach()

ament_target_dependencies(ros2_control_py_core PUBLIC
rclcpp
rclcpp_lifecycle
hardware_interface)
if(BUILD_TESTING)
find_package(ament_cmake_pytest REQUIRED)
file(GLOB_RECURSE _pytest_tests CONFIGURE_DEPENDS RELATIVE "${CMAKE_CURRENT_LIST_DIR}" "tests/test_*.py" "tests/*/test_*.py")
foreach(_test_path ${_pytest_tests})
cmake_path(RELATIVE_PATH _test_path
BASE_DIRECTORY "tests/"
OUTPUT_VARIABLE _test_name
)
ament_add_pytest_test(${_test_name} ${_test_path})
endforeach()
endif()

install(TARGETS ros2_control_py_core
DESTINATION "${PYTHON_INSTALL_DIR}/ros2_control_py")
ament_package()
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,34 @@
# Python bindings for ros2_control using pybind11

-------------------------------------------------

## Install

Assuming that your [ros2_control](https://github.com/ros-controls/ros2_control) workspace is in the directory `~/ros2_control_py_ws`:

```sh
mkdir -p ~/ros2_control_py_ws/src
cd ~/ros2_control_py_ws/src
git clone https://github.com/Gepetto/ros2_control_py --recursive
cd ~/ros2_control_py_ws
rosdep install --from-paths src -y --ignore-src
```

## Compiling

```sh
cd ~/ros2_control_py_ws
colcon build
```

## Testing

```sh
cd ~/ros2_control_py_ws
colcon build --cmake-args ' -DCMAKE_BUILD_TYPE=Debug -DSANITIZE'
colcon test
```

## Usage

See [doc](doc/index.rst) and [tests](tests/).
11 changes: 11 additions & 0 deletions builder/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
cmake_minimum_required(VERSION 3.5)

add_subdirectory(cppparser)

add_executable(builder
src/main.cpp
)
target_link_libraries(builder
PRIVATE
cppparser
)
1 change: 1 addition & 0 deletions builder/cppparser
Submodule cppparser added at 157aac
Loading

0 comments on commit cbb9cb2

Please sign in to comment.