-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add reproducible test for loading parameter file.
Signed-off-by: Tomoya Fujita <[email protected]>
- Loading branch information
1 parent
7a81aeb
commit 9290736
Showing
5 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |