Skip to content

Conversation

minggangw
Copy link
Member

@minggangw minggangw commented Aug 29, 2025

This PR adds comprehensive examples demonstrating client/service patterns using the nav_msgs/srv/GetMap service type, which is commonly used in robotics for retrieving occupancy grid map data. The examples complement the existing AddTwoInts service examples by showing how to work with more complex message types.

  • Adds GetMap service server example that provides sample occupancy grid data
  • Adds GetMap client example that requests and analyzes map data with visualization
  • Updates documentation with detailed usage instructions and explanations

Fix: #1246

@Copilot Copilot AI review requested due to automatic review settings August 29, 2025 15:32
Copy link

@Copilot 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 comprehensive examples demonstrating client/service patterns using the nav_msgs/srv/GetMap service type, which is commonly used in robotics for retrieving occupancy grid map data. The examples complement the existing AddTwoInts service examples by showing how to work with more complex message types.

  • Adds GetMap service server example that provides sample occupancy grid data
  • Adds GetMap client example that requests and analyzes map data with visualization
  • Updates documentation with detailed usage instructions and explanations

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
example/services/service/getmap-service-example.js Service server that provides sample 10x10 occupancy grid map data with obstacles
example/services/client/getmap-client-example.js Service client that requests map data and displays comprehensive analysis with ASCII visualization
example/services/README.md Updated documentation with GetMap examples, usage instructions, and explanations of complex message types

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +30 to +32
mapData[22] = 100; // obstacle at position (2,2)
mapData[33] = 100; // obstacle at position (3,3)
mapData[44] = 100; // obstacle at position (4,4)
Copy link

Copilot AI Aug 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The magic numbers 22, 33, 44 should be calculated using the formula y * mapWidth + x for clarity. For example: mapData[2 * mapWidth + 2] = 100; // obstacle at position (2,2)

Suggested change
mapData[22] = 100; // obstacle at position (2,2)
mapData[33] = 100; // obstacle at position (3,3)
mapData[44] = 100; // obstacle at position (4,4)
mapData[2 * mapWidth + 2] = 100; // obstacle at position (2,2)
mapData[3 * mapWidth + 3] = 100; // obstacle at position (3,3)
mapData[4 * mapWidth + 4] = 100; // obstacle at position (4,4)

Copilot uses AI. Check for mistakes.

Comment on lines +34 to +46
const sampleMapResponse = {
map: {
header: {
stamp: {
sec: Math.floor(Date.now() / 1000),
nanosec: (Date.now() % 1000) * 1000000,
},
frame_id: 'map',
},
info: {
map_load_time: {
sec: Math.floor(Date.now() / 1000),
nanosec: (Date.now() % 1000) * 1000000,
Copy link

Copilot AI Aug 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Date.now() is called twice which could result in inconsistent timestamps. Store the value in a variable: const now = Date.now(); sec: Math.floor(now / 1000), nanosec: (now % 1000) * 1000000

Suggested change
const sampleMapResponse = {
map: {
header: {
stamp: {
sec: Math.floor(Date.now() / 1000),
nanosec: (Date.now() % 1000) * 1000000,
},
frame_id: 'map',
},
info: {
map_load_time: {
sec: Math.floor(Date.now() / 1000),
nanosec: (Date.now() % 1000) * 1000000,
const now = Date.now();
const sampleMapResponse = {
map: {
header: {
stamp: {
sec: Math.floor(now / 1000),
nanosec: (now % 1000) * 1000000,
},
frame_id: 'map',
},
info: {
map_load_time: {
sec: Math.floor(now / 1000),
nanosec: (now % 1000) * 1000000,

Copilot uses AI. Check for mistakes.

Comment on lines +34 to +46
const sampleMapResponse = {
map: {
header: {
stamp: {
sec: Math.floor(Date.now() / 1000),
nanosec: (Date.now() % 1000) * 1000000,
},
frame_id: 'map',
},
info: {
map_load_time: {
sec: Math.floor(Date.now() / 1000),
nanosec: (Date.now() % 1000) * 1000000,
Copy link

Copilot AI Aug 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Date.now() is called twice again, similar to the header timestamp. This should use the same timestamp value for consistency within the same response.

Suggested change
const sampleMapResponse = {
map: {
header: {
stamp: {
sec: Math.floor(Date.now() / 1000),
nanosec: (Date.now() % 1000) * 1000000,
},
frame_id: 'map',
},
info: {
map_load_time: {
sec: Math.floor(Date.now() / 1000),
nanosec: (Date.now() % 1000) * 1000000,
const now = Date.now();
const sampleMapResponse = {
map: {
header: {
stamp: {
sec: Math.floor(now / 1000),
nanosec: (now % 1000) * 1000000,
},
frame_id: 'map',
},
info: {
map_load_time: {
sec: Math.floor(now / 1000),
nanosec: (now % 1000) * 1000000,

Copilot uses AI. Check for mistakes.

@coveralls
Copy link

Coverage Status

coverage: 84.555%. remained the same
when pulling 2275d4e on minggangw:fix-1246
into d9a0440 on RobotWebTools:develop.

@minggangw minggangw merged commit 1b99138 into RobotWebTools:develop Sep 1, 2025
19 checks passed
minggangw added a commit that referenced this pull request Sep 10, 2025
This PR adds comprehensive examples demonstrating client/service patterns using the `nav_msgs/srv/GetMap` service type, which is commonly used in robotics for retrieving occupancy grid map data. The examples complement the existing AddTwoInts service examples by showing how to work with more complex message types.

- Adds GetMap service server example that provides sample occupancy grid data
- Adds GetMap client example that requests and analyzes map data with visualization
- Updates documentation with detailed usage instructions and explanations

Fix: #1246
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.

Add client/service example using nav_msgs/srv/GetMap

2 participants