Skip to content

Commit

Permalink
Merge pull request #7 from cmastalli/topic/ros2-migration
Browse files Browse the repository at this point in the history
ROS2 support
  • Loading branch information
cmastalli authored Jul 7, 2023
2 parents f5cb651 + 9a66776 commit 26818d3
Show file tree
Hide file tree
Showing 22 changed files with 1,014 additions and 601 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ jobs:
strategy:
matrix:
env:
- {ROS_DISTRO: noetic}
- {ROS_DISTRO: noetic, PRERELEASE: true}
- {ROS_DISTRO: humble}
- {ROS_DISTRO: rolling}
env:
PRERELEASE: true
UPSTREAM_WORKSPACE: dependencies.rosinstall
runs-on: ubuntu-latest
steps:
Expand Down
161 changes: 109 additions & 52 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
cmake_minimum_required(VERSION 3.1)
cmake_minimum_required(VERSION 3.3)
project(crocoddyl_msgs)

if(CMAKE_CXX_COMPILER_ID MATCHES "(GNU|Clang)")
add_compile_options(-Wall -Wextra -Wpedantic -Wno-sign-conversion)
endif()

# Set up project properties
set(PROJECT_NAME crocoddyl_msgs)
set(PROJECT_DESCRIPTION "Crocoddyl ROS messages")
Expand All @@ -15,61 +19,114 @@ message(STATUS "Released under the BSD 3-Clause License.")
# Find required packages
find_package(Eigen3 REQUIRED)
find_package(pinocchio REQUIRED)
find_package(
catkin REQUIRED COMPONENTS roscpp std_msgs whole_body_state_msgs
message_generation realtime_tools pybind11_catkin)

# Define messages to be generated
add_message_files(
DIRECTORY
msg
FILES
TimeInterval.msg
State.msg
Control.msg
FeedbackGain.msg
SolverStatistics.msg
SolverTrajectory.msg)
generate_messages(DEPENDENCIES std_msgs)

# Define catkin dependencies
catkin_package(
INCLUDE_DIRS
include
CATKIN_DEPENDS
message_runtime
std_msgs
whole_body_state_msgs
DEPENDS)

# Define the Python modules
set(${PROJECT_NAME}_PYBIND11_MODULE crocoddyl_ros)

if(APPLE AND ${pybind11_catkin_VERSION} VERSION_LESS "2.10.3")
add_definitions(-DCROCODDYL_MSG_DISABLE_PYBIND11_WARNINGS)
if($ENV{ROS_VERSION} EQUAL 2) # ROS 2
add_definitions(-DROS2)
# Default to C++14
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 14)
endif()
# Find ROS2 required packages
set(PACKAGE_DEPENDENCIES rclcpp std_msgs whole_body_state_msgs realtime_tools
pybind11)
find_package(ament_cmake REQUIRED)
find_package(rosidl_default_generators REQUIRED)
foreach(DEPENDENCY IN ITEMS ${PACKAGE_DEPENDENCIES})
find_package(${DEPENDENCY} REQUIRED)
endforeach()
# Define messages to be generated
rosidl_generate_interfaces(
${PROJECT_NAME}
"msg/TimeInterval.msg"
"msg/State.msg"
"msg/Control.msg"
"msg/FeedbackGain.msg"
"msg/SolverStatistics.msg"
"msg/SolverTrajectory.msg"
DEPENDENCIES
std_msgs
whole_body_state_msgs)
# Add warning definitions
if(APPLE AND ${pybind11_VERSION} VERSION_LESS "2.10.3")
add_definitions(-DCROCODDYL_MSG_DISABLE_PYBIND11_WARNINGS)
endif()
# Build the Python interface for the ROS publisher and subscriber
foreach(PYBIND11_MODULE ${${PROJECT_NAME}_PYBIND11_MODULE})
pybind11_add_module(${PYBIND11_MODULE} MODULE src/${PYBIND11_MODULE}.cpp)
target_include_directories(
${PYBIND11_MODULE}
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
${EIGEN3_INCLUDE_DIR} $<INSTALL_INTERFACE:include>)
ament_target_dependencies(${PYBIND11_MODULE} PUBLIC ${PACKAGE_DEPENDENCIES})
rosidl_get_typesupport_target(cpp_typesupport_target ${PROJECT_NAME}
rosidl_typesupport_cpp)
target_link_libraries(
${PYBIND11_MODULE} PUBLIC ${cpp_typesupport_target} ${Boost_LIBRARIES}
${Boost_PYTHON_LIBRARY} pinocchio::pinocchio)
set_target_properties(${PYBIND11_MODULE} PROPERTIES LIBRARY_OUTPUT_DIRECTORY
lib/${PROJECT_NAME})
install(TARGETS ${PYBIND11_MODULE}
LIBRARY DESTINATION ${PYTHON_INSTALL_DIR})
endforeach(PYBIND11_MODULE ${${PROJECT_NAME}_PYBIND11_MODULE})
# Install the include files
install(DIRECTORY include/${PROJECT_NAME}/
DESTINATION include/${PROJECT_NAME})
ament_export_dependencies(rosidl_default_runtime)
ament_package()
else() # ROS 1
# Find ROS1 required packages
find_package(
catkin REQUIRED
COMPONENTS roscpp std_msgs whole_body_state_msgs message_generation
realtime_tools pybind11_catkin)
# Define messages to be generated
add_message_files(
DIRECTORY
msg
FILES
TimeInterval.msg
State.msg
Control.msg
FeedbackGain.msg
SolverStatistics.msg
SolverTrajectory.msg)
generate_messages(DEPENDENCIES std_msgs whole_body_state_msgs)
# Define catkin dependencies
catkin_package(
INCLUDE_DIRS
include
CATKIN_DEPENDS
message_runtime
std_msgs
whole_body_state_msgs
DEPENDS)
# Add warnings definition
if(APPLE AND ${pybind11_catkin_VERSION} VERSION_LESS "2.10.3")
add_definitions(-DCROCODDYL_MSG_DISABLE_PYBIND11_WARNINGS)
endif()
# Build the Python interface for the ROS publisher and subscriber
foreach(PYBIND11_MODULE ${${PROJECT_NAME}_PYBIND11_MODULE})
pybind11_add_module(${PYBIND11_MODULE} MODULE src/${PYBIND11_MODULE}.cpp)
target_include_directories(
${PYBIND11_MODULE} PUBLIC include ${catkin_INCLUDE_DIRS}
${EIGEN3_INCLUDE_DIR} ${Boost_INCLUDE_DIRS})
target_link_libraries(
${PYBIND11_MODULE} PUBLIC ${catkin_LIBRARIES} ${Boost_LIBRARIES}
${Boost_PYTHON_LIBRARY} pinocchio::pinocchio)
add_dependencies(${PYBIND11_MODULE} ${crocoddyl_msgs_EXPORTED_TARGETS})
set_target_properties(
${PYBIND11_MODULE}
PROPERTIES LIBRARY_OUTPUT_DIRECTORY
${CATKIN_DEVEL_PREFIX}/${CATKIN_GLOBAL_PYTHON_DESTINATION})
install(TARGETS ${PYBIND11_MODULE}
LIBRARY DESTINATION ${CATKIN_GLOBAL_PYTHON_DESTINATION})
endforeach(PYBIND11_MODULE ${${PROJECT_NAME}_PYBIND11_MODULE})
# Install the include files
install(DIRECTORY include/${PROJECT_NAME}/
DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION})
endif()

