robotrack.php3 8.58 KB
Newer Older
1 2
<?php
#
3
# Copyright (c) 2000-2013 University of Utah and the Flux Group.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
# 
# {{{EMULAB-LICENSE
# 
# This file is part of the Emulab network testbed software.
# 
# This file is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
# 
# This file is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public
# License for more details.
# 
# You should have received a copy of the GNU Affero General Public License
# along with this file.  If not, see <http://www.gnu.org/licenses/>.
# 
# }}}
23 24 25 26
#
chdir("..");
include("defs.php3");

27 28 29 30
$this_user = CheckLoginOrDie();
$uid       = $this_user->uid();
$isadmin   = ISADMIN();

31 32 33 34 35 36 37 38 39
$optargs = OptionalPageArguments("building",    PAGEARG_STRING,
				 "floor",       PAGEARG_STRING,
				 "experiment",  PAGEARG_EXPERIMENT,
				 "camheight",   PAGEARG_INTEGER,
				 "camwidth",    PAGEARG_INTEGER,
				 "camfps",      PAGEARG_INTEGER,
				 "camera",      PAGEARG_INTEGER,
				 "withwebcams", PAGEARG_BOOLEAN);

40 41 42 43 44
#
# Optional pid,eid. Without a building/floor, show all the nodes for the
# experiment in all buildings/floors. Without pid,eid show all wireless
# nodes in the specified building/floor.
#
45 46 47
if (isset($experiment)) {
    if (!$experiment->AccessCheck($this_user, $TB_EXPT_READINFO)) {
	USERERROR("You do not have permission to view this experiment!", 1);
48
    }
Leigh B. Stoller's avatar
Leigh B. Stoller committed
49 50
    $pid = $experiment->pid();
    $eid = $experiment->eid();
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
}
else {
    #
    # Else, we need to find whatever experiment is running. What if there
    # is more then one? Good question; I do not have a plan for that yet!
    #
    $query_result =
	DBQueryFatal("select pid,eid from experiments ".
		     "where locpiper_pid!=0 and locpiper_port!=0");
    if (mysql_num_rows($query_result)) {
	$row = mysql_fetch_array($query_result);
	$pid = $row["pid"];
	$eid = $row["eid"];
    }
    else {
	unset($pid);
	unset($eid);
    }
}

71
#
72
# Verify page arguments. Allow user to optionally specify building/floor.
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
#
if (isset($building) && $building != "") {
    # Sanitize for the shell.
    if (!preg_match("/^[-\w]+$/", $building)) {
	PAGEARGERROR("Invalid building argument.");
    }
    # Optional floor argument. Sanitize for the shell.
    if (isset($floor) && !preg_match("/^[-\w]+$/", $floor)) {
	PAGEARGERROR("Invalid floor argument.");
    }
}
else {
    $building = "MEB-ROBOTS";
    $floor    = 4;
}
Leigh B. Stoller's avatar
Leigh B. Stoller committed
88 89 90 91 92 93 94 95 96 97 98 99
$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"];
}
100 101 102
else {
    USERERROR("No such building/floor $building/$floor", 1);
}
103

104 105 106 107 108 109 110 111 112 113 114 115 116
#
# Some stuff to control the camera.
#
if (! isset($camheight) || !TBvalid_integer($camheight)) {
    $camheight = 180;
}
if (! isset($camwidth) || !TBvalid_integer($camwidth)) {
    $camwidth = 240;
}
if (! isset($camfps) || !TBvalid_integer($camfps)) {
    $camfps = 2;
}

117 118 119 120 121
#
# If adding in the webcams, get that stuff too.
#
$webcams = array();

122
if (isset($withwebcams) && $withwebcams) {
123 124 125 126 127 128
    if (isset($camera) && TBvalid_integer($camera)) {
	$query_result = DBQueryFatal("select * from webcams ".
				     "where id='$camera'");
    }
    else 
	$query_result = DBQueryFatal("select * from webcams");
129

130 131 132 133 134
    while ($row = mysql_fetch_array($query_result)) {
	$id      = $row["id"];
	$camurl  = "../webcamimg.php3?webcamid=${id}&applet=1&fromtracker=1";
	$webcams[] = $camurl;
    }
135 136
}

137 138 139 140 141
#
# Standard Testbed Header
#
PAGEHEADER("Real Time Robot Tracking Applet");

Leigh B. Stoller's avatar
Tweaks.  
Leigh B. Stoller committed
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
#
# Draw the legend and some explanatory text.
#
echo "<table cellspacing=5 cellpadding=5 border=0 class=\"stealth\">
      <tr>
       <td align=\"left\" valign=\"top\" class=\"stealth\">
         <table>
           <tr><th colspan=2>Legend</th></tr>
           <tr>
             <td><img src=\"../floormap/map_legend_node.gif\"></td>
             <td nowrap=1>Robot Actual Position</td>
           </tr>
           <tr>
             <td><img src=\"../floormap/map_legend_node_dst.gif\"></td>
             <td nowrap=1>Robot Destination Position</td>
           </tr>
         </table>
       </td>
       <td class=stealth>This applet allows you to view the robots
161 162
                         as they move around, as well as move the robots
                         with drag and drop. The table at the bottom
Leigh B. Stoller's avatar
Tweaks.  
Leigh B. Stoller committed
163
                         shows the current position (x, y, orientation),
