-
Notifications
You must be signed in to change notification settings - Fork 83
add new example: ros-graph-example #803
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
wayneparrott
merged 3 commits into
RobotWebTools:develop
from
wayneparrott:ros-graph-example
Jul 16, 2021
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,126 @@ | ||
| // foo | ||
|
|
||
| // Copyright (c) 2021 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'); | ||
|
|
||
| console.log( | ||
| 'This example creates the following nodes and outputs the corresponding ROS2 graph:' | ||
| ); | ||
| console.log(' publisher_node'); | ||
| console.log(' subscriber_node'); | ||
| console.log(' service_node'); | ||
| console.log(' ros_graph_display_node'); | ||
|
|
||
| rclnodejs | ||
| .init() | ||
| .then(() => { | ||
| const ns = 'ns1'; | ||
|
|
||
| let publisherNode = new rclnodejs.Node('publisher_node', ns); | ||
| publisherNode.createPublisher('std_msgs/msg/String', 'topic'); | ||
|
|
||
| let subscriberNode = new rclnodejs.Node('subscriber_node', ns); | ||
| subscriberNode.createSubscription('std_msgs/msg/String', 'topic', () => {}); | ||
|
|
||
| let serviceNode = new rclnodejs.Node('service_node', ns); | ||
| serviceNode.createService( | ||
| 'example_interfaces/srv/AddTwoInts', | ||
| 'add_two_ints', | ||
| (request, response) => { | ||
| let result = response.template; | ||
| result.sum = request.a + request.b; | ||
| response.send(result); | ||
| } | ||
| ); | ||
|
|
||
| let node = rclnodejs.createNode('ros_graph_display_node', ns); | ||
| let nodeNamesAndNameSpaces = node.getNodeNamesAndNamespaces(); | ||
|
|
||
| console.log('NODES'); | ||
| console.log(node.getNodeNames()); | ||
| console.log(nodeNamesAndNameSpaces); | ||
|
|
||
| console.log('TOPICS & TYPES'); | ||
| console.log(node.getTopicNamesAndTypes()); | ||
|
|
||
| console.log('SERVICES & TYPES'); | ||
| console.log(node.getServiceNamesAndTypes()); | ||
|
|
||
| console.log('PUBLISHERS BY NODE'); | ||
| console.log( | ||
| JSON.stringify( | ||
| nodeNamesAndNameSpaces.map((nameNs) => { | ||
| return { | ||
| node: { | ||
| name: nameNs.name, | ||
| namespace: nameNs.namespace, | ||
| }, | ||
| info: node.getPublisherNamesAndTypesByNode( | ||
| nameNs.name, | ||
| nameNs.namespace | ||
| ), | ||
| }; | ||
| }), | ||
| undefined, | ||
| ' ' | ||
| ) | ||
| ); | ||
|
|
||
| console.log('SUBSCRIPTIONS BY NODE'); | ||
| console.log( | ||
| JSON.stringify( | ||
| nodeNamesAndNameSpaces.map((nameNs) => { | ||
| return { | ||
| node: { | ||
| name: nameNs.name, | ||
| namespace: nameNs.namespace, | ||
| }, | ||
| info: node.getSubscriptionNamesAndTypesByNode( | ||
| nameNs.name, | ||
| nameNs.namespace | ||
| ), | ||
| }; | ||
| }), | ||
| undefined, | ||
| ' ' | ||
| ) | ||
| ); | ||
|
|
||
| console.log('SERVICES BY NODE'); | ||
| console.log( | ||
| JSON.stringify( | ||
| nodeNamesAndNameSpaces.map((nameNs) => { | ||
| return { | ||
| node: { | ||
| name: nameNs.name, | ||
| namespace: nameNs.namespace, | ||
| }, | ||
| info: node.getServiceNamesAndTypesByNode( | ||
| nameNs.name, | ||
| nameNs.namespace | ||
| ), | ||
| }; | ||
| }), | ||
| undefined, | ||
| ' ' | ||
| ) | ||
| ); | ||
| }) | ||
| .catch((e) => { | ||
| console.log(`Error: ${e}`); | ||
| }); | ||
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: remove these lines? Please go ahead to merge it when it's done, thanks!