Skip to content

Commit

Permalink
feat: Add installation procedure for ROS 2 and change Python bindings…
Browse files Browse the repository at this point in the history
… package name
  • Loading branch information
2b-t committed Nov 19, 2023
1 parent 5c1454d commit 1f26489
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 18 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*.pyc
build/
myactuator_rmd.egg-info/
myactuator_rmd_py.egg-info/

36 changes: 25 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ include(ConfigExtras.cmake)
include_directories(
include/
)

add_library(myactuator_rmd SHARED
src/can/node.cpp
src/can/utilities.cpp
Expand All @@ -33,19 +32,31 @@ add_library(myactuator_rmd SHARED
)
set(MYACTUATOR_RMD_LIBRARIES "")
target_link_libraries(myactuator_rmd ${MYACTUATOR_RMD_LIBRARIES})
install(TARGETS
myactuator_rmd
DESTINATION lib/${PROJECT_NAME}
install(
DIRECTORY include/
DESTINATION include/${PROJECT_NAME}
)
install(TARGETS myactuator_rmd
EXPORT export_${PROJECT_NAME}
RUNTIME DESTINATION bin
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
)

if(PYTHON_BINDINGS)
pybind11_add_module(pymyactuator_rmd bindings/myactuator_rmd.cpp)
target_link_libraries(pymyactuator_rmd PRIVATE myactuator_rmd)
set_target_properties(pymyactuator_rmd PROPERTIES OUTPUT_NAME myactuator_rmd)

install(TARGETS
pymyactuator_rmd
DESTINATION lib/${PROJECT_NAME}
pybind11_add_module(myactuator_rmd_py
bindings/myactuator_rmd.cpp
)
target_link_libraries(myactuator_rmd_py PUBLIC
myactuator_rmd
)

if(ament_cmake_FOUND)
find_package(ament_cmake_python REQUIRED)
ament_python_install_package(${PROJECT_NAME})
endif()
install(TARGETS myactuator_rmd_py
DESTINATION ${PYTHON_INSTALL_DIR}/${PROJECT_NAME}
)
endif()

Expand Down Expand Up @@ -84,5 +95,8 @@ if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING)
endif()

if(ament_cmake_FOUND)
ament_export_targets(export_${PROJECT_NAME} HAS_LIBRARY_TARGET)
ament_export_dependencies(ament_cmake)
ament_export_dependencies(ament_cmake_python)
ament_package(CONFIG_EXTRAS ConfigExtras.cmake)
endif()
6 changes: 3 additions & 3 deletions ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ For **building and installing the Python bindings** for this driver open a new t
$ pip3 install .
```

This will use the `setup.py` to invoke CMake and install the bindings as a C++ library. If you want to remove them again simply invoke `$ pip3 uninstall myactuator_rmd`.
This will use the `setup.py` to invoke CMake and install the bindings as a C++ library. If you want to remove them again simply invoke `$ pip3 uninstall myactuator-rmd-py`.



Expand All @@ -63,15 +63,15 @@ This will use the `setup.py` to invoke CMake and install the bindings as a C++ l
$ python3
Python 3.10.6 (main, Mar 10 2023, 10:55:28) [GCC 11.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from myactuator_rmd import Driver
>>> from myactuator_rmd_py import Driver
>>> driver = Driver("can0", 1)
>>> driver.getVersionDate()
2023020601
>>> driver.sendPositionAbsoluteSetpoint(180.0, 500.0)
>>> driver.shutdownMotor()
```

For more information you might also inspect the contents of the module inside Python 3 with `help(myactuator_rmd)`.
For more information you might also inspect the contents of the module inside Python 3 with `help(myactuator_rmd_py)`.



Expand Down
2 changes: 1 addition & 1 deletion bindings/myactuator_rmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#include "myactuator_rmd/io.hpp"


PYBIND11_MODULE(myactuator_rmd, m) {
PYBIND11_MODULE(myactuator_rmd_py, m) {

m.doc() = "MyActuator RMD driver main module";
pybind11::class_<myactuator_rmd::Driver>(m, "Driver")
Expand Down
1 change: 1 addition & 0 deletions myactuator_rmd/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from myactuator_rmd.myactuator_rmd_py import *
4 changes: 4 additions & 0 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
<license>MIT</license>

<buildtool_depend>ament_cmake_ros</buildtool_depend>
<buildtool_depend>ament_cmake_python</buildtool_depend>
<buildtool_depend>python_cmake_module</buildtool_depend>

<depend>pybind11_vendor</depend>

<test_depend>ament_lint_auto</test_depend>
<test_depend>ament_lint_common</test_depend>
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ def build_extension(self, ext: CMakeExtension) -> None:


setup(
name="myactuator_rmd",
name="myactuator_rmd_py",
version="0.0.1",
author="Tobit Flatscher",
author_email="tobit.flatscher@outlook.com",
description="CAN driver for the MyActuator RMD X actuator series",
long_description="",
ext_modules=[CMakeExtension("myactuator_rmd")],
ext_modules=[CMakeExtension("myactuator_rmd_py")],
cmdclass={"build_ext": CMakeBuild},
zip_safe=False,
extras_require={"test": ["pytest>=6.0"]},
Expand Down

0 comments on commit 1f26489

Please sign in to comment.