|
From: <rob...@us...> - 2009-09-02 00:54:13
|
Revision: 23624
http://personalrobots.svn.sourceforge.net/personalrobots/?rev=23624&view=rev
Author: rob_wheeler
Date: 2009-09-02 00:54:03 +0000 (Wed, 02 Sep 2009)
Log Message:
-----------
Facilitate widgets listening on multiple topics by passing the topic name
along with the message to the widget's receive function.
Make the zoom function zoom to a particular point.
Replace the robot footprint with a png of the robot.
Modified Paths:
--------------
pkg/trunk/sandbox/web/navigation_application/jslib/map_viewer.js
pkg/trunk/sandbox/web/navigation_application/templates/index.cs
pkg/trunk/sandbox/web/webui/src/webui/mod/webui/jslib/pr2_graph.js
pkg/trunk/sandbox/web/webui/src/webui/mod/webui/jslib/pr2_pb.js
pkg/trunk/sandbox/web/webui/src/webui/mod/webui/jslib/pr2_widgets.js
pkg/trunk/sandbox/web/webui/src/webui/mod/webui/jslib/ros.js
pkg/trunk/sandbox/web/webui/src/webui/mod/webui/jslib/ros_toolbar.js
Added Paths:
-----------
pkg/trunk/sandbox/web/navigation_application/images/pr2_small.png
Added: pkg/trunk/sandbox/web/navigation_application/images/pr2_small.png
===================================================================
(Binary files differ)
Property changes on: pkg/trunk/sandbox/web/navigation_application/images/pr2_small.png
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Modified: pkg/trunk/sandbox/web/navigation_application/jslib/map_viewer.js
===================================================================
--- pkg/trunk/sandbox/web/navigation_application/jslib/map_viewer.js 2009-09-02 00:28:09 UTC (rev 23623)
+++ pkg/trunk/sandbox/web/navigation_application/jslib/map_viewer.js 2009-09-02 00:54:03 UTC (rev 23624)
@@ -45,7 +45,9 @@
var MapViewer = Class.create({
initialize: function(domobj) {
this.viewer = domobj;
- this.topics = domobj.getAttribute("topic").split(',');
+ //this.topics = ['/robot_pose_visualization', '/move_base/NavfnROS/plan'];
+ //this.topics = ['/robot_pose_visualization', '/move_base/TrajectoryPlannerROS/robot_footprint'];
+ this.topics = ['/robot_pose_visualization'];
},
init: function() {
@@ -84,12 +86,15 @@
this.panning = false;
this.settingGoal = false;
this.settingPose = false;
+
+ this.robot_img = new Image();
+ this.robot_img.src = window.location.pathname + '/images/pr2_small.png';
},
handleDblClick : function(e) {
if (Event.isLeftClick(e)) {
var off = this.viewer.cumulativeOffset();
- this.zoom(-0.25,
+ this.zoom(e.ctrlKey ? 0.25 : -0.25,
Event.pointerX(e) - off.left,
Event.pointerY(e) - off.top);
}
@@ -137,31 +142,41 @@
this.panMap(-10, 0);
} else if (e.keyCode == 38) { // Up
if (e.ctrlKey)
- this.zoom(-0.25, 0, 0);
+ this.zoom(-0.25, this.dim.width/2, this.dim.height/2);
else
this.panMap(0, -10);
} else if (e.keyCode == 39) { // Right
this.panMap(10, 0);
} else if (e.keyCode == 40) { // Down
if (e.ctrlKey)
- this.zoom(0.25, 0, 0);
+ this.zoom(0.25, this.dim.width/2, this.dim.height/2);
else
this.panMap(0, 10);
}
},
zoom : function(factor, center_x, center_y) {
+ var center = this.pixelToMap([center_x, center_y]);
this.scale += factor;
+
+ var x = Math.floor(center.x / this.scale / this.sourceResolution);
+ var y = this.sourceHeight / this.scale - Math.floor(center.y / this.scale / this.sourceResolution);
+
+ this.panMap(this.dim.width/2-x, this.dim.height/2-y, false);
for (var i = 0; i < this.tiles.length; ++i) {
var tile = this.tiles[i];
tile.rescale(this.scale);
}
- this.drawRobot();
+ this.updateCanvas();
},
- panMap : function(x, y) {
- var left = parseInt(this.panner.style.left) + x;
- var top = parseInt(this.panner.style.top) + y;
+ panMap : function(x, y, relative) {
+ var left = x;
+ var top = y;
+ if (typeof(relative) != 'undefined' ? relative : true) {
+ left = parseInt(this.panner.style.left) + x;
+ top = parseInt(this.panner.style.top) + y;
+ }
if (left > 0) left = 0;
if (top > 0) top = 0;
if (left < (this.dim.width - this.sourceWidth/this.scale))
@@ -186,7 +201,7 @@
dy -= this.tilesHigh * this.tileHeight;
if (dx || dy) tile.move(dx, dy);
}
- this.drawRobot();
+ this.updateCanvas();
},
pixelToMap: function(p) {
@@ -206,10 +221,32 @@
return [x, y];
},
- drawRobot: function() {
+ updateCanvas: function() {
var ctx = this.canvas.getContext('2d');
ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
+ if (0) {
+ ctx.strokeStyle = "rgb(0, 0, 255)";
+ ctx.beginPath();
+ ctx.moveTo(this.canvas.width/2 - 5, this.canvas.height/2 - 0);
+ ctx.lineTo(this.canvas.width/2 + 5, this.canvas.height/2 - 0);
+ ctx.moveTo(this.canvas.width/2 - 0, this.canvas.height/2 - 5);
+ ctx.lineTo(this.canvas.width/2 - 0, this.canvas.height/2 + 5);
+ ctx.stroke();
+ }
+
+ if (this.robot) {
+ var coords = this.mapToPixel(this.robot);
+ ctx.save();
+ ctx.translate(coords[0], coords[1]);
+ ctx.rotate(this.robot.angle);
+ var sx = 0.65 / (this.robot_img.width * this.sourceResolution * this.scale);
+ var sy = 0.65 / (this.robot_img.height * this.sourceResolution * this.scale);
+ ctx.scale(sx, sy);
+ ctx.drawImage(this.robot_img, -this.robot_img.width / 2, -this.robot_img.height / 2);
+ ctx.restore();
+ }
+
// Draw plan
if (this.plan) {
ctx.strokeStyle = "rgb(0, 255, 0)";
@@ -238,15 +275,40 @@
}
},
- receive: function(msg) {
- var ctx = this.canvas.getContext('2d');
- ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
- if (msg.polygon) {
+ quaternionToEuler: function (q)
+ {
+ result = {'r':0.0, 'p':0.0, 'y':0.0};
+
+ var sqw = q.w * q.w;
+ var sqx = q.x * q.x;
+ var sqy = q.y * q.y;
+ var sqz = q.z * q.z;
+
+ // Roll
+ result.r = Math.atan2(2 * (q.y*q.z + q.w*q.x), sqw - sqx - sqy + sqz);
+
+ // Pitch
+ result.p = Math.asin(-2 * (q.x*q.z - q.w * q.y));
+
+ // Yaw
+ result.y = Math.atan2(2 * (q.x*q.y + q.w*q.z), sqw + sqx - sqy - sqz);
+
+ return result;
+ },
+
+ receive: function(topic, msg) {
+ if (topic == '/robot_pose_visualization') {
+ var angle = -this.quaternionToEuler(msg.pose.orientation).y;
+ this.robot = {'x': msg.pose.position.x,
+ 'y': msg.pose.position.y,
+ 'angle': angle};
+ } else if (topic == '/move_base/NavfnROS/plan') {
+ ros_debug('new plan: ' + msg.poses.length + ' poses');
+ this.plan = msg.poses;
+ } else if (topic == '/move_base/TrajectoryPlannerROS/robot_footprint') {
this.footprint = msg.polygon.points;
- } else if (msg.poses) {
- this.plan = msg.poses;
}
- this.drawRobot();
+ this.updateCanvas();
},
});
Modified: pkg/trunk/sandbox/web/navigation_application/templates/index.cs
===================================================================
--- pkg/trunk/sandbox/web/navigation_application/templates/index.cs 2009-09-02 00:28:09 UTC (rev 23623)
+++ pkg/trunk/sandbox/web/navigation_application/templates/index.cs 2009-09-02 00:54:03 UTC (rev 23624)
@@ -18,7 +18,7 @@
<table width=80% align=center>
<tr>
<td>
-<div style="position:absolute;overflow:hidden;width:80%;height:600;border:red 2px solid" objtype=MapViewer topic="/move_base/TrajectoryPlannerROS/robot_footprint,/move_base/NavfnROS/plan"></div><br>
+<div style="position:absolute;overflow:hidden;width:80%;height:600;border:2px solid" objtype=MapViewer></div><br>
</td>
</table>
Modified: pkg/trunk/sandbox/web/webui/src/webui/mod/webui/jslib/pr2_graph.js
===================================================================
--- pkg/trunk/sandbox/web/webui/src/webui/mod/webui/jslib/pr2_graph.js 2009-09-02 00:28:09 UTC (rev 23623)
+++ pkg/trunk/sandbox/web/webui/src/webui/mod/webui/jslib/pr2_graph.js 2009-09-02 00:54:03 UTC (rev 23624)
@@ -36,7 +36,7 @@
this.chart.draw(this.data, this.options);
},
- receive: function(msg) {
+ receive: function(topic, msg) {
var pbmsg = msg.status[0]
if(pbmsg.name == "Power board 0") {
if(this.data.getNumberOfRows() > 60) {
@@ -93,7 +93,7 @@
this.chart.draw(this.data, this.options);
},
- receive: function(msg) {
+ receive: function(topic, msg) {
var pbmsg = msg.status[0]
if(pbmsg.name == "Power board 0") {
if(this.data.getNumberOfRows() > 60) {
@@ -153,7 +153,7 @@
this.chart.draw(this.data, this.options);
},
- receive: function(msg) {
+ receive: function(topic, msg) {
if(this.data.getNumberOfRows() > 60) {
this.data.removeRow(0);
}
@@ -181,7 +181,7 @@
init: function() {
},
- receive: function(msg) {
+ receive: function(topic, msg) {
var pbmsg = msg.status[0]
if(pbmsg.name == "Power board 0") {
var cb0 = pbmsg.strings[1].value + " @ " + pbmsg.values[4].value.toFixed(2) + "V";
@@ -235,7 +235,7 @@
this.chart.draw(this.data, this.options);
},
- receive: function(msg) {
+ receive: function(topic, msg) {
if(msg[this.key] != null) {
var percent = 100. * parseFloat(msg[this.key]) / parseFloat(msg[this.key2]);
this.data.setValue(0, 1, percent|0);
Modified: pkg/trunk/sandbox/web/webui/src/webui/mod/webui/jslib/pr2_pb.js
===================================================================
--- pkg/trunk/sandbox/web/webui/src/webui/mod/webui/jslib/pr2_pb.js 2009-09-02 00:28:09 UTC (rev 23623)
+++ pkg/trunk/sandbox/web/webui/src/webui/mod/webui/jslib/pr2_pb.js 2009-09-02 00:54:03 UTC (rev 23624)
@@ -9,7 +9,7 @@
init: function() {
},
- receive: function(msg) {
+ receive: function(topic, msg) {
var pbmsg = msg.status[0]
if(pbmsg.name == "Power board 0") {
var state = null;
@@ -52,7 +52,7 @@
init: function() {
},
- receive: function(msg) {
+ receive: function(topic, msg) {
var pbmsg = msg.status[0]
if(pbmsg.name == "Power board 0") {
var estop_button_status = null;
@@ -112,7 +112,7 @@
init: function() {
},
- receive: function(msg) {
+ receive: function(topic, msg) {
var pbmsg = msg.status[0]
if(pbmsg.name == "Power board 0") {
var estop_button_status = null;
Modified: pkg/trunk/sandbox/web/webui/src/webui/mod/webui/jslib/pr2_widgets.js
===================================================================
--- pkg/trunk/sandbox/web/webui/src/webui/mod/webui/jslib/pr2_widgets.js 2009-09-02 00:28:09 UTC (rev 23623)
+++ pkg/trunk/sandbox/web/webui/src/webui/mod/webui/jslib/pr2_widgets.js 2009-09-02 00:54:03 UTC (rev 23624)
@@ -43,7 +43,7 @@
this.draw();
},
- receive: function(msg) {
+ receive: function(topic, msg) {
if(msg['energy_remaining'] != null) {
this.percent = Math.round(100. * parseFloat(msg['energy_remaining']) / parseFloat(msg['energy_capacity']));
if (this.percent > 100) this.percent = 100;
@@ -69,7 +69,7 @@
this.domobj.innerHTML = html;
},
- receive: function(msg) {
+ receive: function(topic, msg) {
var html = '<span style="font-size:11px;position:relative;top:-3">Circuits:</span><span>';
var states = msg['circuit_state'];
for (var i = 0; i < 3; ++i) {
@@ -100,7 +100,7 @@
init: function() {
},
- receive: function(msg) {
+ receive: function(topic, msg) {
var voltage = msg['input_voltage'];
var src;
Modified: pkg/trunk/sandbox/web/webui/src/webui/mod/webui/jslib/ros.js
===================================================================
--- pkg/trunk/sandbox/web/webui/src/webui/mod/webui/jslib/ros.js 2009-09-02 00:28:09 UTC (rev 23623)
+++ pkg/trunk/sandbox/web/webui/src/webui/mod/webui/jslib/ros.js 2009-09-02 00:54:03 UTC (rev 23624)
@@ -87,7 +87,7 @@
if(listeners) {
for(var j=0; j<listeners.length; j++) {
try {
- listeners[j].receive(msgEnv.msg);
+ listeners[j].receive(msgEnv.topic, msgEnv.msg);
} catch (e) {
ros_debug("Error with receiver.");
}
@@ -215,7 +215,7 @@
}
},
- receive: function(msg) {
+ receive: function(topic, msg) {
if(this.selector && this.selectorValue) {
if(msg[this.selector] != this.selectorValue) return;
}
@@ -260,7 +260,7 @@
init: function() {
},
- receive: function(msg) {
+ receive: function(topic, msg) {
if(!this.selector || !this.selectorValue) return;
if(this.selector && this.selectorValue) {
@@ -290,7 +290,7 @@
init: function() {
},
- receive: function(msg) {
+ receive: function(topic, msg) {
if(msg[this.key] != null) {
var percent = parseFloat(msg[this.key]) / parseFloat(msg[this.key2]);
this.domobj.innerHTML = (100. * percent).toFixed(2) + "%";
@@ -330,7 +330,7 @@
this.textdiv.appendChild(d);
},
- receive: function(msg) {
+ receive: function(topic, msg) {
this.new_message(msg);
if(this.textdiv.childNodes.length > this.maxlines) {
this.textdiv.removeChild(this.textdiv.childNodes[0]);
@@ -380,7 +380,7 @@
this.domobj.innerHTML = "";
},
- receive: function(msg) {
+ receive: function(topic, msg) {
if(msg[this.key] != null) {
var lst = msg[this.key];
var s = "";
@@ -413,7 +413,7 @@
this.domobj.innerHTML = "";
},
- receive: function(msg) {
+ receive: function(topic, msg) {
var s = "<ul>";
for(var key in msg) {
s = s + "<li>" + key + ": " + msg[key];
@@ -497,7 +497,7 @@
//c.appendChild(tn);
},
- receive: function(msg) {
+ receive: function(topic, msg) {
this.new_message(msg);
if(this.tbl.rows.length > this.maxlines) {
this.tbl.deleteRow(0);
Modified: pkg/trunk/sandbox/web/webui/src/webui/mod/webui/jslib/ros_toolbar.js
===================================================================
--- pkg/trunk/sandbox/web/webui/src/webui/mod/webui/jslib/ros_toolbar.js 2009-09-02 00:28:09 UTC (rev 23623)
+++ pkg/trunk/sandbox/web/webui/src/webui/mod/webui/jslib/ros_toolbar.js 2009-09-02 00:54:03 UTC (rev 23624)
@@ -23,7 +23,7 @@
//this.pump.service_call("status_update", []);
},
- receive: function(msg) {
+ receive: function(topic, msg) {
if(msg.taskid != this.taskid) return;
var prev_state = this.state;
@@ -81,7 +81,7 @@
this.set_state();
},
- receive: function(msg) {
+ receive: function(topic, msg) {
if(msg.taskid != this.taskid) return;
var prev_state = this.state;
@@ -138,7 +138,7 @@
this.domobj.innerHTML = "";
},
- receive: function(msg) {
+ receive: function(topic, msg) {
var s = "";
for(var i=0; i<msg.active.length; i++) {
s = s + "|" + "<a href='/webui/app/" + msg.active[i].taskid + "'>" + msg.active[i].name + "</a>";
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|