Skip to content

Conversation

@minggangw
Copy link
Member

@minggangw minggangw commented Aug 28, 2025

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

Copilot AI review requested due to automatic review settings August 28, 2025 08:32
Copy link

Copilot AI left a 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);
Copy link

Copilot AI Aug 28, 2025

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.

Suggested change
publisher.publish(message);
publisher.publish({data: message});

Copilot uses AI. Check for mistakes.

// Create a subscriber for String messages on 'topic'
node.createSubscription('std_msgs/msg/String', 'topic', (msg) => {
console.log(`Received message: ${typeof msg}`, msg);
Copy link

Copilot AI Aug 28, 2025

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.

Suggested change
console.log(`Received message: ${typeof msg}`, msg);
console.log(`Received message: ${msg.data}`);

Copilot uses AI. Check for mistakes.
Comment on lines +190 to +191
a: BigInt(10),
b: BigInt(15),
Copy link

Copilot AI Aug 28, 2025

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.

Suggested change
a: BigInt(10),
b: BigInt(15),
a: 10,
b: 15,

Copilot uses AI. Check for mistakes.
Comment on lines +322 to +324
Received message: string Hello ROS 0
Received message: string Hello ROS 1
Received message: string Hello ROS 2
Copy link

Copilot AI Aug 28, 2025

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.

Suggested change
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

Copilot uses AI. Check for mistakes.
Comment on lines +354 to +362
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 }
Copy link

Copilot AI Aug 28, 2025

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.

Suggested change
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 }

Copilot uses AI. Check for mistakes.
@coveralls
Copy link

Coverage Status

coverage: 84.555%. remained the same
when pulling e9d9180 on minggangw:fix-1241
into 3dea196 on RobotWebTools:develop.

@minggangw minggangw merged commit d9a0440 into RobotWebTools:develop Aug 28, 2025
27 of 28 checks passed
minggangw added a commit that referenced this pull request Sep 10, 2025
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Provide tutorial about basic concepts of ROS2

2 participants