# Build the Python interface for the ROS publisher and subscriber
add_compile_options(-Wall -Wpedantic -Wextra -Wno-sign-conversion)
foreach(PYBIND11_MODULE ${${PROJECT_NAME}_PYBIND11_MODULE})
pybind11_add_module(${PYBIND11_MODULE} MODULE src/${PYBIND11_MODULE}.cpp)
target_include_directories(
${PYBIND11_MODULE} PRIVATE include ${catkin_INCLUDE_DIRS}
${EIGEN3_INCLUDE_DIR} ${Boost_INCLUDE_DIRS})
target_link_libraries(
${PYBIND11_MODULE} PRIVATE ${catkin_LIBRARIES} ${Boost_LIBRARIES}
${Boost_PYTHON_LIBRARY} pinocchio::pinocchio)
add_dependencies(${PYBIND11_MODULE} ${crocoddyl_msgs_EXPORTED_TARGETS})
set_target_properties(
${PYBIND11_MODULE}
PROPERTIES LIBRARY_OUTPUT_DIRECTORY
${CATKIN_DEVEL_PREFIX}/${CATKIN_GLOBAL_PYTHON_DESTINATION})
install(TARGETS ${PYBIND11_MODULE}
LIBRARY DESTINATION ${CATKIN_GLOBAL_PYTHON_DESTINATION})
endforeach(PYBIND11_MODULE ${${PROJECT_NAME}_PYBIND11_MODULE})

# Install the include files
install(DIRECTORY include/${PROJECT_NAME}/
DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION})

add_subdirectory(unittest)
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,19 @@ Furthermore, the Python bindings of publishers and subscribers using roscpp help
- [std_msgs](http://wiki.ros.org/std_msgs)
- [whole_body_state_msgs](https://github.com/loco-3d/whole_body_state_msgs)
- [realtime_tools](http://wiki.ros.org/realtime_tools)
- [pybind11_catkin](https://github.com/wxmerkt/pybind11_catkin), wrapping [pybind11](https://pybind11.readthedocs.io/en/stable/basics.html) for use in ROS1
- [pybind11](https://pybind11.readthedocs.io/en/stable/basics.html) (we wrap it in ROS1 via [pybind11_catkin](https://github.com/wxmerkt/pybind11_catkin))
- [Eigen](http://eigen.tuxfamily.org/index.php?title=Main_Page)
- [pinocchio](https://github.com/stack-of-tasks/pinocchio)

To compile this catkin project you need to do:
To compile this catkin/colcon project you need to do:

```bash
cd your_ros_ws/
catkin build # ROS1
colcon build # ROS2
```
cd your_ros_ws/
catkin build #catkin_make
```

Note that this package supports ROS1 and ROS2.

## :copyright: Credits

Expand Down
Loading

0 comments on commit 26818d3

Please sign in to comment.