Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ros2 #4

Merged
merged 21 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 30 additions & 27 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,43 @@ name: tests

on:
push:
branches: [ master ]
branches: [master]
pull_request:
branches: [ master ]
branches: [master]

env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
BUILD_TYPE: Debug

jobs:
build:
runs-on: ubuntu-latest
runs-on: ubuntu-24.04

steps:
- uses: actions/checkout@v2
- uses: ros-tooling/[email protected]
with:
required-ros-distributions: noetic

- name: Install Dependendies
run: |
sudo apt-get update
sudo apt-get install gcc-10 g++-10
sudo apt-get install libboost-all-dev libprotobuf-dev libzmq3-dev libfmt-dev

- name: Configure CMake
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}
env:
CC: gcc-10
CXX: g++-10

- name: Build
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}

- name: Test
working-directory: ${{github.workspace}}/build
run: make -j$(nproc) && make -j$(nproc) tests

- uses: actions/checkout@v2
- uses: ros-tooling/[email protected]
with:
required-ros-distributions: jazzy

- name: Install Dependendies
run: |
sudo apt-get update
sudo apt-get install gcc-10 g++-10
sudo apt-get install libboost-all-dev libprotobuf-dev libzmq3-dev libfmt-dev

- name: Configure CMake
run: |
source /opt/ros/jazzy/setup.bash
cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}
env:
CC: gcc-10
CXX: g++-10

- name: Build
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}

- name: Test
working-directory: ${{github.workspace}}/build
run: |
source /opt/ros/jazzy/setup.bash
make -j$(nproc) && make -j$(nproc) tests
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
*.swp
*.swo
/build
/build_imx
.DS_Store
.vscode
61 changes: 46 additions & 15 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
cmake_minimum_required(VERSION 3.5)

project(tyndall)
cmake_minimum_required(VERSION 2.8.3)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
Expand All @@ -15,18 +16,17 @@ add_definitions(-DDEBUG)
include_directories(${CMAKE_SOURCE_DIR})
set(LD_FLAGS "-lpthread -lzmq -lprotobuf -lfmt -lrt -latomic")

find_package(roscpp)

if ("${roscpp_FOUND}")
if ("${roscpp_LINK_DIRECTORIES}" STREQUAL "")
# quickfix using the path of the first library in roscpp_LIBRARIES
execute_process(COMMAND bash "-c" "dirname -z $(echo \"${roscpp_LIBRARIES}\" | cut -f1 -d ';')" OUTPUT_VARIABLE roscpp_LINK_DIRECTORIES)
endif()
find_package(ament_cmake)
find_package(rclcpp)
find_package(std_msgs)
find_package(std_srvs)
find_package(builtin_interfaces)

include_directories(${roscpp_INCLUDE_DIRS})
link_directories(${roscpp_LINK_DIRECTORIES})
set(LD_FLAGS "${LD_FLAGS} -lpthread -lroscpp -lrosconsole -lrosconsole_backend_interface -lrosconsole_log4cxx -lroscpp_serialization -lxmlrpcpp -lrostime -lcpp_common")
if("${rclcpp_FOUND}")
message(STATUS "ROS2 found")
set(LD_FLAGS "${LD_FLAGS} -lpthread")
else()
message(STATUS "ROS2 not found")
add_definitions("-DNO_ROS")
endif()

Expand All @@ -35,20 +35,26 @@ add_library(tyndall SHARED ${CFILES})
target_link_libraries(tyndall ${LD_FLAGS})
install(TARGETS tyndall DESTINATION lib)

if("${rclcpp_FOUND}")
ament_target_dependencies(tyndall rclcpp builtin_interfaces std_msgs std_srvs)
endif()

file(GLOB HEADERS "tyndall/*.h*" "tyndall/*/*.h*")

