From 4f4c6f167be90b1899ee3a61d1d3ac2540a2fae9 Mon Sep 17 00:00:00 2001 From: Jed Wood Date: Sat, 29 Jun 2013 17:20:53 -0700 Subject: [PATCH 1/2] add flip with 'f' key. Flips in direction of movement --- plugins/pilot/index.js | 4 ++++ plugins/pilot/public/js/pilot.js | 38 +++++++++++++++++++++++++++----- 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/plugins/pilot/index.js b/plugins/pilot/index.js index 956899e..deb93fe 100644 --- a/plugins/pilot/index.js +++ b/plugins/pilot/index.js @@ -14,6 +14,10 @@ function pilot(name, deps) { console.log("calibrate", cmd); return deps.client.calibrate(cmd.device_num); }); + socket.on('/pilot/animate', function (cmd) { + console.log("animate", cmd); + return deps.client.animate(cmd.action, 500); + }); }); }; diff --git a/plugins/pilot/public/js/pilot.js b/plugins/pilot/public/js/pilot.js index c6ba54e..f7d3827 100644 --- a/plugins/pilot/public/js/pilot.js +++ b/plugins/pilot/public/js/pilot.js @@ -10,6 +10,7 @@ PILOT_ACCELERATION = 0.04; , backward = 's' , left = 'a' , right = 'd' + , flip = 'f' ; if (options && options.keyboard === 'qwerty') { } else if (options && options.keyboard === 'azerty') { @@ -52,6 +53,10 @@ PILOT_ACCELERATION = 0.04; 69 : { ev : 'drone', action : 'disableEmergency' + }, + 70 : { + ev : 'animate', + action : 'flip' } }; Keymap[keyCodeMap[forward]] = { @@ -79,6 +84,7 @@ PILOT_ACCELERATION = 0.04; console.log("Loading Pilot plugin."); this.cockpit = cockpit; this.speed = 0; + this.moving = false; this.keys = {}; // Start with magneto calibration disabled. @@ -131,15 +137,37 @@ PILOT_ACCELERATION = 0.04; return; } ev.preventDefault(); - + var key = ev.keyCode; var cmd = Keymap[key]; + //if flip, determine which direction to flip + var regFlip = /^flip/; + if (regFlip.test(cmd.action)) { + console.log("FLIP!"); + //check for which direction to flip + switch (this.moving) { + case 'front': + cmd.action = 'flipAhead'; + break; + case 'back': + cmd.action = 'flipBehind'; + break; + case 'right': + cmd.action = 'flipRight'; + break; + default: + cmd.action = 'flipLeft'; + break; + } + + } // If a motion command, we just update the speed if (cmd.ev == "move") { + this.moving = Keymap[ev.keyCode].action; if (typeof(this.keys[key])=='undefined' || this.keys[key]===null) { this.keys[key] = PILOT_ACCELERATION; } - } + } // Else we send the command immediately else { this.cockpit.socket.emit("/pilot/" + cmd.ev, { @@ -158,7 +186,7 @@ PILOT_ACCELERATION = 0.04; return; } ev.preventDefault(); - + // Delete the key from the tracking array var key = ev.keyCode; delete this.keys[key]; @@ -176,7 +204,7 @@ PILOT_ACCELERATION = 0.04; }); } } - + /* * Triggered by a timer, check for active keys * and send the appropriate motion commands @@ -189,7 +217,7 @@ PILOT_ACCELERATION = 0.04; action : cmd.action, speed : this.keys[k] }); - + // Update the speed this.keys[k] = this.keys[k] + PILOT_ACCELERATION / (1 - this.keys[k]); this.keys[k] = Math.min(1, this.keys[k]); From a15997ba3b90343d32df6e4d5470fc04a5c28161 Mon Sep 17 00:00:00 2001 From: Jed Wood Date: Sat, 29 Jun 2013 17:50:54 -0700 Subject: [PATCH 2/2] toggle acceleration from slow to fast with 'tab' --- plugins/pilot/public/js/pilot.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/plugins/pilot/public/js/pilot.js b/plugins/pilot/public/js/pilot.js index f7d3827..f8f7fff 100644 --- a/plugins/pilot/public/js/pilot.js +++ b/plugins/pilot/public/js/pilot.js @@ -133,6 +133,12 @@ PILOT_ACCELERATION = 0.04; */ Pilot.prototype.keyDown = function keyDown(ev) { console.log("Keydown: " + ev.keyCode); + if (ev.keyCode == 9) { + PILOT_ACCELERATION = (PILOT_ACCELERATION == 0.04) ? 0.64 : 0.04; + console.log("PILOT_ACCELERATION: " + PILOT_ACCELERATION); + ev.preventDefault(); + return; + } if (Keymap[ev.keyCode] == null) { return; }