Leigh B. Stoller's avatar
Leigh B. Stoller committed
164
                         the destination position,
Leigh B. Stoller's avatar
Tweaks.  
Leigh B. Stoller committed
165
                         and the battery level (percentage and voltage).
166
                         The shaded areas are <em>exclusion</em>
Leigh B. Stoller's avatar
Leigh B. Stoller committed
167
                         zones where robots are not allowed to go. You can
168 169
                         <b>right click</b> on a robot to bring up its
                         info page. See below for instructions on how to
170 171 172 173
                         use the <b>drag and drop</b> features. If you are on
                         a <b>high speed</b> connection, you can try the
                         <a href=${REQUEST_URI}&withwebcams=1>WithWebCams</a>
                         option.
Leigh B. Stoller's avatar
Tweaks.  
Leigh B. Stoller committed
174 175 176 177
        </td>
      </tr>
      </table><hr>\n";

178 179 180 181 182 183 184 185 186 187 188 189 190 191
#
# Create a tempfile to use as a unique prefix; it is not actually used but
# serves the same purpose (The script uses ${prefix}.jpg and ${prefix}.map .)
# 
$prefix = tempnam("/tmp", "floormap");

#
# Get the unique part to send back.
#
if (!preg_match("/^\/tmp\/([-\w]+)$/", $prefix, $matches)) {
    TBERROR("Bad tempnam: $prefix", 1);
}
$uniqueid = $matches[1];

192
$perl_args = "-o $prefix -t -z -n -x -v -y -f $floor $building";
193 194 195 196 197 198 199 200 201 202

$retval = SUEXEC($uid, "nobody", "webfloormap $perl_args",
		 SUEXEC_ACTION_IGNORE);

if ($retval) {
    SUEXECERROR(SUEXEC_ACTION_USERERROR);
    # Never returns.
    die("");
}

203
$auth    = $_COOKIE[$TBAUTHCOOKIE];
204
$pipeurl = "robopipe.php3?building=$building&floor=$floor";
205 206 207
$baseurl = "../floormap_aux.php3?prefix=$uniqueid";

# Temp for debugging.
Leigh B. Stoller's avatar
Leigh B. Stoller committed
208
if (isset($fake))
209 210 211 212
    $pipeurl .= "&fake=yes";
if (isset($pid) && isset($eid)) {
    $pipeurl .= "&pid=$pid&eid=$eid";
}
213
     
214
echo "<applet name='tracker' code='RoboTrack.class'
215
              archive='tracker.jar'
216
              width='1025' height='1150'
217 218
              alt='You need java to run this applet'>
            <param name='pipeurl' value='$pipeurl'>
219
            <param name='floorurl' value='$baseurl'>
220 221
            <param name='uid' value='$uid'>
            <param name='auth' value='$auth'>
Leigh B. Stoller's avatar
Leigh B. Stoller committed
222
            <param name='ppm' value='$ppm'>
223
            <param name='building' value='$building'>
224 225
            <param name='floor' value='$floor'>";
if (count($webcams)) {
226 227 228 229
    echo "<param name='WebCamHeight' value=$camheight>
          <param name='WebCamWidth' value=$camwidth>
          <param name='WebCamFPS' value=$camfps>\n";
    
230 231 232 233 234 235 236 237 238 239 240 241
    $camcount = count($webcams);
    $x = 400;
    $y = 460;
    
    echo "<param name='WebCamCount' value='$camcount'>";

    for ($i = 0; $i < $camcount; $i++) {
	$camurl = $webcams[$i];

	echo "<param name='WebCam${i}' value='$camurl'>
              <param name='WebCam${i}XY' value='$x,$y'>";

242
	$x += ($camwidth + 20);
243 244 245

	if ($x > 700) {
	    $x = 400;
246
	    $y = $y + ($camheight + 20);
247 248 249 250
	}
    }
}
echo "</applet>\n";
251

Leigh B. Stoller's avatar
Leigh B. Stoller committed
252
echo "<br>
253
     <blockquote><blockquote>
Leigh B. Stoller's avatar
Leigh B. Stoller committed
254 255
     <center>
     <h3>Using the Robot Tracker Applet</h3>
256
     </center>
Leigh B. Stoller's avatar
Leigh B. Stoller committed
257 258 259 260 261 262 263 264
     <ul>
     <li> Right Click over a robot or mote will pop up a browser window 
          showing information about the robot/mote.
     <li> Left click and drag over a (stationary) robot allows you to setup a
          move to a new position. Remember to edit the orientation in the
          table, if needed. Cancel by moving back to its original position. 
     <li> Left click over the background image brings up a menu to submit your 
          moves (start the robots on their way), or cancel the moves.
265 266
     <li> Only one move per robot at a time.
     <li> To change just the orientation (no drag), edit the destination
267 268 269
          orientation column in the table.
     <li> A robot destination must not overlap an obstacle (shaded area,
          blue border), and it must be fully within the field of view of at
270 271 272 273
          least one camera (orange boxes).
     <li> A robot destination must not overlap with another robot (its final
          destination). Because of the sensors on the robots, the closest a
          robot can come to anything else is 23cm.
274 275
     </ul>
     <blockquote><blockquote>\n";
276

277 278
PAGEFOOTER();
?>