From b038006967e336f7415bc3f9bafc0439140fb971 Mon Sep 17 00:00:00 2001 From: Yuntianyi Chen Date: Thu, 11 Jul 2024 21:57:50 +0800 Subject: [PATCH] refactor(dummy_infrastructure): rework parameters (#5275) Signed-off-by: Yuntianyi Chen --- system/dummy_infrastructure/CMakeLists.txt | 4 +- system/dummy_infrastructure/README.md | 3 +- .../config/dummy_infrastructure.param.yaml | 10 +-- .../launch/dummy_infrastructure.launch.xml | 1 + .../dummy_infrastructure_node.schema.json | 65 +++++++++++++++++++ .../dummy_infrastructure_node.cpp | 12 ++-- 6 files changed, 81 insertions(+), 14 deletions(-) create mode 100644 system/dummy_infrastructure/schema/dummy_infrastructure_node.schema.json diff --git a/system/dummy_infrastructure/CMakeLists.txt b/system/dummy_infrastructure/CMakeLists.txt index cfe326d7bb53b..5d3d39d02365d 100644 --- a/system/dummy_infrastructure/CMakeLists.txt +++ b/system/dummy_infrastructure/CMakeLists.txt @@ -15,6 +15,6 @@ rclcpp_components_register_node(dummy_infrastructure_node_component ament_auto_package( INSTALL_TO_SHARE - config - launch + launch + config ) diff --git a/system/dummy_infrastructure/README.md b/system/dummy_infrastructure/README.md index 2f3196189a1b3..d032bfa1a7e3d 100644 --- a/system/dummy_infrastructure/README.md +++ b/system/dummy_infrastructure/README.md @@ -29,8 +29,9 @@ ros2 run rqt_reconfigure rqt_reconfigure | Name | Type | Default Value | Explanation | | ------------------- | ------ | ------------- | ------------------------------------------------- | -| `update_rate` | int | `10` | Timer callback period [Hz] | +| `update_rate` | double | `10.0` | Timer callback period [Hz] | | `use_first_command` | bool | `true` | Consider instrument id or not | +| `use_command_state` | bool | `false` | Consider command state or not | | `instrument_id` | string | `` | Used as command id | | `approval` | bool | `false` | set approval filed to ros param | | `is_finalized` | bool | `false` | Stop at stop_line if finalization isn't completed | diff --git a/system/dummy_infrastructure/config/dummy_infrastructure.param.yaml b/system/dummy_infrastructure/config/dummy_infrastructure.param.yaml index 50dc36193776b..83976798d30b2 100644 --- a/system/dummy_infrastructure/config/dummy_infrastructure.param.yaml +++ b/system/dummy_infrastructure/config/dummy_infrastructure.param.yaml @@ -1,8 +1,8 @@ /**: ros__parameters: update_rate_hz: 10.0 - use_first_command: false - use_command_state: true - instrument_id: '0' - approval: true - is_finalized: true + use_first_command: true + use_command_state: false + instrument_id: "" + approval: false + is_finalized: false diff --git a/system/dummy_infrastructure/launch/dummy_infrastructure.launch.xml b/system/dummy_infrastructure/launch/dummy_infrastructure.launch.xml index 751575e343fa6..bc45abdebec70 100644 --- a/system/dummy_infrastructure/launch/dummy_infrastructure.launch.xml +++ b/system/dummy_infrastructure/launch/dummy_infrastructure.launch.xml @@ -1,3 +1,4 @@ + diff --git a/system/dummy_infrastructure/schema/dummy_infrastructure_node.schema.json b/system/dummy_infrastructure/schema/dummy_infrastructure_node.schema.json new file mode 100644 index 0000000000000..697ec01d31a64 --- /dev/null +++ b/system/dummy_infrastructure/schema/dummy_infrastructure_node.schema.json @@ -0,0 +1,65 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "Parameters for Dummy Infrastructure Node", + "type": "object", + "definitions": { + "dummy_infrastructure": { + "type": "object", + "properties": { + "update_rate_hz": { + "type": "number", + "default": "10.0", + "description": "Timer callback period [Hz]" + }, + "use_first_command": { + "type": "boolean", + "default": "true", + "description": "Consider instrument id or not" + }, + "use_command_state": { + "type": "boolean", + "default": "false", + "description": "Consider command state or not" + }, + "instrument_id": { + "type": "string", + "default": "", + "description": "Used as command id" + }, + "approval": { + "type": "boolean", + "default": "false", + "description": "set approval filed to ros param" + }, + "is_finalized": { + "type": "boolean", + "default": "false", + "description": "Stop at stop_line if finalization isn't completed" + } + }, + "required": [ + "update_rate_hz", + "use_first_command", + "use_command_state", + "instrument_id", + "approval", + "is_finalized" + ], + "additionalProperties": false + } + }, + "properties": { + "/**": { + "type": "object", + "properties": { + "ros__parameters": { + "$ref": "#/definitions/dummy_infrastructure" + } + }, + "required": ["ros__parameters"], + "additionalProperties": false + } + }, + "required": ["/**"], + "additionalProperties": false +} diff --git a/system/dummy_infrastructure/src/dummy_infrastructure_node/dummy_infrastructure_node.cpp b/system/dummy_infrastructure/src/dummy_infrastructure_node/dummy_infrastructure_node.cpp index f24ce4587de0b..485d85c926268 100644 --- a/system/dummy_infrastructure/src/dummy_infrastructure_node/dummy_infrastructure_node.cpp +++ b/system/dummy_infrastructure/src/dummy_infrastructure_node/dummy_infrastructure_node.cpp @@ -89,12 +89,12 @@ DummyInfrastructureNode::DummyInfrastructureNode(const rclcpp::NodeOptions & nod this->add_on_set_parameters_callback(std::bind(&DummyInfrastructureNode::onSetParam, this, _1)); // Parameter - node_param_.update_rate_hz = declare_parameter("update_rate_hz", 10.0); - node_param_.use_first_command = declare_parameter("use_first_command", true); - node_param_.use_command_state = declare_parameter("use_command_state", false); - node_param_.instrument_id = declare_parameter("instrument_id", ""); - node_param_.approval = declare_parameter("approval", false); - node_param_.is_finalized = declare_parameter("is_finalized", false); + node_param_.update_rate_hz = declare_parameter("update_rate_hz"); + node_param_.use_first_command = declare_parameter("use_first_command"); + node_param_.use_command_state = declare_parameter("use_command_state"); + node_param_.instrument_id = declare_parameter("instrument_id"); + node_param_.approval = declare_parameter("approval"); + node_param_.is_finalized = declare_parameter("is_finalized"); // Subscriber sub_command_array_ = create_subscription(