Refactor goal state machine implementation and add unit tests (#311)

* Fix buggy if-conditions in transition functions.
* Bugfix: incease number of states by one
* Cleanup CMakeLists.txt and package.xml
* Move goal state machine implementation details from header to C file
This commit is contained in:
Jacob Perron 2018-10-30 16:15:10 -07:00 committed by GitHub
parent 2c0e35d9d1
commit 29e7dbe156
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 317 additions and 162 deletions

View file

@ -6,14 +6,11 @@ find_package(ament_cmake_ros REQUIRED)
find_package(action_msgs REQUIRED)
find_package(rcl REQUIRED)
find_package(rcutils REQUIRED)
# find_package(rmw REQUIRED)
include_directories(
include
${action_msgs_INCLUDE_DIRS}
${rcl_INCLUDE_DIRS}
${rcutils_INCLUDE_DIRS}
)
# Default to C11
@ -34,77 +31,63 @@ add_executable(test_compile_headers
src/test_compile_headers.c
)
# set(rcl_action_sources
# src/action_server.c
# src/action_client.c
# src/action_goal.c
# src/transition_map.c
# )
# set_source_files_properties(
# ${rcl_action_sources}
# PROPERTIES language "C"
# )
set(rcl_action_sources
src/${PROJECT_NAME}/goal_state_machine.c
)
### C-Library depending only on RCL
# add_library(
# ${PROJECT_NAME}
# ${rcl_action_sources}
# )
set_source_files_properties(
${rcl_action_sources}
PROPERTIES language "C"
)
# specific order: dependents before dependencies
# ament_target_dependencies(${PROJECT_NAME}
# "rcl"
# "action_msgs"
# "rosidl_generator_c"
# "rcutils"
# )
add_library(
${PROJECT_NAME}
${rcl_action_sources}
)
ament_target_dependencies(${PROJECT_NAME}
"rcl"
"action_msgs"
)
# Causes the visibility macros to use dllexport rather than dllimport,
# which is appropriate when building the dll but not consuming it.
# target_compile_definitions(${PROJECT_NAME} PRIVATE "RCL_ACTION_BUILDING_DLL")
# install(TARGETS ${PROJECT_NAME}
# ARCHIVE DESTINATION lib
# LIBRARY DESTINATION lib
# RUNTIME DESTINATION bin
# )
if(BUILD_TESTING)
find_package(ament_cmake_gtest REQUIRED)
find_package(ament_lint_auto REQUIRED)
ament_lint_auto_find_test_dependencies()
# Gtests
# ament_add_gtest(test_action_server
# test/test_action_server.cpp
# )
# if(TARGET test_action_server)
# target_include_directories(test_action_server PUBLIC
# ${rcl_INCLUDE_DIRS}
# )
# target_link_libraries(test_action_server ${PROJECT_NAME})
# endif()
# ament_add_gtest(test_action_client
# test/test_action_client.cpp
# )
# if(TARGET test_action_client)
# target_include_directories(test_action_client PUBLIC
# ${rcl_INCLUDE_DIRS}
# )
# target_link_libraries(test_action_client ${PROJECT_NAME})
# endif()
endif()
# specific order: dependents before dependencies
ament_export_include_directories(include)
# ament_export_libraries(${PROJECT_NAME})
ament_export_dependencies(ament_cmake)
ament_export_dependencies(rcl)
# ament_export_dependencies(action_msgs)
ament_export_dependencies(rcutils)
ament_package()
target_compile_definitions(${PROJECT_NAME} PRIVATE "RCL_ACTION_BUILDING_DLL")
install(
DIRECTORY include/
DESTINATION include
)
install(TARGETS ${PROJECT_NAME}
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
)
if(BUILD_TESTING)
find_package(ament_cmake_gtest REQUIRED)
find_package(ament_lint_auto REQUIRED)
ament_lint_auto_find_test_dependencies()
ament_find_gtest()
# Gtests
ament_add_gtest(test_goal_state_machine
test/rcl_action/test_goal_state_machine.cpp
)
if(TARGET test_goal_state_machine)
target_include_directories(test_goal_state_machine PUBLIC
${rcl_INCLUDE_DIRS}
)
target_link_libraries(test_goal_state_machine
${PROJECT_NAME}
)
endif()
endif()
# specific order: dependents before dependencies
ament_export_include_directories(include)
ament_export_libraries(${PROJECT_NAME})
ament_export_dependencies(ament_cmake)
ament_export_dependencies(rcl)
ament_export_dependencies(action_msgs)
ament_package()