Add client/service example using nav_msgs/srv/GetMap#1247
Conversation
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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) |
| 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, |
There was a problem hiding this comment.
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, |
| 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, |
There was a problem hiding this comment.
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, |
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/GetMapservice 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