-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFirstDR.cfg
More file actions
85 lines (73 loc) · 4.05 KB
/
FirstDR.cfg
File metadata and controls
85 lines (73 loc) · 4.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/env python3
"""
This is essentially a python file that describes the parameters concerned
Reference tutorial: https://wiki.ros.org/dynamic_reconfigure/Tutorials/HowToWriteYourFirstCfgFile
"""
# A variable to hold package name
PACKAGE = "cpp_basic_nodes"
# Import the dynamic_reconfigure package
# Link: http://docs.ros.org/en/melodic/api/catkin/html/howto/format1/dynamic_reconfiguration.html
# Location (on disk): /opt/ros/noetic/lib/python3/dist-packages/dynamic_reconfigure
# Catkin Link: https://docs.ros.org/en/indigo/api/catkin/html/howto/format2/dynamic_reconfiguration.html
from dynamic_reconfigure.parameter_generator_catkin import *
# Create a generation object (this will create dynamically reconfigurable parameters)
gen = ParameterGenerator()
# Use the .add() function to add a property for the dynamic reconfiguration server
"""
Parameters are
1. Name of the parameter to be created
2. Type of the parameter (can be int_t, double_t, str_t or bool_t only)
3. Level of the parameter
- In the event a set of parameters are changed at once, the levels of all the parameters that have
changed undergo a binary OR operation and that result is sent to the callback of the server
4. A Description for the parameter
5. Default value of the parameter (50 here)
6. Minimum value of the parameter (0 here, do not use this for str_t and bool_t)
7. Maximum value of the parameter (100 here, do not use this for str_t and bool_t)
"""
gen.add("user_int", int_t, 0, "A configurable integer", 50, 0, 100)
# Add a few more such basic parameters (as an example to demonstrate the significance of 'level')
"""
As an example, if usr_int1, usr_int2 and usr_int3 are all changed in just one request, then the resultant level will be
level of usr_int1 = 3, usr_int2 = 2, and usr_int3 = 8
3 | 2 | 8 = 0b0011 | 0b0010 | 0b1000 = 0b1011 = 11
You can use such methodologies to understand what exact parameters have been modified and what have stayed as they were
"""
gen.add("usr_int1", int_t, 3, "An integer with level 3", 50, 0, 100)
gen.add("usr_int2", int_t, 2, "An integer with level 2", 50, 0, 100)
gen.add("usr_int3", int_t, 8, "An integer with level 8", 50, 0, 100)
# Add some parameters of other types
gen.add("user_bool", bool_t, 0, "A boolean value", False)
gen.add("user_str", str_t, 0, "A string value", "Hello, World!")
# Create an enumerate type of selection (selection from a list)
# First, create an edit method that will be used to edit the field
"""
A ParameterGenerator.enum object creates an edit_method for the add method. The parameters are
- [constants]: An array of constants (type ParameterGenerator.const)
- The parameters of it are
- Name: Name of the constant
- Type: Type of the constants (they must all be of the same type)
- Value: A value of that type (for identification better keep it unique)
- Description: A description for the particular constant
- Description: A description of the enum
"""
size_enum = gen.enum(
[
gen.const("OP_1", int_t, 1, "Option 1"),
gen.const("OP_2", int_t, 2, "Option 2"),
gen.const("OP_3", int_t, 3, "Option 3")
],
"A selection between OP_1, OP_2 and OP_3"
)
# Add this to the list (use same type as that of enum constants). Notice the default value, min, max and edit_method
gen.add("OP_sel", int_t, 16, "A selection of options", 1, 1, 3, edit_method=size_enum)
# Generate the files needed for creating dynamic reconfiguration server and client
"""
In ParameterGenerator.generate function, the parameters are
- Package name, this was stored in PACKAGE variable
- A simple node name (for documentation only)
- See file 'FirstDRConfig-usage.dox' in 'devel/share/cpp_basic_nodes/docs' folder
- Name of the `.cfg` file (without extension)
This function returns an exit code (in case there's an error, it will be used to debug)
"""
exit(gen.generate(PACKAGE, "dynamic_reconfig_node", "FirstDR"))