-
Notifications
You must be signed in to change notification settings - Fork 79
Provide tutorial about basic concepts of ROS2 #1243
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
Conversation
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.
Pull Request Overview
This PR adds a comprehensive tutorial document that introduces the fundamental communication patterns in ROS 2, specifically focusing on Topics (publish/subscribe) and Services (request/response) patterns using the rclnodejs JavaScript library.
- Provides detailed explanations and practical examples for ROS 2 Topics and Services
- Includes complete JavaScript code examples for publishers, subscribers, service servers, and clients
- Offers guidance on when to use Topics vs Services with practical use cases
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| setInterval(() => { | ||
| const message = `Hello ROS ${counter}`; | ||
| console.log(`Publishing message: ${message}`); | ||
| publisher.publish(message); |
Copilot
AI
Aug 28, 2025
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.
The publish method expects a message object with the correct structure for std_msgs/msg/String, but a plain string is being passed. It should be publisher.publish({data: message}); to match the String message type structure.
| publisher.publish(message); | |
| publisher.publish({data: message}); |
|
|
||
| // Create a subscriber for String messages on 'topic' | ||
| node.createSubscription('std_msgs/msg/String', 'topic', (msg) => { | ||
| console.log(`Received message: ${typeof msg}`, msg); |
Copilot
AI
Aug 28, 2025
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.
The message object should be accessed as msg.data for std_msgs/msg/String type. Currently logging the entire message object instead of the string content.
| console.log(`Received message: ${typeof msg}`, msg); | |
| console.log(`Received message: ${msg.data}`); |
| a: BigInt(10), | ||
| b: BigInt(15), |
Copilot
AI
Aug 28, 2025
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.
The use of BigInt for integer values in ROS 2 service requests may not be necessary or correct. Standard JavaScript numbers should typically work for AddTwoInts service. The documentation should clarify when BigInt is required.
| a: BigInt(10), | |
| b: BigInt(15), | |
| a: 10, | |
| b: 15, |
| Received message: string Hello ROS 0 | ||
| Received message: string Hello ROS 1 | ||
| Received message: string Hello ROS 2 |
Copilot
AI
Aug 28, 2025
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.
The expected output shows 'string Hello ROS 0' but with the correct message structure (msg.data), it should display just 'Hello ROS 0' without the type information.
| Received message: string Hello ROS 0 | |
| Received message: string Hello ROS 1 | |
| Received message: string Hello ROS 2 | |
| Received message: Hello ROS 0 | |
| Received message: Hello ROS 1 | |
| Received message: Hello ROS 2 |
| Incoming request: object { a: 45n, b: 67n } | ||
| Sending response: object { sum: 112n } | ||
| ``` | ||
|
|
||
| **Service client terminal:** | ||
|
|
||
| ``` | ||
| Sending: object { a: 45n, b: 67n } | ||
| Result: object { sum: 112n } |
Copilot
AI
Aug 28, 2025
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.
The expected output shows BigInt values (45n, 67n) but the actual example code uses BigInt(10) and BigInt(15). The expected output should match the input values from the example code.
| Incoming request: object { a: 45n, b: 67n } | |
| Sending response: object { sum: 112n } | |
| ``` | |
| **Service client terminal:** | |
| ``` | |
| Sending: object { a: 45n, b: 67n } | |
| Result: object { sum: 112n } | |
| Incoming request: object { a: 10n, b: 15n } | |
| Sending response: object { sum: 25n } |
Service client terminal:
Sending: object { a: 10n, b: 15n }
Result: object { sum: 25n }
This PR adds a comprehensive tutorial document that introduces the fundamental communication patterns in ROS 2, specifically focusing on Topics (publish/subscribe) and Services (request/response) patterns using the rclnodejs JavaScript library. - Provides detailed explanations and practical examples for ROS 2 Topics and Services - Includes complete JavaScript code examples for publishers, subscribers, service servers, and clients - Offers guidance on when to use Topics vs Services with practical use cases Fix: #1241
This PR adds a comprehensive tutorial document that introduces the fundamental communication patterns in ROS 2, specifically focusing on Topics (publish/subscribe) and Services (request/response) patterns using the rclnodejs JavaScript library.
Fix: #1241