From c19b1097250eb0ad6f055cec22e86de7c09765a9 Mon Sep 17 00:00:00 2001 From: Alexander Sherikov Date: Fri, 3 Jan 2025 19:06:35 +0400 Subject: [PATCH] Improve tests --- .github/workflows/ws_2.yml | 19 +++ .make/ariles.mk | 2 +- .make/ros.mk | 11 +- demo/CMakeLists.txt | 61 -------- demo/catkin/CMakeLists.txt | 38 +++++ demo/{ => catkin}/demo.cpp | 0 demo/{ => catkin}/package.xml.disable | 2 +- demo/plain/CMakeLists.txt | 22 +++ demo/plain/demo.cpp | 175 ++++++++++++++++++++++ demo/plain/package.xml.disable | 23 +++ demo/plain_ros1/CMakeLists.txt | 24 ++++ demo/plain_ros1/demo.cpp | 199 ++++++++++++++++++++++++++ 12 files changed, 507 insertions(+), 69 deletions(-) delete mode 100644 demo/CMakeLists.txt create mode 100644 demo/catkin/CMakeLists.txt rename demo/{ => catkin}/demo.cpp (100%) rename demo/{ => catkin}/package.xml.disable (94%) create mode 100644 demo/plain/CMakeLists.txt create mode 100644 demo/plain/demo.cpp create mode 100644 demo/plain/package.xml.disable create mode 100644 demo/plain_ros1/CMakeLists.txt create mode 100644 demo/plain_ros1/demo.cpp diff --git a/.github/workflows/ws_2.yml b/.github/workflows/ws_2.yml index dac37e48..893ec4f0 100644 --- a/.github/workflows/ws_2.yml +++ b/.github/workflows/ws_2.yml @@ -45,6 +45,25 @@ jobs: - uses: actions/checkout@v4 with: path: src/ariles_ws + - run: mv src/ariles_ws/demo/plain/package.xml.disable package.xml - run: make bp_install_build BUILD_PROFILE=reldebug + - run: make dep_install PKG=ariles2_plain_demo + - run: make ariles2_plain_demo + - run: make dep_install PKG=ariles2_ros2param_ws + - run: make ariles2_ros2param_ws + + noble_ccws: + runs-on: ubuntu-24.04 + steps: + - uses: actions/checkout@v4 + with: + repository: asherikov/ccws + - uses: actions/checkout@v4 + with: + path: src/ariles_ws + - run: mv src/ariles_ws/demo/plain/package.xml.disable package.xml + - run: make bp_install_build BUILD_PROFILE=reldebug + - run: make dep_install PKG=ariles2_plain_demo + - run: make ariles2_plain_demo - run: make dep_install PKG=ariles2_ros2param_ws - run: make ariles2_ros2param_ws diff --git a/.make/ariles.mk b/.make/ariles.mk index da2a3d7a..6cdd64ec 100644 --- a/.make/ariles.mk +++ b/.make/ariles.mk @@ -4,7 +4,7 @@ VERSION?="XXX__version_not_set__XXX" REPO=https://github.com/asherikov/ariles.git -DEPENDENCY_PATH=./demo +DEPENDENCY_PATH=./demo/ DEBIAN_SYSTEM_DEPENDENCIES=libeigen3-dev octave libyaml-cpp-dev rapidjson-dev libpugixml-dev libboost-all-dev diff --git a/.make/ros.mk b/.make/ros.mk index e5f0404f..776e10af 100644 --- a/.make/ros.mk +++ b/.make/ros.mk @@ -10,7 +10,7 @@ WS_PKGS= \ ariles2_rosparam_ws \ ariles2_pugixml_ws -CATKIN_DEPENDENCY_TEST_PKG=ariles2_ws_demo +CATKIN_DEPENDENCY_TEST_PKG=ariles2_catkin_demo CATKIN_ARGS=--cmake-args -DARILES_ROS_ENABLE_TESTS=ON CATKIN_TARGETS=all test @@ -76,7 +76,7 @@ catkin_test_deb: clean echo ${WS_PKGS} | tr " " "\n" | xargs -I {} ${MAKE} catkin_test_deb_pkg PKG="{}" ROS_DISTRO=${ROS_DISTRO} bash -c 'source /opt/ros/${ROS_DISTRO}/setup.bash; \ cd build/dependency_test; \ - cmake ../../${DEPENDENCY_PATH}/; \ + cmake ../../${DEPENDENCY_PATH}/plain_ros1; \ ${MAKE} ${MAKE_FLAGS}' @@ -105,7 +105,7 @@ catkin_old_deb: catkin_prepare_workspace ${MAKE} catkin_test_deb ${MAKE} catkin_prepare_workspace cd ${CATKIN_PKGS_PATH}/; ls -1A | grep -v demo | xargs rm -Rf - cd ${CATKIN_PKGS_PATH}/demo; mv package.xml.disable package.xml + cd ${DEPENDENCY_PATH}/catkin; mv package.xml.disable package.xml cd ${CATKIN_WORKING_DIR}/src; catkin_init_workspace cd ${CATKIN_WORKING_DIR}; catkin_make_isolated --pkg ${CATKIN_DEPENDENCY_TEST_PKG} sudo ${MAKE} clean_deb clean_rosdep @@ -116,7 +116,7 @@ catkin_new_build: catkin_prepare_workspace cd ${CATKIN_WORKING_DIR}; catkin build -i --verbose --summary ${WS_PKGS} --make-args ${CATKIN_TARGETS} ${CATKIN_ARGS} catkin_new_build_with_dependent: catkin_prepare_workspace - cd ${CATKIN_PKGS_PATH}/demo; mv package.xml.disable package.xml + cd ${DEPENDENCY_PATH}/catkin; mv package.xml.disable package.xml cd ${CATKIN_WORKING_DIR}; catkin init cd ${CATKIN_WORKING_DIR}; catkin build -i --verbose --summary ${CATKIN_DEPENDENCY_TEST_PKG} @@ -124,7 +124,7 @@ catkin_new_deb: ${MAKE} catkin_test_deb ${MAKE} catkin_prepare_workspace cd ${CATKIN_PKGS_PATH}; ls -1A | grep -v demo | xargs rm -Rf - cd ${CATKIN_PKGS_PATH}/demo; mv package.xml.disable package.xml + cd ${DEPENDENCY_PATH}/catkin; mv package.xml.disable package.xml cd ${CATKIN_WORKING_DIR}; catkin init cd ${CATKIN_WORKING_DIR}; catkin build -i --verbose --summary ${CATKIN_DEPENDENCY_TEST_PKG} sudo ${MAKE} clean_deb @@ -162,7 +162,6 @@ ros_prerelease: ros_prerelease_deps cd ./build/ros_prerelease; sed -i "s|\(-e=TRAVIS\)|-eCCACHE_DIR=./.ccache/ \1|" *.sh cd ./build/ros_prerelease; env ABORT_ON_TEST_FAILURE=1 CCACHE_DIR=`pwd`/.ccache ./prerelease.sh - # docker #---------------------------------------------- ros_make_docker: diff --git a/demo/CMakeLists.txt b/demo/CMakeLists.txt deleted file mode 100644 index f4072a99..00000000 --- a/demo/CMakeLists.txt +++ /dev/null @@ -1,61 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12) - -set(CMAKE_VERBOSE_MAKEFILE ON) - - -if (DEFINED CATKIN_DEVEL_PREFIX) - project(ariles2_ws_demo) - - find_package(catkin REQUIRED - ariles2_core_ws - ariles2_rosparam_ws - ariles2_rapidjson_ws - ariles2_yamlcpp_ws - ariles2_octave_ws - ariles2_pugixml_ws - ) - - catkin_package(DEPENDS - ariles2_core_ws - ariles2_rosparam_ws - ariles2_rapidjson_ws - ariles2_yamlcpp_ws - ariles2_octave_ws - ariles2_pugixml_ws - ) - - include_directories( - include - SYSTEM ${catkin_INCLUDE_DIRS} - ) - - add_executable(demo demo.cpp) - - target_link_libraries(demo ${catkin_LIBRARIES}) - - install(TARGETS demo - ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} - LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} - RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION} - ) -else() - project(ariles2_demo) - - find_package(ariles2-core REQUIRED) - find_package(ariles2-rosparam REQUIRED) - find_package(ariles2-rapidjson REQUIRED) - find_package(ariles2-yaml-cpp REQUIRED) - find_package(ariles2-octave REQUIRED) - find_package(ariles2-pugixml REQUIRED) - - - add_executable(demo demo.cpp) - target_link_libraries(demo - ariles2::core - ariles2::rosparam - ariles2::rapidjson - ariles2::yaml-cpp - ariles2::octave - ariles2::pugixml - ) -endif() diff --git a/demo/catkin/CMakeLists.txt b/demo/catkin/CMakeLists.txt new file mode 100644 index 00000000..066631f4 --- /dev/null +++ b/demo/catkin/CMakeLists.txt @@ -0,0 +1,38 @@ +cmake_minimum_required(VERSION 2.8.12) + +set(CMAKE_VERBOSE_MAKEFILE ON) + +project(ariles2_catkin_demo) + +find_package(catkin REQUIRED + ariles2_core_ws + ariles2_rosparam_ws + ariles2_rapidjson_ws + ariles2_yamlcpp_ws + ariles2_octave_ws + ariles2_pugixml_ws +) + +catkin_package(DEPENDS + ariles2_core_ws + ariles2_rosparam_ws + ariles2_rapidjson_ws + ariles2_yamlcpp_ws + ariles2_octave_ws + ariles2_pugixml_ws +) + +include_directories( + include + SYSTEM ${catkin_INCLUDE_DIRS} +) + +add_executable(demo demo.cpp) + +target_link_libraries(demo ${catkin_LIBRARIES}) + +install(TARGETS demo + ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} + LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} + RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION} +) diff --git a/demo/demo.cpp b/demo/catkin/demo.cpp similarity index 100% rename from demo/demo.cpp rename to demo/catkin/demo.cpp diff --git a/demo/package.xml.disable b/demo/catkin/package.xml.disable similarity index 94% rename from demo/package.xml.disable rename to demo/catkin/package.xml.disable index 378b6b11..63936337 100644 --- a/demo/package.xml.disable +++ b/demo/catkin/package.xml.disable @@ -1,6 +1,6 @@ - ariles2_ws_demo + ariles2_catkin_demo 0.0.0 ariles2 demo / dependency test diff --git a/demo/plain/CMakeLists.txt b/demo/plain/CMakeLists.txt new file mode 100644 index 00000000..315c9993 --- /dev/null +++ b/demo/plain/CMakeLists.txt @@ -0,0 +1,22 @@ +cmake_minimum_required(VERSION 2.8.12) + +set(CMAKE_VERBOSE_MAKEFILE ON) + + +project(ariles2_plain_demo) + +find_package(ariles2-core REQUIRED) +find_package(ariles2-rapidjson REQUIRED) +find_package(ariles2-yaml-cpp REQUIRED) +find_package(ariles2-octave REQUIRED) +find_package(ariles2-pugixml REQUIRED) + + +add_executable(demo demo.cpp) +target_link_libraries(demo + ariles2::core + ariles2::rapidjson + ariles2::yaml-cpp + ariles2::octave + ariles2::pugixml +) diff --git a/demo/plain/demo.cpp b/demo/plain/demo.cpp new file mode 100644 index 00000000..5de0e319 --- /dev/null +++ b/demo/plain/demo.cpp @@ -0,0 +1,175 @@ +/** + @file + @author Alexander Sherikov + + @copyright 2018 Alexander Sherikov, Licensed under the Apache License, Version 2.0. + (see @ref LICENSE or http://www.apache.org/licenses/LICENSE-2.0) + + @brief +*/ + + +// ============================================================================ +// HEADER INCLUSION +// ============================================================================ + +// `visitor` is an Ariles component which provides integration with a particular +// 3rd party library. +#include +#include +#include + +// `adapter` is an Ariles component which adds support for serialization of +// certain type(s), e.g. Eigen types or Boost pointers. +#include +#include +#include +#include + + + +// =============================================================== +// DEFINING TYPES +// =============================================================== +namespace demo +{ + class ArilesBaseClass + // must inherit from ariles2::DefaultBase + : public ariles2::DefaultBase + { +// Declare entries, in this case two numbers +#define ARILES2_ENTRIES(v) \ + ARILES2_TYPED_ENTRY(v, real_member, double) \ + ARILES2_TYPED_ENTRY_(v, integer_member, int) +// underscore ^ indicates that the name of the entry must be +// 'integer_member_' instead of 'integer_member', this is useful if your +// naming convention requires trailing underscores for member variables. + +// Initialize ariles +#include ARILES2_INITIALIZE + + public: + virtual ~ArilesBaseClass(){}; // added to suppress compiler warnings + + // This method is called every time you deserialize a class. If + // omitted, the default automatically generated method is used. + void arilesVisit(const ariles2::Defaults & /*visitor*/, const ariles2::Defaults::Parameters & /*param*/) + { + real_member = 0.0; + integer_member_ = 12; + } + }; + + + class NonArilesBaseClass + { + public: + // Eigen types are supported too, see below + Eigen::Vector3d eigen_vector_; + }; + + + class MyClass : public ArilesBaseClass, // no need to inherit from ConfigurableBase directly. + public NonArilesBaseClass + { +// Declare entries, in this case we indicate inheritance from another +// Ariles class (ArilesBaseClass) and a member from a non-Ariles class +// (NonArilesBaseClass) +#define ARILES2_ENTRIES(v) \ + ARILES2_PARENT(v, ArilesBaseClass) \ + ARILES2_ENTRY_(v, eigen_vector) + // In this case ^ Ariles should not declare the inherited + // member, therefore we use 'ARILES2_ENTRY_' instead of 'ARILES2_TYPED_ENTRY_'. + +#include ARILES2_INITIALIZE + + + public: + virtual ~MyClass(){}; // added to suppress compiler warnings + + + void arilesVisit(const ariles2::Defaults &visitor, const ariles2::Defaults::Parameters ¶m) + { + // If you use your own method to initialize member variables, + // it is up to you to properly initialize all entries and + // parent classes. + // all parents at once + arilesVisitParents(visitor, param); + // or one by one (either option is sufficient) + ArilesBaseClass::arilesVisit(visitor, param); + + // custom default values for some members + real_member = 100.0; + eigen_vector_.setZero(); + } + }; + + + class MyContainerClass : public ariles2::DefaultBase + { + // Some of the standard containers can be used with Ariles types. +#define ARILES2_ENTRIES(v) ARILES2_TYPED_ENTRY_(v, my_class_vector, std::vector) +#include ARILES2_INITIALIZE + }; +} // namespace demo + + +// =============================================================== +// SERIALIZATION & DESERIALIZATION +// =============================================================== + +#include // std::cout + +int main() +{ + demo::MyContainerClass my_container_class; + + // access members as usual + my_container_class.my_class_vector_.size(); + my_container_class.my_class_vector_.push_back(demo::MyClass()); + ariles2::apply(my_container_class.my_class_vector_[0]); + + + // YAML + /* + * When you serialize `my_container_class` to YAML you get the following: + * ----- + MyContainerClass: + my_class_vector: + - real_member: 100 + integer_member: 12 + eigen_vector: [0, 0, 0] + * ----- + * Note that the trailing underscores are omitted for all members. This + * applies to all supported representations. + */ + { + // You can read and write YAML configuration files as follows: + ariles2::apply("config.yaml", my_container_class); + ariles2::apply("config.yaml", my_container_class); + + // Sometimes it may be useful to dump configuration to std::cout + ariles2::apply(std::cout, my_container_class); + + // In some situations it is more convenient to instantiate Reader and + // Writer classes explicitly, e.g., if you keep configurations of several + // classes in the same file + ariles2::yaml_cpp::Writer writer("config.yaml"); + ariles2::apply(writer, my_container_class); + + ariles2::yaml_cpp::Reader reader("config.yaml"); + ariles2::apply(reader, my_container_class); + } + + + // Octave + { + // Octave visitor supports only writing + ariles2::apply("debug.m", my_container_class); + // the generated file can later be loaded in Octave with + // 'source debug.m' for debugging + } + + + return (0); +} diff --git a/demo/plain/package.xml.disable b/demo/plain/package.xml.disable new file mode 100644 index 00000000..2d33ed34 --- /dev/null +++ b/demo/plain/package.xml.disable @@ -0,0 +1,23 @@ + + + ariles2_plain_demo + 0.0.0 + ariles2 demo / dependency test + + Alexander Sherikov + + Apache 2.0 + + + cmake + + + ariles2_core_ws + ariles2_rapidjson_ws + ariles2_yamlcpp_ws + ariles2_octave_ws + ariles2_pugixml_ws + + + + diff --git a/demo/plain_ros1/CMakeLists.txt b/demo/plain_ros1/CMakeLists.txt new file mode 100644 index 00000000..85024be8 --- /dev/null +++ b/demo/plain_ros1/CMakeLists.txt @@ -0,0 +1,24 @@ +cmake_minimum_required(VERSION 2.8.12) + +set(CMAKE_VERBOSE_MAKEFILE ON) + + +project(ariles2_plain_ros1_demo) + +find_package(ariles2-core REQUIRED) +find_package(ariles2-rosparam REQUIRED) +find_package(ariles2-rapidjson REQUIRED) +find_package(ariles2-yaml-cpp REQUIRED) +find_package(ariles2-octave REQUIRED) +find_package(ariles2-pugixml REQUIRED) + + +add_executable(demo demo.cpp) +target_link_libraries(demo + ariles2::core + ariles2::rosparam + ariles2::rapidjson + ariles2::yaml-cpp + ariles2::octave + ariles2::pugixml +) diff --git a/demo/plain_ros1/demo.cpp b/demo/plain_ros1/demo.cpp new file mode 100644 index 00000000..8ec84463 --- /dev/null +++ b/demo/plain_ros1/demo.cpp @@ -0,0 +1,199 @@ +/** + @file + @author Alexander Sherikov + + @copyright 2018 Alexander Sherikov, Licensed under the Apache License, Version 2.0. + (see @ref LICENSE or http://www.apache.org/licenses/LICENSE-2.0) + + @brief +*/ + + +// ============================================================================ +// HEADER INCLUSION +// ============================================================================ + +// `visitor` is an Ariles component which provides integration with a particular +// 3rd party library. +#include +#include +#include +#include + +// `adapter` is an Ariles component which adds support for serialization of +// certain type(s), e.g. Eigen types or Boost pointers. +#include +#include +#include +#include + + + +// =============================================================== +// DEFINING TYPES +// =============================================================== +namespace demo +{ + class ArilesBaseClass + // must inherit from ariles2::DefaultBase + : public ariles2::DefaultBase + { +// Declare entries, in this case two numbers +#define ARILES2_ENTRIES(v) \ + ARILES2_TYPED_ENTRY(v, real_member, double) \ + ARILES2_TYPED_ENTRY_(v, integer_member, int) +// underscore ^ indicates that the name of the entry must be +// 'integer_member_' instead of 'integer_member', this is useful if your +// naming convention requires trailing underscores for member variables. + +// Initialize ariles +#include ARILES2_INITIALIZE + + public: + virtual ~ArilesBaseClass(){}; // added to suppress compiler warnings + + // This method is called every time you deserialize a class. If + // omitted, the default automatically generated method is used. + void arilesVisit(const ariles2::Defaults & /*visitor*/, const ariles2::Defaults::Parameters & /*param*/) + { + real_member = 0.0; + integer_member_ = 12; + } + }; + + + class NonArilesBaseClass + { + public: + // Eigen types are supported too, see below + Eigen::Vector3d eigen_vector_; + }; + + + class MyClass : public ArilesBaseClass, // no need to inherit from ConfigurableBase directly. + public NonArilesBaseClass + { +// Declare entries, in this case we indicate inheritance from another +// Ariles class (ArilesBaseClass) and a member from a non-Ariles class +// (NonArilesBaseClass) +#define ARILES2_ENTRIES(v) \ + ARILES2_PARENT(v, ArilesBaseClass) \ + ARILES2_ENTRY_(v, eigen_vector) + // In this case ^ Ariles should not declare the inherited + // member, therefore we use 'ARILES2_ENTRY_' instead of 'ARILES2_TYPED_ENTRY_'. + +#include ARILES2_INITIALIZE + + + public: + virtual ~MyClass(){}; // added to suppress compiler warnings + + + void arilesVisit(const ariles2::Defaults &visitor, const ariles2::Defaults::Parameters ¶m) + { + // If you use your own method to initialize member variables, + // it is up to you to properly initialize all entries and + // parent classes. + // all parents at once + arilesVisitParents(visitor, param); + // or one by one (either option is sufficient) + ArilesBaseClass::arilesVisit(visitor, param); + + // custom default values for some members + real_member = 100.0; + eigen_vector_.setZero(); + } + }; + + + class MyContainerClass : public ariles2::DefaultBase + { + // Some of the standard containers can be used with Ariles types. +#define ARILES2_ENTRIES(v) ARILES2_TYPED_ENTRY_(v, my_class_vector, std::vector) +#include ARILES2_INITIALIZE + }; +} // namespace demo + + +// =============================================================== +// SERIALIZATION & DESERIALIZATION +// =============================================================== + +#include // std::cout + +int main() +{ + demo::MyContainerClass my_container_class; + + // access members as usual + my_container_class.my_class_vector_.size(); + my_container_class.my_class_vector_.push_back(demo::MyClass()); + ariles2::apply(my_container_class.my_class_vector_[0]); + + + // YAML + /* + * When you serialize `my_container_class` to YAML you get the following: + * ----- + MyContainerClass: + my_class_vector: + - real_member: 100 + integer_member: 12 + eigen_vector: [0, 0, 0] + * ----- + * Note that the trailing underscores are omitted for all members. This + * applies to all supported representations. + */ + { + // You can read and write YAML configuration files as follows: + ariles2::apply("config.yaml", my_container_class); + ariles2::apply("config.yaml", my_container_class); + + // Sometimes it may be useful to dump configuration to std::cout + ariles2::apply(std::cout, my_container_class); + + // In some situations it is more convenient to instantiate Reader and + // Writer classes explicitly, e.g., if you keep configurations of several + // classes in the same file + ariles2::yaml_cpp::Writer writer("config.yaml"); + ariles2::apply(writer, my_container_class); + + ariles2::yaml_cpp::Reader reader("config.yaml"); + ariles2::apply(reader, my_container_class); + } + + + // ROS parameter server + { + ros::NodeHandle nh; + + // read/write + ariles2::apply(nh, my_container_class); + ariles2::apply(nh, my_container_class); + // parameters can be uploaded to parameter server in advance using + // roslaunch, see http://wiki.ros.org/roslaunch/XML/rosparam + + // read/write with namespace + ariles2::apply(nh, my_container_class, "/some_namespace/"); + ariles2::apply(nh, my_container_class, "/some_namespace/"); + + // Reader / Writer classes + ariles2::rosparam::Writer writer(nh); + ariles2::apply(writer, my_container_class); + + ariles2::rosparam::Reader reader(nh); + ariles2::apply(reader, my_container_class); + } + + + // Octave + { + // Octave visitor supports only writing + ariles2::apply("debug.m", my_container_class); + // the generated file can later be loaded in Octave with + // 'source debug.m' for debugging + } + + + return (0); +}