Skip to content

Commit

Permalink
add reproducible test for loading parameter file.
Browse files Browse the repository at this point in the history
Signed-off-by: Tomoya Fujita <[email protected]>
  • Loading branch information
fujitatomoya committed Oct 27, 2021
1 parent 7a81aeb commit 9290736
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 0 deletions.
1 change: 1 addition & 0 deletions prover_rclcpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ custom_executable(rmw_fastrtps_555)
#custom_executable(ros2_946_pub)
#custom_executable(ros2_946_sub)
#custom_executable(ros2_1026)
custom_executable(ros2_1173)

#custom_executable(ros2cli_601)

Expand Down
13 changes: 13 additions & 0 deletions prover_rclcpp/src/ros2_1173.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include "rclcpp/rclcpp.hpp"

int main(int argc, char ** argv)
{
rclcpp::init(argc, argv);
rclcpp::NodeOptions options;
options.automatically_declare_parameters_from_overrides(true);

std::shared_ptr<rclcpp::Node> node = rclcpp::Node::make_shared("ParametersNode", options);

rclcpp::spin(node);
rclcpp::shutdown();
}
1 change: 1 addition & 0 deletions prover_rclpy/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
'rclpy_client_822 = src.rclpy_client_822:main',
'rclpy_server_822 = src.rclpy_server_822:main',
'rclpy_827 = src.rclpy_827:main',
'ros2_1173 = src.ros2_1173:main',
],
},
)
Binary file modified prover_rclpy/src/__pycache__/__init__.cpython-38.pyc
Binary file not shown.
38 changes: 38 additions & 0 deletions prover_rclpy/src/ros2_1173.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Refer to the following API:
import rclpy
from rclpy.node import Node
from rcl_interfaces.msg import SetParametersResult

class ParametersNode(Node):
def __init__(self):
super().__init__('ParametersNode', automatically_declare_parameters_from_overrides=True)
self.get_logger().info("Initialized Parameters Node.")
#self._timer = self.create_timer(1, self.printParam)
self.declare_parameter("self_declared_param", 45)
# self.set_parameters_callback(self.onParameterChange)
# self.add_on_set_parameters_callback(self.onParameterChange)

def printParam(self):
params = ["test", "group.list_param", "group.string_param", "group2.complex_param",
"group.group2.float_param", "group.group2.bool_param"]
for p in params:
try:
obj = self.get_parameter(p)
value = obj._value
self.get_logger().info(f"Parameter {p}: {value} ({type(value)}), ({obj.type_})")
except rclpy.exceptions.ParameterNotDeclaredException:
self.get_logger().info(f"Parameter {p} not defined!")

def onParameterChange(self, params):
txt = "\n".join(f" {p.name}={p.value}" for p in params)
self.get_logger().info("Parameter changed callback called! Changed parameters:\n" + txt)
return SetParametersResult(successful=True)

def main(args=None):
rclpy.init(args=args)

node = ParametersNode()
rclpy.spin(node)

node.destroy_node()
rclpy.shutdown()

0 comments on commit 9290736

Please sign in to comment.