Merge pull request #11 from wiseman/magnetocompass
Added magnetometer calibration to pilot plugin.
Esse commit está contido em:
+36
@@ -5,6 +5,7 @@ var express = require('express')
|
|||||||
, server = require("http").createServer(app)
|
, server = require("http").createServer(app)
|
||||||
, io = require('socket.io').listen(server)
|
, io = require('socket.io').listen(server)
|
||||||
, arDrone = require('ar-drone')
|
, arDrone = require('ar-drone')
|
||||||
|
, arDroneConstants = require('ar-drone/lib/constants')
|
||||||
, config = require('./config')
|
, config = require('./config')
|
||||||
;
|
;
|
||||||
|
|
||||||
@@ -48,10 +49,23 @@ app.get('/', function (req, res) {
|
|||||||
* call 'listen' on the server, not the express app
|
* call 'listen' on the server, not the express app
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
function navdata_option_mask(c) {
|
||||||
|
return 1 << c;
|
||||||
|
}
|
||||||
|
|
||||||
|
// From the SDK.
|
||||||
|
var default_navdata_options = (
|
||||||
|
navdata_option_mask(arDroneConstants.options.DEMO) |
|
||||||
|
navdata_option_mask(arDroneConstants.options.VISION_DETECT));
|
||||||
|
|
||||||
// Connect and configure the drone
|
// Connect and configure the drone
|
||||||
var client = new arDrone.createClient();
|
var client = new arDrone.createClient();
|
||||||
client.config('general:navdata_demo', 'TRUE');
|
client.config('general:navdata_demo', 'TRUE');
|
||||||
client.config('video:video_channel', '0');
|
client.config('video:video_channel', '0');
|
||||||
|
// Enable the magnetometer data.
|
||||||
|
client.config('general:navdata_options',
|
||||||
|
default_navdata_options |
|
||||||
|
navdata_option_mask(arDroneConstants.options.MAGNETO));
|
||||||
|
|
||||||
// Add a handler on navdata updates
|
// Add a handler on navdata updates
|
||||||
var latestNavData;
|
var latestNavData;
|
||||||
@@ -59,6 +73,28 @@ client.on('navdata', function (d) {
|
|||||||
latestNavData = d;
|
latestNavData = d;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Signal landed and flying events.
|
||||||
|
client.on('landing', function () {
|
||||||
|
console.log('LANDING');
|
||||||
|
io.sockets.emit('landing');
|
||||||
|
});
|
||||||
|
client.on('landed', function () {
|
||||||
|
console.log('LANDED');
|
||||||
|
io.sockets.emit('landed');
|
||||||
|
});
|
||||||
|
client.on('takeoff', function() {
|
||||||
|
console.log('TAKEOFF');
|
||||||
|
io.sockets.emit('takeoff');
|
||||||
|
});
|
||||||
|
client.on('hovering', function() {
|
||||||
|
console.log('HOVERING');
|
||||||
|
io.sockets.emit('hovering');
|
||||||
|
});
|
||||||
|
client.on('flying', function() {
|
||||||
|
console.log('FLYING');
|
||||||
|
io.sockets.emit('flying');
|
||||||
|
});
|
||||||
|
|
||||||
// Process new websocket connection
|
// Process new websocket connection
|
||||||
io.set('log level', 1);
|
io.set('log level', 1);
|
||||||
io.sockets.on('connection', function (socket) {
|
io.sockets.on('connection', function (socket) {
|
||||||
|
|||||||
@@ -13,13 +13,13 @@
|
|||||||
// Add required UI elements
|
// Add required UI elements
|
||||||
$('#cockpit').append('<div id="compass"></div>');
|
$('#cockpit').append('<div id="compass"></div>');
|
||||||
var div = $('#compass').get(0);
|
var div = $('#compass').get(0);
|
||||||
|
|
||||||
// Listen to navdata updates
|
// Listen to navdata updates
|
||||||
var compass = this;
|
var compass = this;
|
||||||
this.cockpit.socket.on('navdata', function(data) {
|
this.cockpit.socket.on('navdata', function(data) {
|
||||||
if (!jQuery.isEmptyObject(data)) {
|
if (!jQuery.isEmptyObject(data)) {
|
||||||
requestAnimationFrame(function() {
|
requestAnimationFrame(function() {
|
||||||
compass.moveTo(data.demo.rotation.clockwise);
|
compass.moveTo(data.magneto.heading.fusionUnwrapped);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -10,6 +10,10 @@ function pilot(name, deps) {
|
|||||||
console.log("drone", cmd);
|
console.log("drone", cmd);
|
||||||
return typeof deps.client[_name = cmd.action] === "function" ? deps.client[_name]() : void 0;
|
return typeof deps.client[_name = cmd.action] === "function" ? deps.client[_name]() : void 0;
|
||||||
});
|
});
|
||||||
|
socket.on('/pilot/calibrate', function (cmd) {
|
||||||
|
console.log("calibrate", cmd);
|
||||||
|
return deps.client.calibrate(cmd.device_num);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,111 +1,133 @@
|
|||||||
PILOT_ACCELERATION = 0.08;
|
PILOT_ACCELERATION = 0.08;
|
||||||
|
|
||||||
(function(window, document) {
|
(function(window, document) {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
// Static keymap used within this module
|
// Static keymap used within this module
|
||||||
var Keymap = {
|
var Keymap = {
|
||||||
90 : {
|
90 : {
|
||||||
ev : 'move',
|
ev : 'move',
|
||||||
action : 'front'
|
action : 'front'
|
||||||
},
|
},
|
||||||
83 : {
|
83 : {
|
||||||
ev : 'move',
|
ev : 'move',
|
||||||
action : 'back'
|
action : 'back'
|
||||||
},
|
},
|
||||||
81 : {
|
81 : {
|
||||||
ev : 'move',
|
ev : 'move',
|
||||||
action : 'left'
|
action : 'left'
|
||||||
},
|
},
|
||||||
68 : {
|
68 : {
|
||||||
ev : 'move',
|
ev : 'move',
|
||||||
action : 'right'
|
action : 'right'
|
||||||
},
|
},
|
||||||
38 : {
|
38 : {
|
||||||
ev : 'move',
|
ev : 'move',
|
||||||
action : 'up'
|
action : 'up'
|
||||||
},
|
},
|
||||||
40 : {
|
40 : {
|
||||||
ev : 'move',
|
ev : 'move',
|
||||||
action : 'down'
|
action : 'down'
|
||||||
},
|
},
|
||||||
37 : {
|
37 : {
|
||||||
ev : 'move',
|
ev : 'move',
|
||||||
action : 'counterClockwise'
|
action : 'counterClockwise'
|
||||||
},
|
},
|
||||||
39 : {
|
39 : {
|
||||||
ev : 'move',
|
ev : 'move',
|
||||||
action : 'clockwise'
|
action : 'clockwise'
|
||||||
},
|
},
|
||||||
32 : {
|
32 : {
|
||||||
ev : 'drone',
|
ev : 'drone',
|
||||||
action : 'stop'
|
action : 'stop'
|
||||||
},
|
},
|
||||||
84 : {
|
84 : {
|
||||||
ev : 'drone',
|
ev : 'drone',
|
||||||
action : 'takeoff'
|
action : 'takeoff'
|
||||||
},
|
},
|
||||||
76 : {
|
76 : {
|
||||||
ev : 'drone',
|
ev : 'drone',
|
||||||
action : 'land'
|
action : 'land'
|
||||||
},
|
},
|
||||||
69 : {
|
69 : {
|
||||||
ev : 'drone',
|
ev : 'drone',
|
||||||
action : 'disableEmergency'
|
action : 'disableEmergency'
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Constructuor
|
* Constructuor
|
||||||
*/
|
*/
|
||||||
var Pilot = function Pilot(cockpit) {
|
var Pilot = function Pilot(cockpit) {
|
||||||
console.log("Loading Pilot plugin.");
|
console.log("Loading Pilot plugin.");
|
||||||
this.cockpit = cockpit;
|
this.cockpit = cockpit;
|
||||||
this.speed = 0;
|
this.speed = 0;
|
||||||
this.listen();
|
// Start with magneto calibration disabled.
|
||||||
};
|
$('#calibratemagneto').prop('disabled', true);
|
||||||
|
|
||||||
/*
|
this.listen();
|
||||||
* Register keyboard event listener
|
};
|
||||||
*/
|
|
||||||
Pilot.prototype.listen = function listen() {
|
|
||||||
var pilot = this;
|
|
||||||
$(document).keydown(function(ev) {
|
|
||||||
pilot.keyDown(ev);
|
|
||||||
});
|
|
||||||
|
|
||||||
$(document).keyup(function(ev) {
|
/*
|
||||||
pilot.keyUp(ev);
|
* Register keyboard event listener
|
||||||
});
|
*/
|
||||||
};
|
Pilot.prototype.listen = function listen() {
|
||||||
|
var pilot = this;
|
||||||
|
$(document).keydown(function(ev) {
|
||||||
|
pilot.keyDown(ev);
|
||||||
|
});
|
||||||
|
|
||||||
Pilot.prototype.keyDown = function keyDown(ev) {
|
$(document).keyup(function(ev) {
|
||||||
console.log("Keydown: " + ev.keyCode);
|
pilot.keyUp(ev);
|
||||||
if (Keymap[ev.keyCode] == null) {
|
});
|
||||||
return;
|
|
||||||
|
$('#calibratemagneto').click(function(ev) {
|
||||||
|
ev.preventDefault();
|
||||||
|
pilot.calibrate(0);
|
||||||
|
});
|
||||||
|
this.cockpit.socket.on('hovering', function() {
|
||||||
|
$('#calibratemagneto').prop('disabled', false);
|
||||||
|
});
|
||||||
|
this.cockpit.socket.on('landed', function() {
|
||||||
|
$('#calibratemagneto').prop('disabled', true);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
Pilot.prototype.keyDown = function keyDown(ev) {
|
||||||
|
console.log("Keydown: " + ev.keyCode);
|
||||||
|
if (Keymap[ev.keyCode] == null) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
var evData;
|
var evData;
|
||||||
ev.preventDefault();
|
ev.preventDefault();
|
||||||
this.speed = this.speed >= 1 ? 1 : this.speed + PILOT_ACCELERATION / (1 - this.speed);
|
this.speed = this.speed >= 1 ? 1 : this.speed + PILOT_ACCELERATION / (1 - this.speed);
|
||||||
evData = Keymap[ev.keyCode];
|
evData = Keymap[ev.keyCode];
|
||||||
this.cockpit.socket.emit("/pilot/" + evData.ev, {
|
this.cockpit.socket.emit("/pilot/" + evData.ev, {
|
||||||
action : evData.action,
|
action : evData.action,
|
||||||
speed : this.speed
|
speed : this.speed
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
Pilot.prototype.keyUp = function keyUp(ev) {
|
Pilot.prototype.keyUp = function keyUp(ev) {
|
||||||
console.log("Keyup: " + ev.keyCode);
|
console.log("Keyup: " + ev.keyCode);
|
||||||
if (Keymap[ev.keyCode] == null) {
|
if (Keymap[ev.keyCode] == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ev.preventDefault();
|
ev.preventDefault();
|
||||||
this.speed = 0;
|
this.speed = 0;
|
||||||
this.cockpit.socket.emit("/pilot/drone", {
|
this.cockpit.socket.emit("/pilot/drone", {
|
||||||
action : "stop"
|
action : "stop"
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
window.Cockpit.plugins.push(Pilot);
|
Pilot.prototype.calibrate = function calibrate(deviceNum) {
|
||||||
|
this.cockpit.socket.emit("/pilot/calibrate", {
|
||||||
|
device_num : 0
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
window.Cockpit.plugins.push(Pilot);
|
||||||
|
|
||||||
}(window, document));
|
}(window, document));
|
||||||
|
|||||||
+10
-6
@@ -21,13 +21,17 @@
|
|||||||
bottom: 0px;
|
bottom: 0px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#controls {
|
||||||
|
float: right;
|
||||||
|
}
|
||||||
|
|
||||||
#glasspane {
|
#glasspane {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
left: 0px;
|
left: 0px;
|
||||||
right: 0px;
|
right: 0px;
|
||||||
top: 0px;
|
top: 0px;
|
||||||
bottom: 0px;
|
bottom: 0px;
|
||||||
z-index: 100;
|
z-index: 100;
|
||||||
|
|
||||||
-webkit-user-select: none; // webkit (safari, chrome) browsers
|
-webkit-user-select: none; // webkit (safari, chrome) browsers
|
||||||
-moz-user-select: none; // mozilla browsers
|
-moz-user-select: none; // mozilla browsers
|
||||||
|
|||||||
+6
-3
@@ -16,9 +16,12 @@
|
|||||||
<script type="text/javascript" src="/js/cockpit.js"></script>
|
<script type="text/javascript" src="/js/cockpit.js"></script>
|
||||||
<% for(var i=0; i<scripts.length; i++) {%>
|
<% for(var i=0; i<scripts.length; i++) {%>
|
||||||
<script type="text/javascript" src="<%= scripts[i] %>"></script><% } %>
|
<script type="text/javascript" src="<%= scripts[i] %>"></script><% } %>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<div class="header-container">
|
<div class="header-container">
|
||||||
|
<span id="controls">
|
||||||
|
<input type="button" id="calibratemagneto" value="Calibrate magneto">
|
||||||
|
</span>
|
||||||
<header class="wrapper clearfix">
|
<header class="wrapper clearfix">
|
||||||
<span class="brand">WebFlight</span>
|
<span class="brand">WebFlight</span>
|
||||||
</header>
|
</header>
|
||||||
@@ -28,9 +31,9 @@
|
|||||||
<div id="glasspane">
|
<div id="glasspane">
|
||||||
<div id="cockpit">
|
<div id="cockpit">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="footer-container">
|
<div class="footer-container">
|
||||||
<footer class="wrapper">
|
<footer class="wrapper">
|
||||||
</footer>
|
</footer>
|
||||||
|
|||||||
Referência em uma Nova Issue
Bloquear um usuário