From 639810707ddb366f37a6254d5f9514938c785001 Mon Sep 17 00:00:00 2001 From: Jihoon Lee Date: Fri, 26 Apr 2013 18:56:46 +0900 Subject: [PATCH 1/3] Add Service based OccupancyGrid client --- src/maps/OccupancyGridSrvClient.js | 54 ++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 src/maps/OccupancyGridSrvClient.js diff --git a/src/maps/OccupancyGridSrvClient.js b/src/maps/OccupancyGridSrvClient.js new file mode 100644 index 0000000..4ca0642 --- /dev/null +++ b/src/maps/OccupancyGridSrvClient.js @@ -0,0 +1,54 @@ +/** + * @author Jihoon Lee- jihoonlee.in@gmail.com + * + * - Most Implementation is copied from OccupancyGridClient implemented by Russel Toris - rctoris@wpi.edu + */ + +/** + * A map that listens to a given occupancy grid topic. + * + * Emits the following events: + * * 'change' - there was an update or change in the map + * + * @constructor + * @param options - object with following keys: + * * ros - the ROSLIB.Ros connection handle + * * topic (optional) - the map topic to listen to + * * rootObject (optional) - the root object to add this marker to + * * continuous (optional) - if the map should be continuously loaded (e.g., for SLAM) + */ +ROS2D.OccupancyGridSrvClient = function(options) { + var that = this; + options = options || {}; + var ros = options.ros; + var service = options.service || '/static_map'; + this.continuous = options.continuous; + this.rootObject = options.rootObject || new createjs.Container(); + + // current grid that is displayed + this.currentGrid = null; + + // Setting up to the service + var rosService = new ROSLIB.Service({ + ros : ros, + name : service, + serviceType : 'nav_msgs/GetMap', + compression : 'png' + }); + + rosService.callService(new ROSLIB.ServiceRequest(),function(response) { + // check for an old map + if (that.currentGrid) { + that.rootObject.removeChild(that.currentGrid); + } + + that.currentGrid = new ROS2D.OccupancyGrid({ + message : response.map + }); + that.rootObject.addChild(that.currentGrid); + + that.emit('change',that.currentGrid.origin); + + }); +}; +ROS2D.OccupancyGridSrvClient.prototype.__proto__ = EventEmitter2.prototype; From 0ce77db8d65e9bef39005020e570934c72728af2 Mon Sep 17 00:00:00 2001 From: Jihoon Lee Date: Fri, 26 Apr 2013 20:28:29 +0900 Subject: [PATCH 2/3] Polishing --- src/maps/OccupancyGridSrvClient.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/maps/OccupancyGridSrvClient.js b/src/maps/OccupancyGridSrvClient.js index 4ca0642..eee153d 100644 --- a/src/maps/OccupancyGridSrvClient.js +++ b/src/maps/OccupancyGridSrvClient.js @@ -13,16 +13,14 @@ * @constructor * @param options - object with following keys: * * ros - the ROSLIB.Ros connection handle - * * topic (optional) - the map topic to listen to + * * service (optional) - the map topic to listen to * * rootObject (optional) - the root object to add this marker to - * * continuous (optional) - if the map should be continuously loaded (e.g., for SLAM) */ ROS2D.OccupancyGridSrvClient = function(options) { var that = this; options = options || {}; var ros = options.ros; var service = options.service || '/static_map'; - this.continuous = options.continuous; this.rootObject = options.rootObject || new createjs.Container(); // current grid that is displayed @@ -47,7 +45,7 @@ ROS2D.OccupancyGridSrvClient = function(options) { }); that.rootObject.addChild(that.currentGrid); - that.emit('change',that.currentGrid.origin); + that.emit('change'); }); }; From 1b751bf01b462aba204b0c4b538f6cf2c09b7a10 Mon Sep 17 00:00:00 2001 From: Jihoon Lee Date: Fri, 26 Apr 2013 20:29:37 +0900 Subject: [PATCH 3/3] Change notes --- src/maps/OccupancyGridSrvClient.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/maps/OccupancyGridSrvClient.js b/src/maps/OccupancyGridSrvClient.js index eee153d..b6de921 100644 --- a/src/maps/OccupancyGridSrvClient.js +++ b/src/maps/OccupancyGridSrvClient.js @@ -5,7 +5,7 @@ */ /** - * A map that listens to a given occupancy grid topic. + * A static map that receives from map_server.. * * Emits the following events: * * 'change' - there was an update or change in the map