-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introducing ros2 parameters and name remapping (#576)
This PR introduces ROS2 parameter and name remapping support. Parameter Use-cases: Declare Parameters Override Declared Parameters Override Declared Parameters from yaml parameters file List Parameters Describe Parameters Get Parameters Set Parameters Set Parameters Atomically Remap Use-cases: Remap node name Remap node namespace name Remap publisher topic name Remap service name 1. Name remapping and paramter overrides w/ yaml file support is delegated to rcl api. 2. index#init() modified to accept an argv array with --ros-args commandline arguments. 3. index#createNode() accepts NodeOptions for programmatic defined parameter overrides. 4. Added parameter.js with ParameterType Parameter ParameterDescription FloatingPointRange IntegerRange 5. Added is-close module dependency for use in the FloatingPointRange class. 6. New rcl_bindings functions: getParameterOverrides() getTopic() getServiceName() 7. Node.js changes: added instance vars: _parameters _parameterDescriptors _parameterService _parameterEventPublisher init() function changes: sets up parameter-overrides optionally declares parameters from parameter-overrides starts parameterService creates parameterEventPublisher Node methods: getParameterOverrides() hasParameter() declareParameter() declareParameters() undeclareParameter() getParameter() getParameters() hasParameterDescriptor() getParameterDescriptor() getParameterDescriptors() setParameter() setParameters() setParameterAtomically() setParametersAtomically() _getNativeParameterOverrides() _valdateParameters() 8. Tests files: test-parameters.js test-parameter-service.js test-remapping.js 9. Examples: parameter-declaration-example.js parameter-override-example.js Fix #414, #415, #416, #421.
- Loading branch information
1 parent
8006534
commit 6857dd2
Showing
29 changed files
with
3,799 additions
and
38 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,5 +16,8 @@ cpplint.py | |
generated | ||
types/interfaces.d.ts | ||
dist | ||
build | ||
install | ||
log | ||
.vscode | ||
.project |
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 |
---|---|---|
|
@@ -39,6 +39,7 @@ | |
'libraries': [ | ||
'-lrcl', | ||
'-lrcutils', | ||
'-lrcl_yaml_param_parser', | ||
'-lrmw', | ||
'-lrosidl_generator_c', | ||
], | ||
|
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,50 @@ | ||
// Copyright (c) 2020 Wayne Parrott. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
'use strict'; | ||
|
||
const rclnodejs = require('../index.js'); | ||
|
||
const ParameterType = rclnodejs.Parameters.ParameterType; | ||
const Parameter = rclnodejs.Parameters.Parameter; | ||
const ParameterDescriptor = rclnodejs.Parameters.ParameterDescriptor; | ||
|
||
async function main() { | ||
await rclnodejs.init(); | ||
|
||
const node = rclnodejs.createNode('my_node'); | ||
|
||
const parameter = new Parameter( | ||
'param1', | ||
ParameterType.PARAMETER_STRING, | ||
'hello world' | ||
); | ||
const parameterDescriptor = new ParameterDescriptor( | ||
'param1', | ||
ParameterType.PARAMETER_STRING | ||
); | ||
|
||
node.declareParameter(parameter, parameterDescriptor); | ||
console.log(`Declared parameter: ${parameter.name}`); | ||
|
||
if (!node.hasParameter('param1')) { | ||
console.error(`Unable to find parameter: ${parameter.name}`); | ||
return; | ||
} | ||
|
||
console.log('Parameter details: ', node.getParameter('param1')); | ||
console.log(node.getParameterDescriptor('param1')); | ||
} | ||
|
||
main(); |
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,54 @@ | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
'use strict'; | ||
|
||
const rclnodejs = require('../index.js'); | ||
|
||
const ParameterType = rclnodejs.Parameters.ParameterType; | ||
const Parameter = rclnodejs.Parameters.Parameter; | ||
const ParameterDescriptor = rclnodejs.Parameters.ParameterDescriptor; | ||
|
||
async function main() { | ||
const NODE_NAME = 'my_node'; | ||
|
||
// commandline override of param1 | ||
const argv = ['--ros-args', '-p', NODE_NAME + ':param1:=hello ros2']; | ||
|
||
// initialize rclnodejs with commandline argv | ||
await rclnodejs.init(rclnodejs.Context.defaultContext(), argv); | ||
|
||
const node = rclnodejs.createNode(NODE_NAME); | ||
|
||
// define param | ||
const parameter = new Parameter( | ||
'param1', | ||
ParameterType.PARAMETER_STRING, | ||
'hello world' | ||
); | ||
const parameterDescriptor = new ParameterDescriptor( | ||
'param1', | ||
ParameterType.PARAMETER_STRING | ||
); | ||
|
||
// declare param1 | ||
node.declareParameter(parameter, parameterDescriptor); | ||
console.log(`Declared parameter: ${parameter.name}`); | ||
|
||
if (!node.hasParameter('param1')) { | ||
console.error(`Unable to find parameter: ${parameter.name}`); | ||
return; | ||
} | ||
|
||
console.log('Parameter overridden: ', node.getParameter('param1')); | ||
console.log(node.getParameterDescriptor('param1')); | ||
} | ||
|
||
main(); |
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
Oops, something went wrong.