-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
79 lines (58 loc) · 1.5 KB
/
server.js
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
const serialPath = '/dev/tty.usbserial-00000000'
var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);
var Sylvester = require('sylvester');
var Kalman = require('kalman').KF;
const SerialPort = require('serialport');
const parsers = SerialPort.parsers;
const parser = new parsers.Readline({
delimiter: '\r\n'
});
const port = new SerialPort(serialPath, {
baudRate: 9600
});
port.pipe(parser);
var GPS = require('gps');
var gps = new GPS;
// Simple Kalman Filter set up
var A = Sylvester.Matrix.I(2);
var B = Sylvester.Matrix.Zero(2, 2);
var H = Sylvester.Matrix.I(2);
var C = Sylvester.Matrix.I(2);
var Q = Sylvester.Matrix.I(2).multiply(1e-11);
var R = Sylvester.Matrix.I(2).multiply(0.00001);
// Measure
var u = $V([0, 0]);
var filter = new Kalman($V([0, 0]), $M([
[1, 0],
[0, 1]
]));
gps.on('data', function (data) {
if (data.lat && data.lon) {
filter.update({
A: A,
B: B,
C: C,
H: H,
R: R,
Q: Q,
u: u,
y: $V([data.lat, data.lon])
});
gps.state.position = {
cov: filter.P.elements,
pos: filter.x.elements
};
}
io.emit('position', gps.state);
});
app.get('/', function (req, res) {
res.sendFile(__dirname + '/index.html');
});
http.listen(3000, function () {
console.log('listening on port: 3000');
});
parser.on('data', function (data) {
gps.update(data);
});