Skip to content
This repository has been archived by the owner on Jul 1, 2018. It is now read-only.

WIP: Field control interface #130

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions angel-player/src/chrome/content/debug-main.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

<html>
<body>
<div style="width:600px;height:600px;">
<a href="blockeditor/blockeditor.html">Block Editor</a>
<a href="tenshi-frontend/main.html">IDE</a>
<a href="simulator/main.html">Simulator</a>
Expand All @@ -10,5 +11,7 @@
<a href="angelic/test.html">Angelic Test Page</a>
<a href="chrome://global/content/config.xul">about:config</a>
<a href="widget/widget.html">Widgets</a>
<a href="supervisor/supervisor.html">Supervisory Control</a>
</div>
</body>
</html>
10 changes: 10 additions & 0 deletions angel-player/src/chrome/content/main-ui/ui.css
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,13 @@ body {
.module-div {
display: none;
}

#stargate-div {
width: 100%;
height: 100%;
}

#stargate-iframe {
width: 100%;
height: 100%;
}
4 changes: 2 additions & 2 deletions angel-player/src/chrome/content/main-ui/ui.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
<!--Added dynamically-->
</div>
</div>
<div id="mainContent">
<div id="mainContent" style="width:100%; height:100%;">
<div ng-include id="welcome-div" class="module-div"
src="'../welcome/welcome.html'">
</div>
Expand Down Expand Up @@ -71,7 +71,7 @@
</div>

<div id="stargate-div" class="module-div">
<iframe src="../debug-main.html"></iframe>
<iframe src="../debug-main.html" id="stargate-iframe"></iframe>
</div>
</div>
</body>
Expand Down
19 changes: 19 additions & 0 deletions angel-player/src/chrome/content/supervisor/supervisor.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<html>
<head>
<script src="../vendor-js/jquery.js">
</script>
<script src="../common/lcm_ws_bridge.js">
</script>
<script src="supervisor.js">
</script>
</head>
<body>
<div id="seq">
</div>
<div id="main">
</div>
<div>
Hello, world
</div>
</body>
</html>
95 changes: 95 additions & 0 deletions angel-player/src/chrome/content/supervisor/supervisor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*
Supervisor: interface to field control

PUBLIC API:

new Supervisor([station_number, [websocket_url]])
station_number: one of [0, 1, 2, 3]. Defaults to 0
websocket_url: defaults to "ws://localhost:8000"
connect()
automatically called when the Supervisor is created
disconnect()

TODO: figure out what public API to expose to the rest of the app
*/

function proxy (fn, context) {
// Poor man's version of jQuery.proxy
// Binds the "this" inside fn to the specified context
return function () {
return fn.apply(context, arguments);
};
}

function Supervisor (station_number, ws_uri) {
this.station_number = station_number;
this.ws_uri = ws_uri;
if (ws_uri === undefined) {
this.ws_uri = "ws://localhost:8000";
}
if (station_number === undefined) {
this.station_number = 0;
}
this.lcm = null;
this.cmd_sub = "";
this.config_sub = "";
this.disconnect();
this.connect();
}

Supervisor.prototype.connect = function() {
var self = this;
this.lcm = new LCM("ws://localhost:8000");
this.lcm.on_ready(function() {
self.cmd_sub = self.lcm.subscribe(
"piemos" + self.station_number + "/cmd",
"piemos_cmd",
proxy(self._handle_cmd, self));
self.cmd_sub = self.lcm.subscribe(
"PiEMOS" + self.station_number + "/Config",
"ConfigData",
proxy(self._handle_config, self));
});
};

Supervisor.prototype.disconnect = function() {
if (this.lcm !== null) {
this.lcm.unsubscribe(this.cmd_sub);
this.lcm.unsubscribe(this.config_sub);
this.cmd_sub = "";
this.config_sub = "";
this.lcm = null;
}
};

Supervisor.prototype._handle_cmd = function(msg) {
// Message format:
// {
// enabled: bool,
// is_blue: bool,
// auton: bool,
// game_time: int (seconds),
// }

console.log("Got state from field control");
};

Supervisor.prototype._handle_config = function(msg) {
// Message format:
// {
// IsBlue: bool,
// TeamName: string,
// TeamNumber: int
// ...
// }

// Field control still passes PiEMOS configs
// Here is how to extract the radio address from the config:
this.radio_address = JSON.parse(msg.ConfigFile).radioAddress;
console.log("Got config from field control: " + this.radio_address);
};

// Exports for running in a CommonJS environment
if (typeof require !== "undefined") {
exports.Supervisor = Supervisor;
}
3 changes: 0 additions & 3 deletions angel-player/src/chrome/content/welcome/welcome.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
body {
background-image: url("assets/Angel_player.jpg");
background-size: cover;
background-repeat: no-repeat;
}

input:invalid {
Expand Down