From 30fc70cb7371b3ea1afa5946ce25babf35fbae1c Mon Sep 17 00:00:00 2001 From: AugusteBourgois Date: Fri, 2 Aug 2024 11:05:00 +0200 Subject: [PATCH 01/12] correct header install path --- .../cmake/generate_parameter_library.cmake | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/generate_parameter_library/cmake/generate_parameter_library.cmake b/generate_parameter_library/cmake/generate_parameter_library.cmake index ce681d5d..95cca15d 100644 --- a/generate_parameter_library/cmake/generate_parameter_library.cmake +++ b/generate_parameter_library/cmake/generate_parameter_library.cmake @@ -78,7 +78,7 @@ function(generate_parameter_library LIB_NAME YAML_FILE) add_library(${LIB_NAME} INTERFACE ${PARAM_HEADER_FILE} ${VALIDATE_HEADER}) target_include_directories(${LIB_NAME} INTERFACE $ - $ + $ ) set_target_properties(${LIB_NAME} PROPERTIES LINKER_LANGUAGE CXX) target_link_libraries(${LIB_NAME} INTERFACE @@ -90,7 +90,7 @@ function(generate_parameter_library LIB_NAME YAML_FILE) tcb_span::tcb_span tl_expected::tl_expected ) - install(DIRECTORY ${LIB_INCLUDE_DIR} DESTINATION include/${LIB_NAME}) + install(DIRECTORY ${LIB_INCLUDE_DIR} DESTINATION include/${PROJECT_NAME}/${LIB_NAME}) endfunction() @@ -129,7 +129,7 @@ function(generate_parameter_module LIB_NAME YAML_FILE) add_library(${LIB_NAME} INTERFACE ${PARAM_HEADER_FILE} ${VALIDATE_HEADER}) target_include_directories(${LIB_NAME} INTERFACE $ - $ + $ ) endfunction() From 99ffacf7ace5825d1210cd44f079bf7b0a616016 Mon Sep 17 00:00:00 2001 From: AugusteBourgois Date: Wed, 7 Aug 2024 10:04:31 +0200 Subject: [PATCH 02/12] deprecate locally accessible generated header --- .../cmake/generate_parameter_library.cmake | 42 ++++++++++++------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/generate_parameter_library/cmake/generate_parameter_library.cmake b/generate_parameter_library/cmake/generate_parameter_library.cmake index 95cca15d..02c69ca8 100644 --- a/generate_parameter_library/cmake/generate_parameter_library.cmake +++ b/generate_parameter_library/cmake/generate_parameter_library.cmake @@ -35,7 +35,7 @@ function(generate_parameter_library LIB_NAME YAML_FILE) endif() # Make the include directory - set(LIB_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR}/${LIB_NAME}/include/) + set(LIB_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR}/include/${PROJECT_NAME}) file(MAKE_DIRECTORY ${LIB_INCLUDE_DIR}) # Optional 3rd parameter for the user defined validation header @@ -48,14 +48,9 @@ function(generate_parameter_library LIB_NAME YAML_FILE) cmake_path(APPEND VALIDATE_HEADER ${VALIDATE_HEADER_FILENAME}) # Copy the header file into the include directory - add_custom_command( - OUTPUT ${VALIDATE_HEADER} - COMMAND ${CMAKE_COMMAND} -E copy ${IN_VALIDATE_HEADER} ${VALIDATE_HEADER} - DEPENDS ${IN_VALIDATE_HEADER} - COMMENT - "Running `${CMAKE_COMMAND} -E copy ${IN_VALIDATE_HEADER} ${VALIDATE_HEADER}`" - VERBATIM - ) + file(COPY ${IN_VALIDATE_HEADER} DESTINATION ${LIB_INCLUDE_DIR}) + # necessary so that #include can be used in the local package (deprecated) + file(COPY ${IN_VALIDATE_HEADER} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/include) endif() # Set the yaml file parameter to be relative to the current source dir @@ -73,12 +68,25 @@ function(generate_parameter_library LIB_NAME YAML_FILE) "Running `${generate_parameter_library_cpp_BIN} ${PARAM_HEADER_FILE} ${YAML_FILE} ${VALIDATE_HEADER_FILENAME}`" VERBATIM ) + # necessary so that #include can be used in the local package (deprecated) + set(LOCAL_PARAM_HEADER_FILE ${CMAKE_CURRENT_BINARY_DIR}/include/${LIB_NAME}.hpp) + add_custom_command( + OUTPUT ${LOCAL_PARAM_HEADER_FILE} + COMMAND ${CMAKE_COMMAND} -E echo "#pragma warning(\"`#include <${LIB_NAME}>` is deprecated. Use `#include <${PROJECT_NAME}/${LIB_NAME}.hpp>` instead.\")" >> ${LOCAL_PARAM_HEADER_FILE} + COMMAND ${CMAKE_COMMAND} -E cat ${LOCAL_PARAM_HEADER_FILE} ${PARAM_HEADER_FILE} > ${LOCAL_PARAM_HEADER_FILE}.tmp + COMMAND ${CMAKE_COMMAND} -E copy ${LOCAL_PARAM_HEADER_FILE}.tmp ${LOCAL_PARAM_HEADER_FILE} + COMMAND ${CMAKE_COMMAND} -E remove ${LOCAL_PARAM_HEADER_FILE}.tmp + DEPENDS ${PARAM_HEADER_FILE} + COMMENT + "Creating deprecated header file ${LOCAL_PARAM_HEADER_FILE}" + VERBATIM + ) # Create the library target - add_library(${LIB_NAME} INTERFACE ${PARAM_HEADER_FILE} ${VALIDATE_HEADER}) + add_library(${LIB_NAME} INTERFACE ${PARAM_HEADER_FILE} ${VALIDATE_HEADER} ${LOCAL_PARAM_HEADER_FILE}) target_include_directories(${LIB_NAME} INTERFACE - $ - $ + $ + $ ) set_target_properties(${LIB_NAME} PROPERTIES LINKER_LANGUAGE CXX) target_link_libraries(${LIB_NAME} INTERFACE @@ -90,7 +98,9 @@ function(generate_parameter_library LIB_NAME YAML_FILE) tcb_span::tcb_span tl_expected::tl_expected ) - install(DIRECTORY ${LIB_INCLUDE_DIR} DESTINATION include/${PROJECT_NAME}/${LIB_NAME}) + install(DIRECTORY ${LIB_INCLUDE_DIR} DESTINATION include) + ament_export_dependencies(fmt parameter_traits rclcpp rclcpp_lifecycle rsl tcb_span tl_expected) + set(_AMENT_CMAKE_EXPORT_DEPENDENCIES "${_AMENT_CMAKE_EXPORT_DEPENDENCIES}" PARENT_SCOPE) endfunction() @@ -108,7 +118,7 @@ function(generate_parameter_module LIB_NAME YAML_FILE) # Set the yaml file parameter to be relative to the current source dir set(YAML_FILE ${CMAKE_CURRENT_SOURCE_DIR}/${YAML_FILE}) - set(LIB_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR}/${LIB_NAME}) + set(LIB_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR}/include/${PROJECT_NAME}) file(MAKE_DIRECTORY ${LIB_INCLUDE_DIR}) find_package(ament_cmake_python) @@ -128,8 +138,8 @@ function(generate_parameter_module LIB_NAME YAML_FILE) # Create the library target add_library(${LIB_NAME} INTERFACE ${PARAM_HEADER_FILE} ${VALIDATE_HEADER}) target_include_directories(${LIB_NAME} INTERFACE - $ - $ + $ + $ ) endfunction() From 0a64156e0c559b9e08336bd7c878fed85b417501 Mon Sep 17 00:00:00 2001 From: AugusteBourgois Date: Wed, 7 Aug 2024 10:58:07 +0200 Subject: [PATCH 03/12] add example package using parameters generated in another package --- README.md | 42 ++++- example_external/CHANGELOG.rst | 104 ++++++++++++ example_external/CMakeLists.txt | 79 +++++++++ example_external/README.md | 155 ++++++++++++++++++ example_external/config/implementation.yaml | 117 +++++++++++++ example_external/config/missing_required.yaml | 9 + .../minimal_publisher_external.hpp | 52 ++++++ example_external/package.xml | 25 +++ .../src/minimal_publisher_external.cpp | 74 +++++++++ .../test/descriptor_test_gtest.cpp | 98 +++++++++++ example_external/test/example_params.yaml | 53 ++++++ example_external/test/example_test_gmock.cpp | 71 ++++++++ example_external/test/example_test_gtest.cpp | 82 +++++++++ 13 files changed, 958 insertions(+), 3 deletions(-) create mode 100644 example_external/CHANGELOG.rst create mode 100644 example_external/CMakeLists.txt create mode 100644 example_external/README.md create mode 100644 example_external/config/implementation.yaml create mode 100644 example_external/config/missing_required.yaml create mode 100644 example_external/include/generate_parameter_library_example_external/minimal_publisher_external.hpp create mode 100644 example_external/package.xml create mode 100644 example_external/src/minimal_publisher_external.cpp create mode 100644 example_external/test/descriptor_test_gtest.cpp create mode 100644 example_external/test/example_params.yaml create mode 100644 example_external/test/example_test_gmock.cpp create mode 100644 example_external/test/example_test_gtest.cpp diff --git a/README.md b/README.md index 5d75d46d..a3867c60 100644 --- a/README.md +++ b/README.md @@ -80,7 +80,7 @@ generate_parameter_module( **src/turtlesim.cpp** ```c++ #include -#include "turtlesim_parameters.hpp" +#include // you can also use the deprecated #include "turtlesim_parameters.hpp" int main(int argc, char * argv[]) { @@ -350,10 +350,46 @@ The generated parameter value for the nested map example can then be accessed wi ### Use generated struct in Cpp The generated header file is named based on the target library name you passed as the first argument to the cmake function. -If you specified it to be `turtlesim_parameters` you can then include the generated code with `#include "turtlesim_parameters.hpp"`. +If you specified it to be `turtlesim_parameters` you can then include the generated code with `#include `. ```c++ -#include "turtlesim_parameters.hpp" +#include ``` + +Note that this header can also be used from another package: +```cmake +cmake_minimum_required(VERSION 3.8) +project(my_other_package) + + +include(GNUInstallDirs) + +# find dependencies +find_package(ament_cmake REQUIRED) +find_package(turtelsim REQUIRED) + +add_library(my_lib src/my_lib.cpp) +target_include_directories(my_lib PUBLIC + $ + $) +target_link_libraries(my_lib PUBLIC turtlesim::turtlesim_parameters) + +############# +## Install ## +############# + +install(DIRECTORY include/${PROJECT_NAME}/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}) + +install(TARGETS my_lib + EXPORT ${PROJECT_NAME}Targets + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + RUNTIME DESTINATION lib/${PROJECT_NAME}) + +ament_export_targets(${PROJECT_NAME}Targets HAS_LIBRARY_TARGET) +ament_export_dependencies(turtlesim) +ament_package() +``` + In your initialization code, create a `ParamListener` which will declare and get the parameters. An exception will be thrown if any validation fails or any required parameters were not set. Then call `get_params` on the listener to get a copy of the `Params` struct. diff --git a/example_external/CHANGELOG.rst b/example_external/CHANGELOG.rst new file mode 100644 index 00000000..8dfa17da --- /dev/null +++ b/example_external/CHANGELOG.rst @@ -0,0 +1,104 @@ +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +Changelog for package generate_parameter_library_example +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +0.3.8 (2024-03-27) +------------------ +* Restore functionality for mapped params with no struct name (`#185 _`) +* Fix newline issue (`#176 `_) + * fix new line rendering for Python +* Support nested mapped parameters (`#166 `_) +* Contributors: Paul Gesel, Sebastian Castro + +0.3.7 (2024-01-12) +------------------ +* Split example/README.md into C++ and Python version; updated content (`#138 `_) +* Contributors: chriseichmann + +0.3.6 (2023-07-31) +------------------ + +0.3.5 (2023-07-28) +------------------ +* Remove documentation of deprecated validator functions (`#135 `_) +* Contributors: Tyler Weaver + +0.3.4 (2023-07-24) +------------------ +* Add Python support for generate_parameter_library (`#110 `_) + Co-authored-by: Tyler Weaver +* Contributors: Paul Gesel + +0.3.3 (2023-04-13) +------------------ + +0.3.2 (2023-04-12) +------------------ +* Populate Range Constraints in Parameter Descriptors from Validation Functions (`#103 `_) +* Mark deprecated rsl method and propose alternative in the docs. (`#102 `_) +* Contributors: Chance Cardona, Dr. Denis + +0.3.1 (2023-02-01) +------------------ +* Make it easy for users to override (`#92 `_) +* Contributors: Tyler Weaver + +0.3.0 (2022-11-15) +------------------ +* Migrate from parameter_traits to RSL (take 2) (`#91 `_) +* Contributors: Tyler Weaver + +0.2.8 (2022-11-03) +------------------ + +0.2.7 (2022-10-28) +------------------ +* Standardize cmake (`#79 `_) +* Contributors: Tyler Weaver + +0.2.6 (2022-09-28) +------------------ + +0.2.5 (2022-09-20) +------------------ +* 🈵 Support use of '_' in mapped parameters. (`#68 `_) +* Component node example (`#60 `_) +* Update README for example (`#63 `_) +* 🚀 Add cmake macros for using tests with example yaml files. 🤖 (`#57 `_) + Co-authored-by: Tyler Weaver +* Fix example parameters (`#54 `_) +* Contributors: Denis Štogl, Paul Gesel, Tyler Weaver + +0.2.4 (2022-08-19) +------------------ +* INTEGER type (`#53 `_) +* 0.2.3 +* Contributors: Tyler Weaver + +0.2.3 (2022-08-05) +------------------ + +0.2.2 (2022-08-03) +------------------ + +0.2.1 (2022-08-02) +------------------ +* Fix scientific notation (`#46 `_) +* Contributors: Paul Gesel + +0.2.0 (2022-08-01) +------------------ +* Create stack allocated struct (`#45 `_) +* Fixed length arrays (`#44 `_) +* Fixed size string no default bug (`#43 `_) +* static OK to fix ODR errors (`#41 `_) +* Change package name (`#40 `_) +* parameter validators interface library (`#32 `_) +* Validate fixed length Strings (`#33 `_) +* Fixed size strings (`#29 `_) +* Contributors: Paul Gesel, Tyler Weaver + +0.1.0 (2022-07-27) +------------------ +* Example usage of generate_parameter_library. +* Contributors: Paul Gesel, Tyler Weaver diff --git a/example_external/CMakeLists.txt b/example_external/CMakeLists.txt new file mode 100644 index 00000000..9fa6b4ed --- /dev/null +++ b/example_external/CMakeLists.txt @@ -0,0 +1,79 @@ +cmake_minimum_required(VERSION 3.16) +project(generate_parameter_library_example_external) + +if(CMAKE_CXX_COMPILER_ID MATCHES "(GNU|Clang)") + add_compile_options(-Wall -Wextra -Wpedantic -Wshadow -Wconversion -Wsign-conversion -Wold-style-cast) +endif() + +find_package(ament_cmake REQUIRED) +find_package(ament_cmake_python REQUIRED) +find_package(rclcpp REQUIRED) +find_package(rclcpp_components REQUIRED) +find_package(rclpy REQUIRED) +find_package(generate_parameter_library_example REQUIRED) + +add_library(minimal_publisher_external SHARED + src/minimal_publisher_external.cpp +) +target_include_directories(minimal_publisher_external PUBLIC + $ + $ +) +target_link_libraries(minimal_publisher_external + PUBLIC + rclcpp::rclcpp + rclcpp_components::component + generate_parameter_library_example::admittance_controller_parameters +) +rclcpp_components_register_node(minimal_publisher_external + PLUGIN "admittance_controller::MinimalPublisher" + EXECUTABLE test_node +) + +if(BUILD_TESTING) + find_package(ament_lint_auto REQUIRED) + set(ament_cmake_cpplint_FOUND TRUE) # Conflicts with clang-foramt + set(ament_cmake_flake8_FOUND TRUE) # Conflicts with black + set(ament_cmake_uncrustify_FOUND TRUE) # Conflicts with clang-format + ament_lint_auto_find_test_dependencies() + + find_package(ament_cmake_gtest REQUIRED) + find_package(generate_parameter_library REQUIRED) + # example_test_gtest + add_rostest_with_parameters_gtest(test_example_gtest test/example_test_gtest.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/test/example_params.yaml) + target_include_directories(test_example_gtest PRIVATE include) + target_link_libraries(test_example_gtest generate_parameter_library_example::admittance_controller_parameters rclcpp::rclcpp) + # descriptor_test_gtest + add_rostest_with_parameters_gtest(test_descriptor_gtest test/descriptor_test_gtest.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/test/example_params.yaml) + target_include_directories(test_descriptor_gtest PRIVATE include) + target_link_libraries(test_descriptor_gtest generate_parameter_library_example::admittance_controller_parameters rclcpp::rclcpp) + + find_package(ament_cmake_gmock REQUIRED) + add_rostest_with_parameters_gmock(test_example_gmock test/example_test_gmock.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/test/example_params.yaml) + target_include_directories(test_example_gmock PRIVATE include) + target_link_libraries(test_example_gmock generate_parameter_library_example::admittance_controller_parameters rclcpp::rclcpp) +endif() + +install( + DIRECTORY include/ + DESTINATION include/generate_parameter_library_example_external +) + +install(TARGETS minimal_publisher_external + EXPORT export_generate_parameter_library_example_external + ARCHIVE DESTINATION lib + LIBRARY DESTINATION lib + RUNTIME DESTINATION bin +) + +install( + TARGETS test_node + DESTINATION lib/generate_parameter_library_example_external +) + +ament_export_targets(export_generate_parameter_library_example_external HAS_LIBRARY_TARGET) +ament_export_dependencies(rclcpp rclcpp_components generate_parameter_library_example) +ament_package() diff --git a/example_external/README.md b/example_external/README.md new file mode 100644 index 00000000..a34836ee --- /dev/null +++ b/example_external/README.md @@ -0,0 +1,155 @@ +# Example: + +## Build the node + +``` + mkdir colcon_ws + mkdir colcon_ws/src + cd colcon_ws/src + git clone https://github.com/picknikrobotics/generate_parameter_library.git + cd .. + colcon build +``` + +## Run the C++ node + +``` +source install/setup.bash +ros2 run generate_parameter_library_example_external test_node --ros-args --params-file src/generate_parameter_library/example_external/config/implementation.yaml +``` + +You should see an output like this: +`[INFO] [1656018676.015816509] [admittance_controller]: Control frame is: 'ee_link'` + +## ROS 2 CLI + +Run the following: + +`ros2 param list` + +You should see: + +``` +/admittance_controller: + admittance.damping_ratio + admittance.mass + admittance.selected_axes + admittance.stiffness + chainable_command_interfaces + command_interfaces + control.frame.external + control.frame.id + enable_parameter_update_without_reactivation + fixed_array + fixed_string + fixed_string_no_default + fixed_world_frame.frame.external + fixed_world_frame.frame.id + ft_sensor.filter_coefficient + ft_sensor.frame.external + ft_sensor.frame.id + ft_sensor.name + gravity_compensation.CoG.force + gravity_compensation.CoG.pos + gravity_compensation.frame.external + gravity_compensation.frame.id + interpolation_mode + joints + kinematics.alpha + kinematics.base + kinematics.group_name + kinematics.plugin_name + kinematics.plugin_package + kinematics.tip + one_number + pid.elbow_joint.d + pid.elbow_joint.i + pid.elbow_joint.p + pid.rate + pid.shoulder_lift_joint.d + pid.shoulder_lift_joint.i + pid.shoulder_lift_joint.p + pid.shoulder_pan_joint.d + pid.shoulder_pan_joint.i + pid.shoulder_pan_joint.p + pid.wrist_1_joint.d + pid.wrist_1_joint.i + pid.wrist_1_joint.p + pid.wrist_2_joint.d + pid.wrist_2_joint.i + pid.wrist_2_joint.p + pid.wrist_3_joint.d + pid.wrist_3_joint.i + pid.wrist_3_joint.p + qos_overrides./parameter_events.publisher.depth + qos_overrides./parameter_events.publisher.durability + qos_overrides./parameter_events.publisher.history + qos_overrides./parameter_events.publisher.reliability + scientific_notation_num + state_interfaces + three_numbers + three_numbers_of_five + use_feedforward_commanded_input + use_sim_time + ``` + +All parameter are automatically declared and callbacks are setup by default. You can set a parameter by typing: + +`ros2 param set /admittance_controller control.frame.id new_frame` + +You should see: + +`[INFO] [1656019001.515820371] [admittance_controller]: New control frame parameter is: 'new_frame'` + +Congratulations, you updated the parameter! + +If you try to set a parameter that is read only, you will get an error. Running the following + +`ros2 param set /admittance_controller command_interfaces ["velocity"]` + +will result in the error + +`Setting parameter failed: parameter 'command_interfaces' cannot be set because it is read-only` + +Running the following + +`ros2 param describe /admittance_controller admittance.damping_ratio` + +will show a parameter's description + + ``` + Parameter name: admittance.damping_ratio + Type: double array + Description: specifies damping ratio values for x, y, z, rx, ry, and rz used in the admittance calculation. The values are calculated as damping can be used instead: zeta = D / (2 * sqrt( M * S )) + Constraints: + Min value: 0.1 + Max value: 10.0 +``` + +If you try to set a value out of the specified bounds, + +`ros2 param set /admittance_controller admittance.damping_ratio [-10.0,-10.0,-10.0,-10.0,-10.0,-10.0]` + +you will get the error + +`Setting parameter failed: Value -10.0 in parameter 'admittance.damping_ratio' must be within bounds [0.1, 10.0]` + +If you try to set a vector parameter with the wrong length, + +`ros2 param set /admittance_controller admittance.damping_ratio [1.0,1.0,1.0]` + +you will get the error + +`Setting parameter failed: Length of parameter 'admittance.damping_ratio' is 3 but must be equal to 6` + +If you try to load a yaml file with missing required parameters + +`ros2 run generate_parameter_library_example test_node --ros-args --params-file src/generate_parameter_library/example_external/config/missing_required.yaml` + +you will get the error + +``` +terminate called after throwing an instance of 'rclcpp::exceptions::ParameterUninitializedException' + what(): parameter 'fixed_string_no_default' is not initialized +[ros2run]: Aborted +``` diff --git a/example_external/config/implementation.yaml b/example_external/config/implementation.yaml new file mode 100644 index 00000000..4cd1ba91 --- /dev/null +++ b/example_external/config/implementation.yaml @@ -0,0 +1,117 @@ +admittance_controller: + ros__parameters: + joints: + - shoulder_pan_joint + - shoulder_lift_joint + - elbow_joint + - wrist_1_joint + - wrist_2_joint + - wrist_3_joint + + fixed_string_no_default: + "happy" + + elbow_joint: + x: + weight: 2.0 + + pid: + shoulder_pan_joint: + i: 0.7 + shoulder_lift_joint: + i: 0.5 + elbow_joint: + i: 0.2 + wrist_1_joint: + i: 1.2 + wrist_2_joint: + i: 0.8 + wrist_3_joint: + i: 0.5 + + command_interfaces: + - position + + state_interfaces: + - position + - velocity + + chainable_command_interfaces: + - position + - velocity + + kinematics: + plugin_name: kdl_plugin/KDLKinematics + plugin_package: kinematics_interface_kdl + base: base_link # Assumed to be stationary + tip: ee_link + group_name: ur5e_manipulator + alpha: 0.0005 + + ft_sensor: + name: tcp_fts_sensor + frame: + id: ee_link # ee_link Wrench measurements are in this frame + external: false # force torque frame exists within URDF kinematic chain + filter_coefficient: 0.005 + + control: + frame: + id: ee_link # Admittance calcs (displacement etc) are done in this frame. Usually the tool or end-effector + external: false # control frame exists within URDF kinematic chain + + fixed_world_frame: + frame: # Gravity points down (neg. Z) in this frame (Usually: world or base_link) + id: base_link # Admittance calcs (displacement etc) are done in this frame. Usually the tool or end-effector + external: false # control frame exists within URDF kinematic chain + + gravity_compensation: + frame: + id: ee_link + external: false + + CoG: # specifies the center of gravity of the end effector + pos: + - 0.1 # x + - 0.0 # y + - 0.0 # z + force: 23.0 # mass * 9.81 + + admittance: + selected_axes: + - true # x + - true # y + - true # z + - true # rx + - true # ry + - true # rz + + # Having ".0" at the end is MUST, otherwise there is a loading error + # F = M*a + D*v + S*(x - x_d) + mass: + - 3.0 # x + - 3.0 # y + - 3.0 # z + - 0.05 # rx + - 0.05 # ry + - 0.05 # rz + + damping_ratio: # damping can be used instead: zeta = D / (2 * sqrt( M * S )) + - 2.828427 # x + - 2.828427 # y + - 2.828427 # z + - 2.828427 # rx + - 2.828427 # ry + - 2.828427 # rz + + stiffness: + - 50.0 # x + - 50.0 # y + - 50.0 # z + - 1.0 # rx + - 1.0 # ry + - 1.0 # rz + + # general settings + enable_parameter_update_without_reactivation: true + use_feedforward_commanded_input: true diff --git a/example_external/config/missing_required.yaml b/example_external/config/missing_required.yaml new file mode 100644 index 00000000..c29447d7 --- /dev/null +++ b/example_external/config/missing_required.yaml @@ -0,0 +1,9 @@ +admittance_controller: + ros__parameters: + mass: + - -10.0 # x + - -10.0 # y + - 3.0 # z + - 0.05 # rx + - 0.05 # ry + - 0.05 # rz diff --git a/example_external/include/generate_parameter_library_example_external/minimal_publisher_external.hpp b/example_external/include/generate_parameter_library_example_external/minimal_publisher_external.hpp new file mode 100644 index 00000000..9a002b7f --- /dev/null +++ b/example_external/include/generate_parameter_library_example_external/minimal_publisher_external.hpp @@ -0,0 +1,52 @@ +// Copyright 2022 PickNik Inc. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// +// * Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// +// * Neither the name of the PickNik Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. + +#pragma once + +#include +#include + +#include + +namespace admittance_controller { + +class MinimalPublisher : public rclcpp::Node { + public: + MinimalPublisher(const rclcpp::NodeOptions& options = rclcpp::NodeOptions()); + + private: + void timer_callback(); + + rclcpp::TimerBase::SharedPtr timer_; + std::shared_ptr param_listener_; + admittance_controller::Params params_; +}; + +} // namespace admittance_controller + +RCLCPP_COMPONENTS_REGISTER_NODE(admittance_controller::MinimalPublisher) diff --git a/example_external/package.xml b/example_external/package.xml new file mode 100644 index 00000000..f7b0ec89 --- /dev/null +++ b/example_external/package.xml @@ -0,0 +1,25 @@ + + + + generate_parameter_library_example_external + 0.3.8 + Example usage of a parameter header generated in another package. + Paul Gesel + BSD-3-Clause + Paul Gesel + + generate_parameter_library_example + rclcpp + rclcpp_components + + ament_cmake + + ament_cmake_core + + ament_lint_auto + ament_lint_common + + + ament_cmake + + diff --git a/example_external/src/minimal_publisher_external.cpp b/example_external/src/minimal_publisher_external.cpp new file mode 100644 index 00000000..c2b23abb --- /dev/null +++ b/example_external/src/minimal_publisher_external.cpp @@ -0,0 +1,74 @@ +// Copyright 2022 PickNik Inc. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// +// * Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// +// * Neither the name of the PickNik Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. + +#include "generate_parameter_library_example_external/minimal_publisher_external.hpp" + +#include + +#include + +using namespace std::chrono_literals; + +namespace admittance_controller { + +MinimalPublisher::MinimalPublisher(const rclcpp::NodeOptions& options) + : Node("admittance_controller", options) { + timer_ = create_wall_timer( + 500ms, std::bind(&MinimalPublisher::timer_callback, this)); + param_listener_ = + std::make_shared(get_node_parameters_interface()); + params_ = param_listener_->get_params(); + + [[maybe_unused]] StackParams s_params = param_listener_->get_stack_params(); + + RCLCPP_INFO(get_logger(), "Initial control frame parameter is: '%s'", + params_.control.frame.id.c_str()); + RCLCPP_INFO(get_logger(), "fixed string is: '%s'", + std::string{params_.fixed_string}.c_str()); + const tcb::span fixed_array = params_.fixed_array; + for (auto d : fixed_array) { + RCLCPP_INFO(get_logger(), "value: '%s'", std::to_string(d).c_str()); + } +} + +void MinimalPublisher::timer_callback() { + if (param_listener_->is_old(params_)) { + param_listener_->refresh_dynamic_parameters(); + params_ = param_listener_->get_params(); + RCLCPP_INFO(get_logger(), "New control frame parameter is: '%s'", + params_.control.frame.id.c_str()); + RCLCPP_INFO(get_logger(), "fixed string is: '%s'", + std::string{params_.fixed_string}.c_str()); + const tcb::span fixed_array = params_.fixed_array; + for (auto d : fixed_array) { + RCLCPP_INFO(get_logger(), "value: '%s'", std::to_string(d).c_str()); + } + } +} + +} // namespace admittance_controller diff --git a/example_external/test/descriptor_test_gtest.cpp b/example_external/test/descriptor_test_gtest.cpp new file mode 100644 index 00000000..b9736655 --- /dev/null +++ b/example_external/test/descriptor_test_gtest.cpp @@ -0,0 +1,98 @@ +// Copyright 2023 Picknik Robotics +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// +// * Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// +// * Neither the name of the PickNik Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +// Author: Chance Cardona +// + +#include "generate_parameter_library_example/admittance_controller_parameters.hpp" +#include "gtest/gtest.h" +#include "rclcpp/rclcpp.hpp" + +#include +#include + +class DescriptorTest : public ::testing::Test { + public: + void SetUp() { + example_test_node_ = std::make_shared("example_test_node"); + + std::shared_ptr param_listener = + std::make_shared( + example_test_node_->get_node_parameters_interface()); + params_ = param_listener->get_params(); + std::vector names = {"admittance.damping_ratio", "one_number", + "pid.joint4.p", "lt_eq_fifteen", + "gt_fifteen"}; + descriptors_ = example_test_node_->describe_parameters(names); + } + + void TearDown() { example_test_node_.reset(); } + + protected: + std::shared_ptr example_test_node_; + admittance_controller::Params params_; + std::vector descriptors_; +}; + +// Checks element_bounds<> on a float +TEST_F(DescriptorTest, check_floating_point_descriptors) { + EXPECT_EQ(descriptors_[0].floating_point_range.at(0).from_value, 0.1); + EXPECT_EQ(descriptors_[0].floating_point_range.at(0).to_value, 10); +} + +// Checks bounds<> on an int +TEST_F(DescriptorTest, check_integer_descriptors) { + EXPECT_EQ(descriptors_[1].integer_range.at(0).from_value, 1024); + EXPECT_EQ(descriptors_[1].integer_range.at(0).to_value, 65535); +} + +TEST_F(DescriptorTest, check_lower_upper_bounds) { + EXPECT_EQ(descriptors_[2].floating_point_range.at(0).from_value, 0.0001); + EXPECT_EQ(descriptors_[2].floating_point_range.at(0).to_value, + std::numeric_limits::max()); +} + +TEST_F(DescriptorTest, check_lt_eq) { + EXPECT_EQ(descriptors_[3].integer_range.at(0).from_value, + std::numeric_limits::lowest()); + EXPECT_EQ(descriptors_[3].integer_range.at(0).to_value, 15); +} + +TEST_F(DescriptorTest, check_gt) { + EXPECT_EQ(descriptors_[4].integer_range.at(0).from_value, 15); + EXPECT_EQ(descriptors_[4].integer_range.at(0).to_value, + std::numeric_limits::max()); +} + +int main(int argc, char** argv) { + ::testing::InitGoogleTest(&argc, argv); + rclcpp::init(argc, argv); + int result = RUN_ALL_TESTS(); + rclcpp::shutdown(); + return result; +} diff --git a/example_external/test/example_params.yaml b/example_external/test/example_params.yaml new file mode 100644 index 00000000..81ea48b8 --- /dev/null +++ b/example_external/test/example_params.yaml @@ -0,0 +1,53 @@ +example_test_node: + ros__parameters: + + joints: + - joint4 + - joint5 + - joint6 + + ft_sensor: + name: "ft_sensor" + frame: + id: "sensor_frame_id" + filter_coefficient: 0.1 + + + # mandatory parameters not relevant for the test + fixed_string_no_default: "stringy" + command_interfaces: + - "one" + - "two" + state_interfaces: + - "one" + - "two" + chainable_command_interfaces: + - "one" + - "two" + + kinematics: + plugin_name: "kinematics" + plugin_package: "kinematics_pkg" + base: "base_link" + tip: "tcp" + group_name: "manip" + + control: + frame: + id: "control_frame_id" + + fixed_world_frame: + frame: + id: "world_frame" + + gravity_compensation: + frame: + id: "world_frame" + CoG: + pos: [1.0, 2.2, 3.4] + + admittance: + selected_axes: [true, false, true, false, true, false] + mass: [1.2, 2.3, 3.4, 4.5, 5.6, 6.7] + stiffness: [1.2, 2.3, 3.4, 4.5, 5.6, 6.7] + damping_ratio: [1.1, 1.1, 1.1, 1.1, 1.1, 1.1] diff --git a/example_external/test/example_test_gmock.cpp b/example_external/test/example_test_gmock.cpp new file mode 100644 index 00000000..63486c25 --- /dev/null +++ b/example_external/test/example_test_gmock.cpp @@ -0,0 +1,71 @@ +// Copyright 2022 Stogl Robotics Consulting +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// +// * Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// +// * Neither the name of the PickNik Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +// Author: Denis Štogl +// + +#include "generate_parameter_library_example/admittance_controller_parameters.hpp" +#include "gmock/gmock.h" +#include "rclcpp/rclcpp.hpp" + +#include + +class ExampleTest : public ::testing::Test { + public: + void SetUp() { + example_test_node_ = std::make_shared("example_test_node"); + + std::shared_ptr param_listener = + std::make_shared( + example_test_node_->get_node_parameters_interface()); + params_ = param_listener->get_params(); + } + + void TearDown() { example_test_node_.reset(); } + + protected: + std::shared_ptr example_test_node_; + admittance_controller::Params params_; +}; + +TEST_F(ExampleTest, check_parameters) { + ASSERT_EQ(params_.interpolation_mode, "spline"); // default value + + ASSERT_THAT(params_.joints, + ::testing::ElementsAreArray({"joint4", "joint5", "joint6"})); + + ASSERT_EQ(params_.ft_sensor.filter_coefficient, 0.1); +} + +int main(int argc, char** argv) { + ::testing::InitGoogleTest(&argc, argv); + rclcpp::init(argc, argv); + int result = RUN_ALL_TESTS(); + rclcpp::shutdown(); + return result; +} diff --git a/example_external/test/example_test_gtest.cpp b/example_external/test/example_test_gtest.cpp new file mode 100644 index 00000000..40e06e14 --- /dev/null +++ b/example_external/test/example_test_gtest.cpp @@ -0,0 +1,82 @@ +// Copyright 2022 Stogl Robotics Consulting +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// +// * Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// +// * Neither the name of the PickNik Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +// Author: Denis Štogl +// + +#include "generate_parameter_library_example/admittance_controller_parameters.hpp" +#include "gtest/gtest.h" +#include "rclcpp/rclcpp.hpp" + +#include + +class ExampleTest : public ::testing::Test { + public: + void SetUp() { + example_test_node_ = std::make_shared("example_test_node"); + + param_listener_ = std::make_shared( + example_test_node_->get_node_parameters_interface()); + params_ = param_listener_->get_params(); + } + + void TearDown() { example_test_node_.reset(); } + + protected: + std::shared_ptr example_test_node_; + admittance_controller::Params params_; + std::shared_ptr param_listener_; +}; + +TEST_F(ExampleTest, check_parameters) { + ASSERT_EQ(params_.interpolation_mode, "spline"); // default value + + ASSERT_EQ(params_.joints.size(), 3); + EXPECT_EQ(params_.joints[0], "joint4"); + EXPECT_EQ(params_.joints[1], "joint5"); + EXPECT_EQ(params_.joints[2], "joint6"); + + ASSERT_EQ(params_.ft_sensor.filter_coefficient, 0.1); +} + +TEST_F(ExampleTest, try_get_params) { + ASSERT_TRUE(param_listener_->try_get_params(params_)); + + const rclcpp ::Parameter new_param("interpolation_mode", "linear"); + example_test_node_->set_parameter(new_param); + ASSERT_TRUE(param_listener_->try_get_params(params_)); + ASSERT_EQ(params_.interpolation_mode, "linear"); +} + +int main(int argc, char** argv) { + ::testing::InitGoogleTest(&argc, argv); + rclcpp::init(argc, argv); + int result = RUN_ALL_TESTS(); + rclcpp::shutdown(); + return result; +} From 80b0ec54f01244ca2c625d73dbf474e3a98c2956 Mon Sep 17 00:00:00 2001 From: AugusteBourgois Date: Wed, 7 Aug 2024 11:03:04 +0200 Subject: [PATCH 04/12] update changelog and package.xml --- example_external/CHANGELOG.rst | 108 ++------------------------------- example_external/package.xml | 4 +- 2 files changed, 8 insertions(+), 104 deletions(-) diff --git a/example_external/CHANGELOG.rst b/example_external/CHANGELOG.rst index 8dfa17da..53f0675a 100644 --- a/example_external/CHANGELOG.rst +++ b/example_external/CHANGELOG.rst @@ -1,104 +1,8 @@ -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -Changelog for package generate_parameter_library_example -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +Changelog for package generate_parameter_library_example_external +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -0.3.8 (2024-03-27) +0.1.0 (2024-08-07) ------------------ -* Restore functionality for mapped params with no struct name (`#185 _`) -* Fix newline issue (`#176 `_) - * fix new line rendering for Python -* Support nested mapped parameters (`#166 `_) -* Contributors: Paul Gesel, Sebastian Castro - -0.3.7 (2024-01-12) ------------------- -* Split example/README.md into C++ and Python version; updated content (`#138 `_) -* Contributors: chriseichmann - -0.3.6 (2023-07-31) ------------------- - -0.3.5 (2023-07-28) ------------------- -* Remove documentation of deprecated validator functions (`#135 `_) -* Contributors: Tyler Weaver - -0.3.4 (2023-07-24) ------------------- -* Add Python support for generate_parameter_library (`#110 `_) - Co-authored-by: Tyler Weaver -* Contributors: Paul Gesel - -0.3.3 (2023-04-13) ------------------- - -0.3.2 (2023-04-12) ------------------- -* Populate Range Constraints in Parameter Descriptors from Validation Functions (`#103 `_) -* Mark deprecated rsl method and propose alternative in the docs. (`#102 `_) -* Contributors: Chance Cardona, Dr. Denis - -0.3.1 (2023-02-01) ------------------- -* Make it easy for users to override (`#92 `_) -* Contributors: Tyler Weaver - -0.3.0 (2022-11-15) ------------------- -* Migrate from parameter_traits to RSL (take 2) (`#91 `_) -* Contributors: Tyler Weaver - -0.2.8 (2022-11-03) ------------------- - -0.2.7 (2022-10-28) ------------------- -* Standardize cmake (`#79 `_) -* Contributors: Tyler Weaver - -0.2.6 (2022-09-28) ------------------- - -0.2.5 (2022-09-20) ------------------- -* 🈵 Support use of '_' in mapped parameters. (`#68 `_) -* Component node example (`#60 `_) -* Update README for example (`#63 `_) -* 🚀 Add cmake macros for using tests with example yaml files. 🤖 (`#57 `_) - Co-authored-by: Tyler Weaver -* Fix example parameters (`#54 `_) -* Contributors: Denis Štogl, Paul Gesel, Tyler Weaver - -0.2.4 (2022-08-19) ------------------- -* INTEGER type (`#53 `_) -* 0.2.3 -* Contributors: Tyler Weaver - -0.2.3 (2022-08-05) ------------------- - -0.2.2 (2022-08-03) ------------------- - -0.2.1 (2022-08-02) ------------------- -* Fix scientific notation (`#46 `_) -* Contributors: Paul Gesel - -0.2.0 (2022-08-01) ------------------- -* Create stack allocated struct (`#45 `_) -* Fixed length arrays (`#44 `_) -* Fixed size string no default bug (`#43 `_) -* static OK to fix ODR errors (`#41 `_) -* Change package name (`#40 `_) -* parameter validators interface library (`#32 `_) -* Validate fixed length Strings (`#33 `_) -* Fixed size strings (`#29 `_) -* Contributors: Paul Gesel, Tyler Weaver - -0.1.0 (2022-07-27) ------------------- -* Example usage of generate_parameter_library. -* Contributors: Paul Gesel, Tyler Weaver +* Example usage of generated header from another package (generate_parameter_library_example) +* Contributors: Auguste Bourgois diff --git a/example_external/package.xml b/example_external/package.xml index f7b0ec89..b94f0a59 100644 --- a/example_external/package.xml +++ b/example_external/package.xml @@ -2,11 +2,11 @@ generate_parameter_library_example_external - 0.3.8 + 0.1.0 Example usage of a parameter header generated in another package. Paul Gesel BSD-3-Clause - Paul Gesel + Auguste Bourgois generate_parameter_library_example rclcpp From 577b895ba1fc51c9eea84946d7d58008e6420aaa Mon Sep 17 00:00:00 2001 From: AugusteBourgois Date: Wed, 7 Aug 2024 11:15:59 +0200 Subject: [PATCH 05/12] remove unnecessary files and correct deprecation pragma --- example_external/CMakeLists.txt | 27 ----- .../test/descriptor_test_gtest.cpp | 98 ------------------- example_external/test/example_params.yaml | 53 ---------- example_external/test/example_test_gmock.cpp | 71 -------------- example_external/test/example_test_gtest.cpp | 82 ---------------- .../cmake/generate_parameter_library.cmake | 2 +- 6 files changed, 1 insertion(+), 332 deletions(-) delete mode 100644 example_external/test/descriptor_test_gtest.cpp delete mode 100644 example_external/test/example_params.yaml delete mode 100644 example_external/test/example_test_gmock.cpp delete mode 100644 example_external/test/example_test_gtest.cpp diff --git a/example_external/CMakeLists.txt b/example_external/CMakeLists.txt index 9fa6b4ed..8ab3d38f 100644 --- a/example_external/CMakeLists.txt +++ b/example_external/CMakeLists.txt @@ -30,33 +30,6 @@ rclcpp_components_register_node(minimal_publisher_external EXECUTABLE test_node ) -if(BUILD_TESTING) - find_package(ament_lint_auto REQUIRED) - set(ament_cmake_cpplint_FOUND TRUE) # Conflicts with clang-foramt - set(ament_cmake_flake8_FOUND TRUE) # Conflicts with black - set(ament_cmake_uncrustify_FOUND TRUE) # Conflicts with clang-format - ament_lint_auto_find_test_dependencies() - - find_package(ament_cmake_gtest REQUIRED) - find_package(generate_parameter_library REQUIRED) - # example_test_gtest - add_rostest_with_parameters_gtest(test_example_gtest test/example_test_gtest.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/test/example_params.yaml) - target_include_directories(test_example_gtest PRIVATE include) - target_link_libraries(test_example_gtest generate_parameter_library_example::admittance_controller_parameters rclcpp::rclcpp) - # descriptor_test_gtest - add_rostest_with_parameters_gtest(test_descriptor_gtest test/descriptor_test_gtest.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/test/example_params.yaml) - target_include_directories(test_descriptor_gtest PRIVATE include) - target_link_libraries(test_descriptor_gtest generate_parameter_library_example::admittance_controller_parameters rclcpp::rclcpp) - - find_package(ament_cmake_gmock REQUIRED) - add_rostest_with_parameters_gmock(test_example_gmock test/example_test_gmock.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/test/example_params.yaml) - target_include_directories(test_example_gmock PRIVATE include) - target_link_libraries(test_example_gmock generate_parameter_library_example::admittance_controller_parameters rclcpp::rclcpp) -endif() - install( DIRECTORY include/ DESTINATION include/generate_parameter_library_example_external diff --git a/example_external/test/descriptor_test_gtest.cpp b/example_external/test/descriptor_test_gtest.cpp deleted file mode 100644 index b9736655..00000000 --- a/example_external/test/descriptor_test_gtest.cpp +++ /dev/null @@ -1,98 +0,0 @@ -// Copyright 2023 Picknik Robotics -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// -// * Redistributions in binary form must reproduce the above copyright -// notice, this list of conditions and the following disclaimer in the -// documentation and/or other materials provided with the distribution. -// -// * Neither the name of the PickNik Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -// POSSIBILITY OF SUCH DAMAGE. -// -// Author: Chance Cardona -// - -#include "generate_parameter_library_example/admittance_controller_parameters.hpp" -#include "gtest/gtest.h" -#include "rclcpp/rclcpp.hpp" - -#include -#include - -class DescriptorTest : public ::testing::Test { - public: - void SetUp() { - example_test_node_ = std::make_shared("example_test_node"); - - std::shared_ptr param_listener = - std::make_shared( - example_test_node_->get_node_parameters_interface()); - params_ = param_listener->get_params(); - std::vector names = {"admittance.damping_ratio", "one_number", - "pid.joint4.p", "lt_eq_fifteen", - "gt_fifteen"}; - descriptors_ = example_test_node_->describe_parameters(names); - } - - void TearDown() { example_test_node_.reset(); } - - protected: - std::shared_ptr example_test_node_; - admittance_controller::Params params_; - std::vector descriptors_; -}; - -// Checks element_bounds<> on a float -TEST_F(DescriptorTest, check_floating_point_descriptors) { - EXPECT_EQ(descriptors_[0].floating_point_range.at(0).from_value, 0.1); - EXPECT_EQ(descriptors_[0].floating_point_range.at(0).to_value, 10); -} - -// Checks bounds<> on an int -TEST_F(DescriptorTest, check_integer_descriptors) { - EXPECT_EQ(descriptors_[1].integer_range.at(0).from_value, 1024); - EXPECT_EQ(descriptors_[1].integer_range.at(0).to_value, 65535); -} - -TEST_F(DescriptorTest, check_lower_upper_bounds) { - EXPECT_EQ(descriptors_[2].floating_point_range.at(0).from_value, 0.0001); - EXPECT_EQ(descriptors_[2].floating_point_range.at(0).to_value, - std::numeric_limits::max()); -} - -TEST_F(DescriptorTest, check_lt_eq) { - EXPECT_EQ(descriptors_[3].integer_range.at(0).from_value, - std::numeric_limits::lowest()); - EXPECT_EQ(descriptors_[3].integer_range.at(0).to_value, 15); -} - -TEST_F(DescriptorTest, check_gt) { - EXPECT_EQ(descriptors_[4].integer_range.at(0).from_value, 15); - EXPECT_EQ(descriptors_[4].integer_range.at(0).to_value, - std::numeric_limits::max()); -} - -int main(int argc, char** argv) { - ::testing::InitGoogleTest(&argc, argv); - rclcpp::init(argc, argv); - int result = RUN_ALL_TESTS(); - rclcpp::shutdown(); - return result; -} diff --git a/example_external/test/example_params.yaml b/example_external/test/example_params.yaml deleted file mode 100644 index 81ea48b8..00000000 --- a/example_external/test/example_params.yaml +++ /dev/null @@ -1,53 +0,0 @@ -example_test_node: - ros__parameters: - - joints: - - joint4 - - joint5 - - joint6 - - ft_sensor: - name: "ft_sensor" - frame: - id: "sensor_frame_id" - filter_coefficient: 0.1 - - - # mandatory parameters not relevant for the test - fixed_string_no_default: "stringy" - command_interfaces: - - "one" - - "two" - state_interfaces: - - "one" - - "two" - chainable_command_interfaces: - - "one" - - "two" - - kinematics: - plugin_name: "kinematics" - plugin_package: "kinematics_pkg" - base: "base_link" - tip: "tcp" - group_name: "manip" - - control: - frame: - id: "control_frame_id" - - fixed_world_frame: - frame: - id: "world_frame" - - gravity_compensation: - frame: - id: "world_frame" - CoG: - pos: [1.0, 2.2, 3.4] - - admittance: - selected_axes: [true, false, true, false, true, false] - mass: [1.2, 2.3, 3.4, 4.5, 5.6, 6.7] - stiffness: [1.2, 2.3, 3.4, 4.5, 5.6, 6.7] - damping_ratio: [1.1, 1.1, 1.1, 1.1, 1.1, 1.1] diff --git a/example_external/test/example_test_gmock.cpp b/example_external/test/example_test_gmock.cpp deleted file mode 100644 index 63486c25..00000000 --- a/example_external/test/example_test_gmock.cpp +++ /dev/null @@ -1,71 +0,0 @@ -// Copyright 2022 Stogl Robotics Consulting -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// -// * Redistributions in binary form must reproduce the above copyright -// notice, this list of conditions and the following disclaimer in the -// documentation and/or other materials provided with the distribution. -// -// * Neither the name of the PickNik Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -// POSSIBILITY OF SUCH DAMAGE. -// -// Author: Denis Štogl -// - -#include "generate_parameter_library_example/admittance_controller_parameters.hpp" -#include "gmock/gmock.h" -#include "rclcpp/rclcpp.hpp" - -#include - -class ExampleTest : public ::testing::Test { - public: - void SetUp() { - example_test_node_ = std::make_shared("example_test_node"); - - std::shared_ptr param_listener = - std::make_shared( - example_test_node_->get_node_parameters_interface()); - params_ = param_listener->get_params(); - } - - void TearDown() { example_test_node_.reset(); } - - protected: - std::shared_ptr example_test_node_; - admittance_controller::Params params_; -}; - -TEST_F(ExampleTest, check_parameters) { - ASSERT_EQ(params_.interpolation_mode, "spline"); // default value - - ASSERT_THAT(params_.joints, - ::testing::ElementsAreArray({"joint4", "joint5", "joint6"})); - - ASSERT_EQ(params_.ft_sensor.filter_coefficient, 0.1); -} - -int main(int argc, char** argv) { - ::testing::InitGoogleTest(&argc, argv); - rclcpp::init(argc, argv); - int result = RUN_ALL_TESTS(); - rclcpp::shutdown(); - return result; -} diff --git a/example_external/test/example_test_gtest.cpp b/example_external/test/example_test_gtest.cpp deleted file mode 100644 index 40e06e14..00000000 --- a/example_external/test/example_test_gtest.cpp +++ /dev/null @@ -1,82 +0,0 @@ -// Copyright 2022 Stogl Robotics Consulting -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// -// * Redistributions in binary form must reproduce the above copyright -// notice, this list of conditions and the following disclaimer in the -// documentation and/or other materials provided with the distribution. -// -// * Neither the name of the PickNik Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -// POSSIBILITY OF SUCH DAMAGE. -// -// Author: Denis Štogl -// - -#include "generate_parameter_library_example/admittance_controller_parameters.hpp" -#include "gtest/gtest.h" -#include "rclcpp/rclcpp.hpp" - -#include - -class ExampleTest : public ::testing::Test { - public: - void SetUp() { - example_test_node_ = std::make_shared("example_test_node"); - - param_listener_ = std::make_shared( - example_test_node_->get_node_parameters_interface()); - params_ = param_listener_->get_params(); - } - - void TearDown() { example_test_node_.reset(); } - - protected: - std::shared_ptr example_test_node_; - admittance_controller::Params params_; - std::shared_ptr param_listener_; -}; - -TEST_F(ExampleTest, check_parameters) { - ASSERT_EQ(params_.interpolation_mode, "spline"); // default value - - ASSERT_EQ(params_.joints.size(), 3); - EXPECT_EQ(params_.joints[0], "joint4"); - EXPECT_EQ(params_.joints[1], "joint5"); - EXPECT_EQ(params_.joints[2], "joint6"); - - ASSERT_EQ(params_.ft_sensor.filter_coefficient, 0.1); -} - -TEST_F(ExampleTest, try_get_params) { - ASSERT_TRUE(param_listener_->try_get_params(params_)); - - const rclcpp ::Parameter new_param("interpolation_mode", "linear"); - example_test_node_->set_parameter(new_param); - ASSERT_TRUE(param_listener_->try_get_params(params_)); - ASSERT_EQ(params_.interpolation_mode, "linear"); -} - -int main(int argc, char** argv) { - ::testing::InitGoogleTest(&argc, argv); - rclcpp::init(argc, argv); - int result = RUN_ALL_TESTS(); - rclcpp::shutdown(); - return result; -} diff --git a/generate_parameter_library/cmake/generate_parameter_library.cmake b/generate_parameter_library/cmake/generate_parameter_library.cmake index 02c69ca8..ad202a08 100644 --- a/generate_parameter_library/cmake/generate_parameter_library.cmake +++ b/generate_parameter_library/cmake/generate_parameter_library.cmake @@ -72,7 +72,7 @@ function(generate_parameter_library LIB_NAME YAML_FILE) set(LOCAL_PARAM_HEADER_FILE ${CMAKE_CURRENT_BINARY_DIR}/include/${LIB_NAME}.hpp) add_custom_command( OUTPUT ${LOCAL_PARAM_HEADER_FILE} - COMMAND ${CMAKE_COMMAND} -E echo "#pragma warning(\"`#include <${LIB_NAME}>` is deprecated. Use `#include <${PROJECT_NAME}/${LIB_NAME}.hpp>` instead.\")" >> ${LOCAL_PARAM_HEADER_FILE} + COMMAND ${CMAKE_COMMAND} -E echo "#pragma message(\"#include \\\"${LIB_NAME}.hpp\\\" is deprecated. Use #include <${PROJECT_NAME}/${LIB_NAME}.hpp> instead.\")" >> ${LOCAL_PARAM_HEADER_FILE} COMMAND ${CMAKE_COMMAND} -E cat ${LOCAL_PARAM_HEADER_FILE} ${PARAM_HEADER_FILE} > ${LOCAL_PARAM_HEADER_FILE}.tmp COMMAND ${CMAKE_COMMAND} -E copy ${LOCAL_PARAM_HEADER_FILE}.tmp ${LOCAL_PARAM_HEADER_FILE} COMMAND ${CMAKE_COMMAND} -E remove ${LOCAL_PARAM_HEADER_FILE}.tmp From 7b6e66bdba299d5cd84497f4353905e338d57678 Mon Sep 17 00:00:00 2001 From: AugusteBourgois Date: Thu, 8 Aug 2024 12:22:55 +0200 Subject: [PATCH 06/12] correct old ehaders and empty changelog file --- .../minimal_publisher.hpp | 2 +- example/src/minimal_publisher.cpp | 2 +- example/test/descriptor_test_gtest.cpp | 2 +- example/test/example_test_gmock.cpp | 2 +- example/test/example_test_gtest.cpp | 2 +- example_external/CHANGELOG.rst | 8 -------- 6 files changed, 5 insertions(+), 13 deletions(-) diff --git a/example/include/generate_parameter_library_example/minimal_publisher.hpp b/example/include/generate_parameter_library_example/minimal_publisher.hpp index cacce19d..9a002b7f 100644 --- a/example/include/generate_parameter_library_example/minimal_publisher.hpp +++ b/example/include/generate_parameter_library_example/minimal_publisher.hpp @@ -31,7 +31,7 @@ #include #include -#include +#include namespace admittance_controller { diff --git a/example/src/minimal_publisher.cpp b/example/src/minimal_publisher.cpp index e4021b3d..62cdaa4c 100644 --- a/example/src/minimal_publisher.cpp +++ b/example/src/minimal_publisher.cpp @@ -30,7 +30,7 @@ #include -#include +#include using namespace std::chrono_literals; diff --git a/example/test/descriptor_test_gtest.cpp b/example/test/descriptor_test_gtest.cpp index ee81f0bf..ad349f2f 100644 --- a/example/test/descriptor_test_gtest.cpp +++ b/example/test/descriptor_test_gtest.cpp @@ -29,7 +29,7 @@ // Author: Chance Cardona // -#include "admittance_controller_parameters.hpp" +#include "generate_parameter_library_example/admittance_controller_parameters.hpp" #include "gtest/gtest.h" #include "rclcpp/rclcpp.hpp" diff --git a/example/test/example_test_gmock.cpp b/example/test/example_test_gmock.cpp index 15b37351..63486c25 100644 --- a/example/test/example_test_gmock.cpp +++ b/example/test/example_test_gmock.cpp @@ -29,7 +29,7 @@ // Author: Denis Štogl // -#include "admittance_controller_parameters.hpp" +#include "generate_parameter_library_example/admittance_controller_parameters.hpp" #include "gmock/gmock.h" #include "rclcpp/rclcpp.hpp" diff --git a/example/test/example_test_gtest.cpp b/example/test/example_test_gtest.cpp index b7593ba1..40e06e14 100644 --- a/example/test/example_test_gtest.cpp +++ b/example/test/example_test_gtest.cpp @@ -29,7 +29,7 @@ // Author: Denis Štogl // -#include "admittance_controller_parameters.hpp" +#include "generate_parameter_library_example/admittance_controller_parameters.hpp" #include "gtest/gtest.h" #include "rclcpp/rclcpp.hpp" diff --git a/example_external/CHANGELOG.rst b/example_external/CHANGELOG.rst index 53f0675a..e69de29b 100644 --- a/example_external/CHANGELOG.rst +++ b/example_external/CHANGELOG.rst @@ -1,8 +0,0 @@ -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -Changelog for package generate_parameter_library_example_external -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -0.1.0 (2024-08-07) ------------------- -* Example usage of generated header from another package (generate_parameter_library_example) -* Contributors: Auguste Bourgois From d8beefbd669121aaf33c304b4d25fdc977a123c4 Mon Sep 17 00:00:00 2001 From: AugusteBourgois Date: Tue, 13 Aug 2024 12:36:15 +0200 Subject: [PATCH 07/12] export target in the macro --- example/CMakeLists.txt | 2 +- .../cmake/generate_parameter_library.cmake | 15 ++++++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index a61d2c81..9e9ed22e 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -66,7 +66,7 @@ install( DESTINATION include/generate_parameter_library_example ) -install(TARGETS minimal_publisher admittance_controller_parameters +install(TARGETS minimal_publisher EXPORT export_generate_parameter_library_example ARCHIVE DESTINATION lib LIBRARY DESTINATION lib diff --git a/generate_parameter_library/cmake/generate_parameter_library.cmake b/generate_parameter_library/cmake/generate_parameter_library.cmake index ad202a08..08e22357 100644 --- a/generate_parameter_library/cmake/generate_parameter_library.cmake +++ b/generate_parameter_library/cmake/generate_parameter_library.cmake @@ -27,7 +27,7 @@ # POSSIBILITY OF SUCH DAMAGE. -function(generate_parameter_library LIB_NAME YAML_FILE) +macro(generate_parameter_library LIB_NAME YAML_FILE) unset(generate_parameter_library_cpp_BIN CACHE) # Unset the cache variable find_program(generate_parameter_library_cpp_BIN NAMES "generate_parameter_library_cpp") if(NOT generate_parameter_library_cpp_BIN) @@ -54,7 +54,7 @@ function(generate_parameter_library LIB_NAME YAML_FILE) endif() # Set the yaml file parameter to be relative to the current source dir - set(YAML_FILE ${CMAKE_CURRENT_SOURCE_DIR}/${YAML_FILE}) + set(YAML_FILE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/${YAML_FILE}) # Set the output parameter header file name set(PARAM_HEADER_FILE ${LIB_INCLUDE_DIR}/${LIB_NAME}.hpp) @@ -62,10 +62,10 @@ function(generate_parameter_library LIB_NAME YAML_FILE) # Generate the header for the library add_custom_command( OUTPUT ${PARAM_HEADER_FILE} - COMMAND ${generate_parameter_library_cpp_BIN} ${PARAM_HEADER_FILE} ${YAML_FILE} ${VALIDATE_HEADER_FILENAME} - DEPENDS ${YAML_FILE} ${VALIDATE_HEADER} + COMMAND ${generate_parameter_library_cpp_BIN} ${PARAM_HEADER_FILE} ${YAML_FILE_PATH} ${VALIDATE_HEADER_FILENAME} + DEPENDS ${YAML_FILE_PATH} ${VALIDATE_HEADER} COMMENT - "Running `${generate_parameter_library_cpp_BIN} ${PARAM_HEADER_FILE} ${YAML_FILE} ${VALIDATE_HEADER_FILENAME}`" + "Running `${generate_parameter_library_cpp_BIN} ${PARAM_HEADER_FILE} ${YAML_FILE_PATH} ${VALIDATE_HEADER_FILENAME}`" VERBATIM ) # necessary so that #include can be used in the local package (deprecated) @@ -99,9 +99,10 @@ function(generate_parameter_library LIB_NAME YAML_FILE) tl_expected::tl_expected ) install(DIRECTORY ${LIB_INCLUDE_DIR} DESTINATION include) + install(TARGETS ${LIB_NAME} EXPORT ${PROJECT_NAME}Targets) + ament_export_targets(${PROJECT_NAME}Targets HAS_LIBRARY_TARGET) ament_export_dependencies(fmt parameter_traits rclcpp rclcpp_lifecycle rsl tcb_span tl_expected) - set(_AMENT_CMAKE_EXPORT_DEPENDENCIES "${_AMENT_CMAKE_EXPORT_DEPENDENCIES}" PARENT_SCOPE) -endfunction() +endmacro() function(generate_parameter_module LIB_NAME YAML_FILE) From 6f3bfe7d3347ece2574bb81047647c6176df1333 Mon Sep 17 00:00:00 2001 From: AugusteBourgois Date: Mon, 19 Aug 2024 12:15:23 +0200 Subject: [PATCH 08/12] correct cmake linter error --- .../cmake/generate_parameter_library.cmake | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/generate_parameter_library/cmake/generate_parameter_library.cmake b/generate_parameter_library/cmake/generate_parameter_library.cmake index 08e22357..6926d8e7 100644 --- a/generate_parameter_library/cmake/generate_parameter_library.cmake +++ b/generate_parameter_library/cmake/generate_parameter_library.cmake @@ -71,15 +71,16 @@ macro(generate_parameter_library LIB_NAME YAML_FILE) # necessary so that #include can be used in the local package (deprecated) set(LOCAL_PARAM_HEADER_FILE ${CMAKE_CURRENT_BINARY_DIR}/include/${LIB_NAME}.hpp) add_custom_command( - OUTPUT ${LOCAL_PARAM_HEADER_FILE} - COMMAND ${CMAKE_COMMAND} -E echo "#pragma message(\"#include \\\"${LIB_NAME}.hpp\\\" is deprecated. Use #include <${PROJECT_NAME}/${LIB_NAME}.hpp> instead.\")" >> ${LOCAL_PARAM_HEADER_FILE} - COMMAND ${CMAKE_COMMAND} -E cat ${LOCAL_PARAM_HEADER_FILE} ${PARAM_HEADER_FILE} > ${LOCAL_PARAM_HEADER_FILE}.tmp - COMMAND ${CMAKE_COMMAND} -E copy ${LOCAL_PARAM_HEADER_FILE}.tmp ${LOCAL_PARAM_HEADER_FILE} - COMMAND ${CMAKE_COMMAND} -E remove ${LOCAL_PARAM_HEADER_FILE}.tmp - DEPENDS ${PARAM_HEADER_FILE} - COMMENT - "Creating deprecated header file ${LOCAL_PARAM_HEADER_FILE}" - VERBATIM + OUTPUT ${LOCAL_PARAM_HEADER_FILE} + COMMAND ${CMAKE_COMMAND} -E echo "#pragma message(\"#include \\\"${LIB_NAME}.hpp\\\" is deprecated. \ +Use #include <${PROJECT_NAME}/${LIB_NAME}.hpp> instead.\")" >> ${LOCAL_PARAM_HEADER_FILE} + COMMAND ${CMAKE_COMMAND} -E cat ${LOCAL_PARAM_HEADER_FILE} ${PARAM_HEADER_FILE} > ${LOCAL_PARAM_HEADER_FILE}.tmp + COMMAND ${CMAKE_COMMAND} -E copy ${LOCAL_PARAM_HEADER_FILE}.tmp ${LOCAL_PARAM_HEADER_FILE} + COMMAND ${CMAKE_COMMAND} -E remove ${LOCAL_PARAM_HEADER_FILE}.tmp + DEPENDS ${PARAM_HEADER_FILE} + COMMENT + "Creating deprecated header file ${LOCAL_PARAM_HEADER_FILE}" + VERBATIM ) # Create the library target From e821dffdc7b6c44b4e72ff843e6bc18e3b1fec66 Mon Sep 17 00:00:00 2001 From: AugusteBourgois Date: Fri, 4 Oct 2024 10:29:49 +0200 Subject: [PATCH 09/12] Target must be manually exported to avoid breaking change --- README.md | 3 +++ example/CMakeLists.txt | 2 +- .../cmake/generate_parameter_library.cmake | 2 -- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index a3867c60..1bb3f7af 100644 --- a/README.md +++ b/README.md @@ -63,6 +63,9 @@ target_link_libraries(minimal_node PRIVATE rclcpp::rclcpp turtlesim_parameters ) + +install(TARGETS minimal_node turtlesim_parameters + EXPORT ${PROJECT_NAME}Targets ``` **setup.py** diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index 9e9ed22e..a61d2c81 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -66,7 +66,7 @@ install( DESTINATION include/generate_parameter_library_example ) -install(TARGETS minimal_publisher +install(TARGETS minimal_publisher admittance_controller_parameters EXPORT export_generate_parameter_library_example ARCHIVE DESTINATION lib LIBRARY DESTINATION lib diff --git a/generate_parameter_library/cmake/generate_parameter_library.cmake b/generate_parameter_library/cmake/generate_parameter_library.cmake index 6926d8e7..07bf3a29 100644 --- a/generate_parameter_library/cmake/generate_parameter_library.cmake +++ b/generate_parameter_library/cmake/generate_parameter_library.cmake @@ -100,8 +100,6 @@ Use #include <${PROJECT_NAME}/${LIB_NAME}.hpp> instead.\")" >> ${LOCAL_PARAM_HEA tl_expected::tl_expected ) install(DIRECTORY ${LIB_INCLUDE_DIR} DESTINATION include) - install(TARGETS ${LIB_NAME} EXPORT ${PROJECT_NAME}Targets) - ament_export_targets(${PROJECT_NAME}Targets HAS_LIBRARY_TARGET) ament_export_dependencies(fmt parameter_traits rclcpp rclcpp_lifecycle rsl tcb_span tl_expected) endmacro() From 7772d18a4239737f8d7b673bba50221a1c1aef52 Mon Sep 17 00:00:00 2001 From: AugusteBourgois Date: Mon, 7 Oct 2024 10:27:36 +0200 Subject: [PATCH 10/12] correct the readme --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1bb3f7af..17ece4c3 100644 --- a/README.md +++ b/README.md @@ -65,7 +65,8 @@ target_link_libraries(minimal_node PRIVATE ) install(TARGETS minimal_node turtlesim_parameters - EXPORT ${PROJECT_NAME}Targets + EXPORT ${PROJECT_NAME}Targets) +ament_export_targets(${PROJECT_NAME}Targets HAS_LIBRARY_TARGET) ``` **setup.py** From bd7c6086628bd80ca615b4129f4a04e0d71ce4c1 Mon Sep 17 00:00:00 2001 From: AugusteBourgois Date: Thu, 21 Nov 2024 20:46:17 +0100 Subject: [PATCH 11/12] pre commit step --- .../generate_parameter_module_example/minimal_publisher.py | 1 + 1 file changed, 1 insertion(+) diff --git a/example_python/generate_parameter_module_example/minimal_publisher.py b/example_python/generate_parameter_module_example/minimal_publisher.py index 7eaf59cb..35ae3c24 100644 --- a/example_python/generate_parameter_module_example/minimal_publisher.py +++ b/example_python/generate_parameter_module_example/minimal_publisher.py @@ -36,6 +36,7 @@ class MinimalParam(rclpy.node.Node): + def __init__(self): super().__init__('admittance_controller') self.timer = self.create_timer(1, self.timer_callback) From cd67e192abf2e10a07440d128422b4142857e9ca Mon Sep 17 00:00:00 2001 From: AugusteBourgois Date: Mon, 6 Jan 2025 10:34:05 +0100 Subject: [PATCH 12/12] Add sea-bass suggestions --- example_external/README.md | 13 ++++++++++--- .../minimal_publisher_external.hpp | 4 ++-- example_external/src/minimal_publisher_external.cpp | 4 ++-- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/example_external/README.md b/example_external/README.md index a34836ee..09fbb164 100644 --- a/example_external/README.md +++ b/example_external/README.md @@ -1,4 +1,9 @@ -# Example: +# Using parameters defined in another package + +This package is a minimal example demonstrating how the parameters defined in `generate_parameter_library/example` +can be used in a different package (i.e. the current one : `generate_parameter_library/example_external`). + +In particular, check the `CMakeLists.txt` file and the `#include` instructions in the source files. ## Build the node @@ -93,7 +98,8 @@ You should see: use_sim_time ``` -All parameter are automatically declared and callbacks are setup by default. You can set a parameter by typing: +All parameters are automatically declared and callbacks are setup by default. +You can set a parameter by typing: `ros2 param set /admittance_controller control.frame.id new_frame` @@ -103,7 +109,8 @@ You should see: Congratulations, you updated the parameter! -If you try to set a parameter that is read only, you will get an error. Running the following +If you try to set a parameter that is read only, you will get an error. +Running the following `ros2 param set /admittance_controller command_interfaces ["velocity"]` diff --git a/example_external/include/generate_parameter_library_example_external/minimal_publisher_external.hpp b/example_external/include/generate_parameter_library_example_external/minimal_publisher_external.hpp index 9a002b7f..cfca521e 100644 --- a/example_external/include/generate_parameter_library_example_external/minimal_publisher_external.hpp +++ b/example_external/include/generate_parameter_library_example_external/minimal_publisher_external.hpp @@ -1,4 +1,4 @@ -// Copyright 2022 PickNik Inc. +// Copyright 2025 Forssea Robotics // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -10,7 +10,7 @@ // notice, this list of conditions and the following disclaimer in the // documentation and/or other materials provided with the distribution. // -// * Neither the name of the PickNik Inc. nor the names of its +// * Neither the name of Forssea Robotics nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // diff --git a/example_external/src/minimal_publisher_external.cpp b/example_external/src/minimal_publisher_external.cpp index c2b23abb..bf2396b2 100644 --- a/example_external/src/minimal_publisher_external.cpp +++ b/example_external/src/minimal_publisher_external.cpp @@ -1,4 +1,4 @@ -// Copyright 2022 PickNik Inc. +// Copyright 2025 Forssea Robotics // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: @@ -10,7 +10,7 @@ // notice, this list of conditions and the following disclaimer in the // documentation and/or other materials provided with the distribution. // -// * Neither the name of the PickNik Inc. nor the names of its +// * Neither the name of Forssea Robotics nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. //