foreach(HEADER ${HEADERS})
execute_process(COMMAND bash "-c" "dirname -z $(realpath --relative-to=${CMAKE_SOURCE_DIR} ${HEADER})" OUTPUT_VARIABLE HEADER_DIR)
install(FILES ${HEADER} DESTINATION include/${HEADER_DIR})
endforeach(HEADER)

execute_process(COMMAND bash "-c" "echo -n \"${roscpp_LINK_DIRECTORIES}\" | sed -n -e 's/^.*\\(\\/opt\\)/\\1/p'" OUTPUT_VARIABLE PKGCONF_ROS_LIBLINK_PATH)
execute_process(COMMAND bash "-c" "echo -n \"${rclcpp_LINK_DIRECTORIES}\" | sed -n -e 's/^.*\\(\\/opt\\)/\\1/p'" OUTPUT_VARIABLE PKGCONF_ROS_LIBLINK_PATH)
set(PKGCONF_ROS_LIBLINK "-L${PKGCONF_ROS_LIBLINK_PATH}")
set(PKGCONF_LD_FLAGS ${LD_FLAGS})
configure_file(tyndall.pc.in tyndall.pc @ONLY)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/tyndall.pc DESTINATION lib/pkgconfig)

set(EXAMPLE_PREFIX "${CMAKE_PROJECT_NAME}_ex_")
file(GLOB EXAMPLES "examples/*.c*")

foreach(EXAMPLE ${EXAMPLES})
execute_process(COMMAND bash "-c" "printf ${EXAMPLE_PREFIX}$(basename ${EXAMPLE} | cut -f 1 -d '.')" OUTPUT_VARIABLE EXAMPLE_TARGET)
add_executable(${EXAMPLE_TARGET} EXCLUDE_FROM_ALL ${EXAMPLE})
Expand All @@ -57,20 +63,22 @@ foreach(EXAMPLE ${EXAMPLES})
set(EXAMPLE_TARGETS "${EXAMPLE_TARGETS}${EXAMPLE_TARGET};")
endforeach(EXAMPLE)


file(GLOB SUBEXAMPLES "examples/*/*.c*")

foreach(EXAMPLE ${SUBEXAMPLES})
execute_process(COMMAND bash "-c" "printf ${EXAMPLE_PREFIX}$(dirname ${EXAMPLE} | xargs basename)_$(basename ${EXAMPLE} | cut -f 1 -d '.')" OUTPUT_VARIABLE EXAMPLE_TARGET)
add_executable(${EXAMPLE_TARGET} EXCLUDE_FROM_ALL ${EXAMPLE})
target_link_libraries(${EXAMPLE_TARGET} tyndall)
install(TARGETS ${EXAMPLE_TARGET} DESTINATION bin OPTIONAL)
set(EXAMPLE_TARGETS "${EXAMPLE_TARGETS}${EXAMPLE_TARGET};")
endforeach(EXAMPLE)

add_custom_target(examples)
add_dependencies(examples ${EXAMPLE_TARGETS})

set(TEST_PREFIX "${CMAKE_PROJECT_NAME}_test_")
file(GLOB CPP_TESTS "tests/*/*.cpp")

foreach(CPP_TEST ${CPP_TESTS})
execute_process(COMMAND bash "-c" "printf ${TEST_PREFIX}$(dirname ${CPP_TEST} | xargs basename)_$(basename ${CPP_TEST} | cut -f 1 -d '.')" OUTPUT_VARIABLE CPP_TEST_TARGET)
add_executable(${CPP_TEST_TARGET} EXCLUDE_FROM_ALL ${CPP_TEST})
Expand All @@ -80,20 +88,43 @@ foreach(CPP_TEST ${CPP_TESTS})
endforeach(CPP_TEST)

IF(CMAKE_CROSSCOMPILING)
set(TEST_CMD "echo WARNING: Tests are not executed when cross compiling")
set(TEST_CMD "echo WARNING: Tests are not executed when cross compiling")
ELSE()
set(TEST_CMD "set -e; for t in ${CMAKE_BINARY_DIR}/${TEST_PREFIX}*; do $t; done")
set(TEST_CMD "set -e; for t in ${CMAKE_BINARY_DIR}/${TEST_PREFIX}*; do $t; done")
ENDIF()

