Skip to content
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

OccupancyGridSrvClient which uses service to receive a static map #14

Merged
merged 3 commits into from
Apr 26, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions src/maps/OccupancyGridSrvClient.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* @author Jihoon Lee- jihoonlee.in@gmail.com
*
* - Most Implementation is copied from OccupancyGridClient implemented by Russel Toris - rctoris@wpi.edu
*/

/**
* A static map that receives from map_server..
*
* 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
* * service (optional) - the map topic to listen to
* * rootObject (optional) - the root object to add this marker to
*/
ROS2D.OccupancyGridSrvClient = function(options) {
var that = this;
options = options || {};
var ros = options.ros;
var service = options.service || '/static_map';
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');

});
};
ROS2D.OccupancyGridSrvClient.prototype.__proto__ = EventEmitter2.prototype;