Skip to content

Commit 01e9dce

Browse files
Change header install path (#213)
1 parent 75a8d4c commit 01e9dce

File tree

15 files changed

+571
-30
lines changed

15 files changed

+571
-30
lines changed

README.md

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ target_link_libraries(minimal_node PRIVATE
6363
rclcpp::rclcpp
6464
turtlesim_parameters
6565
)
66+
67+
install(TARGETS minimal_node turtlesim_parameters
68+
EXPORT ${PROJECT_NAME}Targets)
69+
ament_export_targets(${PROJECT_NAME}Targets HAS_LIBRARY_TARGET)
6670
```
6771

6872
**setup.py**
@@ -80,7 +84,7 @@ generate_parameter_module(
8084
**src/turtlesim.cpp**
8185
```c++
8286
#include <rclcpp/rclcpp.hpp>
83-
#include "turtlesim_parameters.hpp"
87+
#include <turtlesim/turtlesim_parameters.hpp> // you can also use the deprecated #include "turtlesim_parameters.hpp"
8488

8589
int main(int argc, char * argv[])
8690
{
@@ -350,10 +354,46 @@ The generated parameter value for the nested map example can then be accessed wi
350354

351355
### Use generated struct in Cpp
352356
The generated header file is named based on the target library name you passed as the first argument to the cmake function.
353-
If you specified it to be `turtlesim_parameters` you can then include the generated code with `#include "turtlesim_parameters.hpp"`.
357+
If you specified it to be `turtlesim_parameters` you can then include the generated code with `#include <turtlesim/turtlesim_parameters.hpp>`.
354358
```c++
355-
#include "turtlesim_parameters.hpp"
359+
#include <turtlesim/turtlesim_parameters.hpp>
356360
```
361+
362+
Note that this header can also be used from another package:
363+
```cmake
364+
cmake_minimum_required(VERSION 3.8)
365+
project(my_other_package)
366+
367+
368+
include(GNUInstallDirs)
369+
370+
# find dependencies
371+
find_package(ament_cmake REQUIRED)
372+
find_package(turtelsim REQUIRED)
373+
374+
add_library(my_lib src/my_lib.cpp)
375+
target_include_directories(my_lib PUBLIC
376+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
377+
$<INSTALL_INTERFACE:include>)
378+
target_link_libraries(my_lib PUBLIC turtlesim::turtlesim_parameters)
379+
380+
#############
381+
## Install ##
382+
#############
383+
384+
install(DIRECTORY include/${PROJECT_NAME}/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME})
385+
386+
install(TARGETS my_lib
387+
EXPORT ${PROJECT_NAME}Targets
388+
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
389+
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
390+
RUNTIME DESTINATION lib/${PROJECT_NAME})
391+
392+
ament_export_targets(${PROJECT_NAME}Targets HAS_LIBRARY_TARGET)
393+
ament_export_dependencies(turtlesim)
394+
ament_package()
395+
```
396+
357397
In your initialization code, create a `ParamListener` which will declare and get the parameters.
358398
An exception will be thrown if any validation fails or any required parameters were not set.
359399
Then call `get_params` on the listener to get a copy of the `Params` struct.

example/include/generate_parameter_library_example/minimal_publisher.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
#include <rclcpp/rclcpp.hpp>
3232
#include <rclcpp_components/register_node_macro.hpp>
3333

34-
#include <admittance_controller_parameters.hpp>
34+
#include <generate_parameter_library_example/admittance_controller_parameters.hpp>
3535

3636
namespace admittance_controller {
3737

example/src/minimal_publisher.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
#include <rclcpp/rclcpp.hpp>
3232

33-
#include <admittance_controller_parameters.hpp>
33+
#include <generate_parameter_library_example/admittance_controller_parameters.hpp>
3434

3535
using namespace std::chrono_literals;
3636

example/test/descriptor_test_gtest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
// Author: Chance Cardona
3030
//
3131

32-
#include "admittance_controller_parameters.hpp"
32+
#include "generate_parameter_library_example/admittance_controller_parameters.hpp"
3333
#include "gtest/gtest.h"
3434
#include "rclcpp/rclcpp.hpp"
3535

example/test/example_test_gmock.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
// Author: Denis Štogl
3030
//
3131

32-
#include "admittance_controller_parameters.hpp"
32+
#include "generate_parameter_library_example/admittance_controller_parameters.hpp"
3333
#include "gmock/gmock.h"
3434
#include "rclcpp/rclcpp.hpp"
3535

example/test/example_test_gtest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
// Author: Denis Štogl
3030
//
3131

32-
#include "admittance_controller_parameters.hpp"
32+
#include "generate_parameter_library_example/admittance_controller_parameters.hpp"
3333
#include "gtest/gtest.h"
3434
#include "rclcpp/rclcpp.hpp"
3535

example_external/CHANGELOG.rst

Whitespace-only changes.

example_external/CMakeLists.txt

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
cmake_minimum_required(VERSION 3.16)
2+
project(generate_parameter_library_example_external)
3+
4+
if(CMAKE_CXX_COMPILER_ID MATCHES "(GNU|Clang)")
5+
add_compile_options(-Wall -Wextra -Wpedantic -Wshadow -Wconversion -Wsign-conversion -Wold-style-cast)
6+
endif()
7+
8+
find_package(ament_cmake REQUIRED)
9+
find_package(ament_cmake_python REQUIRED)
10+
find_package(rclcpp REQUIRED)
11+
find_package(rclcpp_components REQUIRED)
12+
find_package(rclpy REQUIRED)
13+
find_package(generate_parameter_library_example REQUIRED)
14+
15+
add_library(minimal_publisher_external SHARED
16+
src/minimal_publisher_external.cpp
17+
)
18+
target_include_directories(minimal_publisher_external PUBLIC
19+
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
20+
$<INSTALL_INTERFACE:include/generate_parameter_library_example_external>
21+
)
22+
target_link_libraries(minimal_publisher_external
23+
PUBLIC
24+
rclcpp::rclcpp
25+
rclcpp_components::component
26+
generate_parameter_library_example::admittance_controller_parameters
27+
)
28+
rclcpp_components_register_node(minimal_publisher_external
29+
PLUGIN "admittance_controller::MinimalPublisher"
30+
EXECUTABLE test_node
31+
)
32+
33+
install(
34+
DIRECTORY include/
35+
DESTINATION include/generate_parameter_library_example_external
36+
)
37+
38+
install(TARGETS minimal_publisher_external
39+
EXPORT export_generate_parameter_library_example_external
40+
ARCHIVE DESTINATION lib
41+
LIBRARY DESTINATION lib
42+
RUNTIME DESTINATION bin
43+
)
44+
45+
install(
46+
TARGETS test_node
47+
DESTINATION lib/generate_parameter_library_example_external
48+
)
49+
50+
ament_export_targets(export_generate_parameter_library_example_external HAS_LIBRARY_TARGET)
51+
ament_export_dependencies(rclcpp rclcpp_components generate_parameter_library_example)
52+
ament_package()

example_external/README.md

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
# Using parameters defined in another package
2+
3+
This package is a minimal example demonstrating how the parameters defined in `generate_parameter_library/example`
4+
can be used in a different package (i.e. the current one : `generate_parameter_library/example_external`).
5+
6+
In particular, check the `CMakeLists.txt` file and the `#include` instructions in the source files.
7+
8+
## Build the node
9+
10+
```
11+
mkdir colcon_ws
12+
mkdir colcon_ws/src
13+
cd colcon_ws/src
14+
git clone https://github.com/picknikrobotics/generate_parameter_library.git
15+
cd ..
16+
colcon build
17+
```
18+
19+
## Run the C++ node
20+
21+
```
22+
source install/setup.bash
23+
ros2 run generate_parameter_library_example_external test_node --ros-args --params-file src/generate_parameter_library/example_external/config/implementation.yaml
24+
```
25+
26+
You should see an output like this:
27+
`[INFO] [1656018676.015816509] [admittance_controller]: Control frame is: 'ee_link'`
28+
29+
## ROS 2 CLI
30+
31+
Run the following:
32+
33+
`ros2 param list`
34+
35+
You should see:
36+
37+
```
38+
/admittance_controller:
39+
admittance.damping_ratio
40+
admittance.mass
41+
admittance.selected_axes
42+
admittance.stiffness
43+
chainable_command_interfaces
44+
command_interfaces
45+
control.frame.external
46+
control.frame.id
47+
enable_parameter_update_without_reactivation
48+
fixed_array
49+
fixed_string
50+
fixed_string_no_default
51+
fixed_world_frame.frame.external
52+
fixed_world_frame.frame.id
53+
ft_sensor.filter_coefficient
54+
ft_sensor.frame.external
55+
ft_sensor.frame.id
56+
ft_sensor.name
57+
gravity_compensation.CoG.force
58+
gravity_compensation.CoG.pos
59+
gravity_compensation.frame.external
60+
gravity_compensation.frame.id
61+
interpolation_mode
62+
joints
63+
kinematics.alpha
64+
kinematics.base
65+
kinematics.group_name
66+
kinematics.plugin_name
67+
kinematics.plugin_package
68+
kinematics.tip
69+
one_number
70+
pid.elbow_joint.d
71+
pid.elbow_joint.i
72+
pid.elbow_joint.p
73+
pid.rate
74+
pid.shoulder_lift_joint.d
75+
pid.shoulder_lift_joint.i
76+
pid.shoulder_lift_joint.p
77+
pid.shoulder_pan_joint.d
78+
pid.shoulder_pan_joint.i
79+
pid.shoulder_pan_joint.p
80+
pid.wrist_1_joint.d
81+
pid.wrist_1_joint.i
82+
pid.wrist_1_joint.p
83+
pid.wrist_2_joint.d
84+
pid.wrist_2_joint.i
85+
pid.wrist_2_joint.p
86+
pid.wrist_3_joint.d
87+
pid.wrist_3_joint.i
88+
pid.wrist_3_joint.p
89+
qos_overrides./parameter_events.publisher.depth
90+
qos_overrides./parameter_events.publisher.durability
91+
qos_overrides./parameter_events.publisher.history
92+
qos_overrides./parameter_events.publisher.reliability
93+
scientific_notation_num
94+
state_interfaces
95+
three_numbers
96+
three_numbers_of_five
97+
use_feedforward_commanded_input
98+
use_sim_time
99+
```
100+
101+
All parameters are automatically declared and callbacks are setup by default.
102+
You can set a parameter by typing:
103+
104+
`ros2 param set /admittance_controller control.frame.id new_frame`
105+
106+
You should see:
107+
108+
`[INFO] [1656019001.515820371] [admittance_controller]: New control frame parameter is: 'new_frame'`
109+
110+
Congratulations, you updated the parameter!
111+
112+
If you try to set a parameter that is read only, you will get an error.
113+
Running the following
114+
115+
`ros2 param set /admittance_controller command_interfaces ["velocity"]`
116+
117+
will result in the error
118+
119+
`Setting parameter failed: parameter 'command_interfaces' cannot be set because it is read-only`
120+
121+
Running the following
122+
123+
`ros2 param describe /admittance_controller admittance.damping_ratio`
124+
125+
will show a parameter's description
126+
127+
```
128+
Parameter name: admittance.damping_ratio
129+
Type: double array
130+
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 ))
131+
Constraints:
132+
Min value: 0.1
133+
Max value: 10.0
134+
```
135+
136+
If you try to set a value out of the specified bounds,
137+
138+
`ros2 param set /admittance_controller admittance.damping_ratio [-10.0,-10.0,-10.0,-10.0,-10.0,-10.0]`
139+
140+
you will get the error
141+
142+
`Setting parameter failed: Value -10.0 in parameter 'admittance.damping_ratio' must be within bounds [0.1, 10.0]`
143+
144+
If you try to set a vector parameter with the wrong length,
145+
146+
`ros2 param set /admittance_controller admittance.damping_ratio [1.0,1.0,1.0]`
147+
148+
you will get the error
149+
150+
`Setting parameter failed: Length of parameter 'admittance.damping_ratio' is 3 but must be equal to 6`
151+
152+
If you try to load a yaml file with missing required parameters
153+
154+
`ros2 run generate_parameter_library_example test_node --ros-args --params-file src/generate_parameter_library/example_external/config/missing_required.yaml`
155+
156+
you will get the error
157+
158+
```
159+
terminate called after throwing an instance of 'rclcpp::exceptions::ParameterUninitializedException'
160+
what(): parameter 'fixed_string_no_default' is not initialized
161+
[ros2run]: Aborted
162+
```

0 commit comments

Comments
 (0)