add_custom_target(tests COMMAND /bin/bash -c "${TEST_CMD}" VERBATIM DEPENDS ${CPP_TEST_TARGETS})

set(TOOL_PREFIX "${CMAKE_PROJECT_NAME}_tool_")
file(GLOB TOOLS "tools/*.c*")

foreach(TOOL ${TOOLS})
execute_process(COMMAND bash "-c" "printf ${TOOL_PREFIX}$(basename ${TOOL} | cut -f 1 -d '.')" OUTPUT_VARIABLE TOOL_TARGET)
add_executable(${TOOL_TARGET} EXCLUDE_FROM_ALL ${TOOL})
target_link_libraries(${TOOL_TARGET} tyndall)
install(TARGETS ${TOOL_TARGET} DESTINATION bin OPTIONAL)
set(TOOL_TARGETS "${TOOL_TARGETS}${TOOL_TARGET};")
endforeach(TOOL)

add_custom_target(tools)
add_dependencies(tools ${TOOL_TARGETS})

function(dump_cmake_variables)
get_cmake_property(_variableNames VARIABLES)
list(SORT _variableNames)

foreach(_variableName ${_variableNames})
if(ARGV0)
unset(MATCHED)
string(REGEX MATCH ${ARGV0} MATCHED ${_variableName})

if(NOT MATCHED)
continue()
endif()
endif()

message(STATUS "${_variableName}=${${_variableName}}")
endforeach()
endfunction()

# dump_cmake_variables()
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,11 @@ Pub / sub example:

```cpp
#include <tyndall/ros_context.h>
#include <std_msgs/Int32.h>
#include <std_msgs/msg/int32.h>

ros_context::init(argc, argv, std::chrono::milliseconds{3}, "ex_ros_context_write");

std_msgs::Int32 msg;
std_msgs::msg::Int32 msg;
msg.data = 42;

ros_context_write(msg, "/ex_ros_context");
Expand All @@ -160,13 +160,13 @@ ros_context_write(msg, "/ex_ros_context");

```cpp
#include <tyndall/ros_context.h>
#include <std_msgs/Int32.h>
#include <std_msgs/msg/int32.h>

ros_context::init(argc, argv, std::chrono::milliseconds{3}, "ex_ros_context_read");

while(1)
{
std_msgs::Int32 msg;
std_msgs::msg::Int32 msg;

int rc = ros_context_read(msg, "/ex_ros_context");

Expand All @@ -181,34 +181,34 @@ Serve / call example:

```cpp
#include <tyndall/ros_context.h>
#include <std_srvs/SetBool.h>
#include <std_srvs/srv/set_bool.hpp>

ros_context::init(argc, argv, std::chrono::milliseconds{3}, "ex_ros_context_serve");
while(1)
{
std_srvs::SetBool srv;
std_srvs::srv::SetBool srv;
srv.response.success = true;

int rc = ros_context_serve(srv, "ex_ros_context");

if (rc == 0)
printf("got: %d\n", srv.request.data);
printf("got: %d\n", srv_req.data);
}
```

### Caller

```cpp
#include <tyndall/ros_context.h>
#include <std_srvs/SetBool.h>
#include <std_srvs/srv/set_bool.hpp>

ros_context::init(argc, argv, std::chrono::milliseconds{3}, "ex_ros_context_serve");
while(1)
{
std_srvs::SetBool srv;
std_srvs::srv::SetBool srv;
srv.response.success = true;

std_srvs::SetBool srv;
std_srvs::srv::SetBool srv;
srv.request.data = true;

int rc = ros_context_call(srv, "/ex_ros_context_serve/ex_ros_context");
Expand Down
Loading
Loading