-
Notifications
You must be signed in to change notification settings - Fork 78
Add client/service example using nav_msgs/srv/GetMap #1247
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 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.
mapData[22] = 100; // obstacle at position (2,2) | ||
mapData[33] = 100; // obstacle at position (3,3) | ||
mapData[44] = 100; // obstacle at position (4,4) |
Copilot
AI
Aug 29, 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 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)
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.
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, |
Copilot
AI
Aug 29, 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.
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
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.
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, |
Copilot
AI
Aug 29, 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.
Date.now() is called twice again, similar to the header timestamp. This should use the same timestamp value for consistency within the same response.
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.
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
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.Fix: #1246