|
|
@@ -0,0 +1,68 @@ |
|
|
|
var sumo = require('node-sumo'); |
|
|
|
|
|
|
|
var drone = sumo.createClient(); |
|
|
|
var stdin = process.stdin; |
|
|
|
// without this, we would only get streams once enter is pressed |
|
|
|
stdin.setRawMode(true); |
|
|
|
stdin.resume(); |
|
|
|
stdin.setEncoding('utf8'); |
|
|
|
|
|
|
|
var isConnected = false; |
|
|
|
|
|
|
|
var speed = 25; |
|
|
|
|
|
|
|
stdin.on('data', function(key) { |
|
|
|
if (!isConnected) { |
|
|
|
console.log("Not Connected!"); |
|
|
|
} |
|
|
|
// ctrl-c ( end of text ) |
|
|
|
if (key === '\u0003') { |
|
|
|
process.exit(); |
|
|
|
} |
|
|
|
// write the key to stdout all normal like |
|
|
|
//process.stdout.write(key); |
|
|
|
if (key === 'w') { |
|
|
|
drone.forward(speed); |
|
|
|
} else if (key === 's') { |
|
|
|
drone.backward(speed); |
|
|
|
} else if (key === 'a') { |
|
|
|
drone.right(speed); |
|
|
|
} else if (key === 'd') { |
|
|
|
drone.left(speed); |
|
|
|
} else if (key === ' ') { |
|
|
|
drone.animationsHighJump(); |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
drone.on("battery", function(battery) { |
|
|
|
console.log("battery: " + battery); |
|
|
|
}); |
|
|
|
|
|
|
|
drone.connect(function() { |
|
|
|
//drone.postureJumper(); |
|
|
|
console.log("We are connected!") |
|
|
|
isConnected = true; |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
// on any data into stdin |
|
|
|
stdin.on('data', function(key) { |
|
|
|
// ctrl-c ( end of text ) |
|
|
|
if (key === '\u0003') { |
|
|
|
process.exit(); |
|
|
|
} |
|
|
|
// write the key to stdout all normal like |
|
|
|
process.stdout.write(key); |
|
|
|
}); |
|
|
|
|
|
|
|
drone.on('postureUnknown', function() { |
|
|
|
console.log('PUT ME DOWN BASTARD!!!!!!!!!!!!!!!!!!!!!'); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
function turnRight() { |
|
|
|
drone.right(50); |
|
|
|
setTimeout(function() { |
|
|
|
drone.stop(); |
|
|
|
}, 230); |
|
|
|
} |