-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
63 lines (52 loc) · 1.92 KB
/
app.js
File metadata and controls
63 lines (52 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// ******************* REQUIRES ***********
var express = require('express'),
app = express(),
five = require("johnny-five"),
server = require('http').createServer(app),
io = require('socket.io').listen(server),
fpr = require("./fpr.js");
var scale = five.Fn.scale; // Useful johnny-five y = mx + b calculator
var board = new five.Board({ port: "/dev/ttyACM0" }); // Instantiates new J5 board
app.use(express.static(__dirname + '/public'));
server.listen(3000);
console.log("Listening on Port 3000...");
board.on("ready", function() {
// Declare motors
var motora = new five.Motor([3, 12]),
motorb = new five.Motor([11, 13]);
// Declare servos
var servox = new five.Servo({
pin: 10,
range: [37, 135]
}),
servoy = new five.Servo({
pin: 5,
range: [40, 115]
});
// ****************** place REPL declarations here as needed **************
this.repl.inject({
motora: new five.Motor([3, 12])
});
// *************** Listen to board sensors events here ********************
// ************ Listen for browser events here ****************************
io.sockets.on('connection', function (socket) {
socket.on('button_down', function(data) {
console.log("Button down...");
fpr.buttonChange (data.button, 'button_down');
});
socket.on('button_up', function(data) {
console.log("Button up...");
fpr.buttonChange (data.button, 'button_up');
});
socket.on('axis_change', function(data) {
if ((data.stick == 'RIGHT_STICK')) { // add this to the conditional: && !fpr.getState("gimbalLock")
console.log(data.stick, data.X, data.Y);
servox.to(scale(data.X, -1, 1, 37, 135)); // I can change this to moveGimbal
servoy.to(scale(data.Y, -1, 1, 40, 115));
}
if (data.stick == 'LEFT_STICK') {
fpr.moveRobot(data.X, -1 * data.Y, motora, motorb);
}
});
});
});