Skip to content

Commit a59e624

Browse files
committed
Add team number variable, add comments, reformat.
1 parent bd62ad5 commit a59e624

File tree

2 files changed

+34
-26
lines changed

2 files changed

+34
-26
lines changed

README.md

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,19 @@
11
# First Robotics Competition Camera Dashboard
2-
32
A dedicated browser-based app for viewing the camera feed from the WPIlib Camera Server on the RoboRIO.
43

5-
Most settings are currently hard-coded.
6-
7-
- Fixed IP address.
8-
- Fixed position and size (1080p widescreen monitor preferred).
9-
- HUD crosshairs with color inversion to improve visibility.
10-
4+
# Building
5+
## Windows
6+
This project uses the [yarn](https://yarnpkg.com/en/) package manager to handle all dependencies. Simply run `yarn install` to gather all the dependencies, and run `yarn start` to test the app. To build for distribution, simply run `yarn dist` to build a single binary as well as an application installer.
117

12-
# TODO
13-
14-
- [ ] Add user setting for team number. Use to generate hostname (roboRIO-xxxx-FRC.local) or IP address (10.xx.xx.2).
15-
- [ ] Add user control to save position and size of app.
16-
- [ ] Load and restore save position and size from config file.
8+
# Notes
9+
* The team number used to connect to the robot is hard-coded and can only be changed in the "index.html" file. Simply change the 1720 number in `const TEAM_NUMBER = "1720";` to use your team's number instead. The IP address of the RoboRIO is also assumed to be "10.TE.AM.2" with the camera server being on port 1181.
10+
* The application currently uses the same width, height, and screen position everytime on startup, and is intended for 1080p screens. This can be adjusted by editing the "main.js" file and modifying the arguments passed to the BrowserWindow object creator.
11+
* The camera, when connected, is given a HUD with a simple crosshair to improve precision.
1712

1813
# License
1914
This project is licensed under the MIT License.
2015

2116
# Acknowledgements
17+
This app wouldn't be possible without the gracious professionalism exhibited by a fellow team at the Indiana Tippecanoe event. While struggling with latency in the LabView dashboard, this team advised us to use the web browser instead. That contribution evolved into the app provided here.
2218

23-
This app wouldn't be possible without the gracious professionalism exhibited by
24-
a fellow team at the Indiana Tippecanoe event. While struggling with latency
25-
in the LabView dashboard, this team advised us to use the web browser instead.
26-
That contribution evolved into the app provided here.
27-
28-
Sadly, we cannot remember which team sparked this effort with their
29-
contribution, and hope to run into them again, and give them the credit they
30-
deserve.
19+
Sadly, we cannot remember which team sparked this effort with their contribution, and hope to run into them again, and give them the credit they deserve.

index.html

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@
1212
</div>
1313
</body>
1414

15-
<!------------ START SCRIPT ------------>
15+
<!-- JavaScript scripts -->
1616
<script>
17+
/* Electron setups */
1718
const isReachable = require('is-reachable');
1819
let ipc = require("electron").ipcRenderer;
1920

2021
function init() {
22+
// Quit with the x button
2123
document.getElementById("close-button").addEventListener("click", function (e) {
2224
console.log("close");
2325
ipc.send("win.close");
@@ -30,13 +32,25 @@
3032
// }
3133
// };
3234
init();
33-
</script>
34-
<script>
35+
</script>
36+
37+
<script>
38+
/* Camera drawing setups */
39+
40+
/* Change this number to your team number! */
41+
const TEAM_NUMBER = "1720";
42+
43+
// Pad the team number for the IP address
44+
let team_num = "0".repeat(4-TEAM_NUMBER.length) + TEAM_NUMBER;
45+
let team_ip = team_num[0] + team_num[1] + "." + team_num[2] + team_num[3];
46+
47+
// The drawing plane
3548
const cameraCanvas = document.getElementById("camera-canvas");
3649
let camCtx = cameraCanvas.getContext('2d');
3750
camCtx.canvas.width = window.innerWidth;
3851
camCtx.canvas.height = window.innerHeight;
3952

53+
// Connection status. Red if not connected, green if connected.
4054
const statusIndicator = document.getElementById("status-indicator");
4155
let stCtx = statusIndicator.getContext('2d');
4256
stCtx.canvas.width = 25;
@@ -54,17 +68,21 @@
5468
height: height / 2.0,
5569
};
5670

57-
let img = new Image();
71+
let img = new Image(); // This is where the camera feed goes
5872

73+
// Used for resizing and centering the image
5974
let scale = 1;
6075
let imageX = 0;
6176
let imageY = 0;
6277

6378
let source = "";
6479

80+
// Connect to the camera
6581
(async () => {
66-
let sourceMain = "http://10.17.20.2:1181";
67-
let sourceUSB = "http://172.22.11.2:1181";
82+
let sourceMain = "http://10." + team_ip + ".2:1181"; // IP is team number dependent
83+
let sourceUSB = "http://172.22.11.2:1181"; // Always the same
84+
85+
// Wait until first contact
6886
while (true) {
6987
if (await isReachable(sourceMain)) {
7088
source = sourceMain + "/?action=stream";
@@ -77,6 +95,7 @@
7795
}
7896
setup(source);
7997

98+
// Green for go!
8099
stCtx.fillStyle = "rgb(0, 255, 0)";
81100
stCtx.fillRect(0, 0, stCtx.canvas.width, stCtx.canvas.height);
82101
})();

0 commit comments

Comments
 (0)