Commit 60c2dc1c authored by Leigh B. Stoller's avatar Leigh B. Stoller
Browse files

A couple fixes for Tim:

* Pass pixels_per_meter to the applet so that it can convert coords
  to meters.

* Use a float formatter thingy to format numbers as X.XX
parent 3fae12c2
...@@ -18,6 +18,7 @@ import java.io.*; ...@@ -18,6 +18,7 @@ import java.io.*;
import java.net.URL; import java.net.URL;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.net.URLConnection; import java.net.URLConnection;
import java.text.DecimalFormat;
/* /*
* Draw the floormap and put little dots on it. * Draw the floormap and put little dots on it.
...@@ -26,7 +27,9 @@ public class RoboTrack extends JApplet { ...@@ -26,7 +27,9 @@ public class RoboTrack extends JApplet {
static Map map; static Map map;
static JTable maptable; static JTable maptable;
static Image floorimage; static Image floorimage;
static double pixels_per_meter = 1.0;
boolean frozen = false; boolean frozen = false;
static final DecimalFormat FORMATTER = new DecimalFormat("0.00");
/* /*
* The connection to boss that will provide robot location info. * The connection to boss that will provide robot location info.
...@@ -46,6 +49,7 @@ public class RoboTrack extends JApplet { ...@@ -46,6 +49,7 @@ public class RoboTrack extends JApplet {
auth = this.getParameter("auth"); auth = this.getParameter("auth");
pipeurl = this.getParameter("pipeurl"); pipeurl = this.getParameter("pipeurl");
baseurl = this.getParameter("baseurl"); baseurl = this.getParameter("baseurl");
pixels_per_meter = Float.parseFloat(this.getParameter("ppm"));
// form the URL that we use to get the background image // form the URL that we use to get the background image
floorurl = new URL(urlServer, floorurl = new URL(urlServer,
...@@ -142,13 +146,22 @@ public class RoboTrack extends JApplet { ...@@ -142,13 +146,22 @@ public class RoboTrack extends JApplet {
* A containter for coordinate information. * A containter for coordinate information.
*/ */
static class Robot { static class Robot {
int x, y; // Current x,y coords int x, y; // Current x,y coords in pixels
double or = 500.0; // Current orientation double or = 500.0; // Current orientation
int dx, dy; // Destination x,y coords int dx, dy; // Destination x,y coords in pixels
double dor = 500.0; // Destination orientation double dor = 500.0; // Destination orientation
boolean gotdest = false; // We have a valid destination boolean gotdest = false; // We have a valid destination
double battery_voltage = 500.0; /*
double battery_percentage = 500.0; * These are formatted as strings to avoid doing conversons
* on the fly when the table is redrawn. Note, we have to
* convert from pixel coords (what the server sends) to meters.
*/
String battery_voltage = "";
String battery_percentage = "";
String x_meters = "";
String y_meters = "";
String dx_meters = "";
String dy_meters = "";
String pname, vname; String pname, vname;
int index; int index;
} }
...@@ -234,6 +247,8 @@ public class RoboTrack extends JApplet { ...@@ -234,6 +247,8 @@ public class RoboTrack extends JApplet {
robbie.vname = tokens.nextToken().trim(); robbie.vname = tokens.nextToken().trim();
robbie.x = Integer.parseInt(tokens.nextToken().trim()); robbie.x = Integer.parseInt(tokens.nextToken().trim());
robbie.y = Integer.parseInt(tokens.nextToken().trim()); robbie.y = Integer.parseInt(tokens.nextToken().trim());
robbie.x_meters = FORMATTER.format(robbie.x / pixels_per_meter);
robbie.y_meters = FORMATTER.format(robbie.y / pixels_per_meter);
str = tokens.nextToken().trim(); str = tokens.nextToken().trim();
if (str.length() > 0) if (str.length() > 0)
...@@ -244,6 +259,10 @@ public class RoboTrack extends JApplet { ...@@ -244,6 +259,10 @@ public class RoboTrack extends JApplet {
robbie.dx = Integer.parseInt(str); robbie.dx = Integer.parseInt(str);
robbie.dy = Integer.parseInt(tokens.nextToken().trim()); robbie.dy = Integer.parseInt(tokens.nextToken().trim());
robbie.dor = Float.parseFloat(tokens.nextToken().trim()); robbie.dor = Float.parseFloat(tokens.nextToken().trim());
robbie.dx_meters = FORMATTER.format(robbie.dx /
pixels_per_meter);
robbie.dy_meters = FORMATTER.format(robbie.dy /
pixels_per_meter);
robbie.gotdest = true; robbie.gotdest = true;
} }
else { else {
...@@ -252,12 +271,20 @@ public class RoboTrack extends JApplet { ...@@ -252,12 +271,20 @@ public class RoboTrack extends JApplet {
str = tokens.nextToken(); str = tokens.nextToken();
} }
// Store these as strings for easy display.
str = tokens.nextToken().trim(); str = tokens.nextToken().trim();
if (str.length() > 0) if (str.length() > 0)
robbie.battery_percentage = Float.parseFloat(str); robbie.battery_percentage =
FORMATTER.format(Float.parseFloat(str));
else
robbie.battery_percentage = "";
str = tokens.nextToken().trim(); str = tokens.nextToken().trim();
if (str.length() > 0) if (str.length() > 0)
robbie.battery_voltage = Float.parseFloat(str); robbie.battery_voltage =
FORMATTER.format(Float.parseFloat(str));
else
robbie.battery_voltage = "";
} }
/* /*
...@@ -462,16 +489,14 @@ public class RoboTrack extends JApplet { ...@@ -462,16 +489,14 @@ public class RoboTrack extends JApplet {
switch (col) { switch (col) {
case 0: return robbie.pname; case 0: return robbie.pname;
case 1: return robbie.vname; case 1: return robbie.vname;
case 2: return "" + robbie.x; case 2: return robbie.x_meters;
case 3: return "" + robbie.y; case 3: return robbie.y_meters;
case 4: return (robbie.or != 500.0 ? "" + robbie.or : ""); case 4: return (robbie.or != 500.0 ? "" + robbie.or : "");
case 5: return (robbie.gotdest ? "" + robbie.dx : ""); case 5: return (robbie.gotdest ? robbie.dx_meters : "");
case 6: return (robbie.gotdest ? "" + robbie.dy : ""); case 6: return (robbie.gotdest ? robbie.dy_meters : "");
case 7: return (robbie.dor != 500.0 ? "" + robbie.dor : ""); case 7: return (robbie.dor != 500.0 ? "" + robbie.dor : "");
case 8: return (robbie.battery_percentage != 500.0 ? case 8: return robbie.battery_percentage;
"" + robbie.battery_percentage : ""); case 9: return robbie.battery_voltage;
case 9: return (robbie.battery_voltage != 500.0 ?
"" + robbie.battery_voltage : "");
} }
return "Foo"; return "Foo";
} }
......
...@@ -35,7 +35,7 @@ function SPEWCLEANUP() ...@@ -35,7 +35,7 @@ function SPEWCLEANUP()
} }
register_shutdown_function("SPEWCLEANUP"); register_shutdown_function("SPEWCLEANUP");
if (!isset($real)) { if (isset($fake)) {
# #
# Just loop forever writing out some stuff. # Just loop forever writing out some stuff.
# #
......
...@@ -17,6 +17,18 @@ PAGEHEADER("Real Time Robot Tracking Applet"); ...@@ -17,6 +17,18 @@ PAGEHEADER("Real Time Robot Tracking Applet");
# #
$building = "MEB-ROBOTS"; $building = "MEB-ROBOTS";
$floor = 4; $floor = 4;
$ppm = 1;
#
# Grab pixel_per_meters for above map.
#
$query_result =
DBQueryFatal("select pixels_per_meter from floorimages ".
"where building='$building' and floor='$floor'");
if (mysql_num_rows($query_result)) {
$row = mysql_fetch_array($query_result);
$ppm = $row["pixels_per_meter"];
}
# #
# Create a tempfile to use as a unique prefix; it is not actually used but # Create a tempfile to use as a unique prefix; it is not actually used but
...@@ -48,8 +60,8 @@ $pipeurl = "robopipe.php3?foo=bar"; ...@@ -48,8 +60,8 @@ $pipeurl = "robopipe.php3?foo=bar";
$baseurl = "../floormap_aux.php3?prefix=$uniqueid"; $baseurl = "../floormap_aux.php3?prefix=$uniqueid";
# Temp for debugging. # Temp for debugging.
if (isset($real)) if (isset($fake))
$pipeurl .= "&real=yes"; $pipeurl .= "&fake=yes";
echo "<applet code='RoboTrack.class' echo "<applet code='RoboTrack.class'
archive='tracker.jar' archive='tracker.jar'
...@@ -59,6 +71,7 @@ echo "<applet code='RoboTrack.class' ...@@ -59,6 +71,7 @@ echo "<applet code='RoboTrack.class'
<param name='baseurl' value='$baseurl'> <param name='baseurl' value='$baseurl'>
<param name='uid' value='$uid'> <param name='uid' value='$uid'>
<param name='auth' value='$auth'> <param name='auth' value='$auth'>
<param name='ppm' value='$ppm'>
</applet>\n"; </applet>\n";
PAGEFOOTER(); PAGEFOOTER();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment