From f5818f33ddcb4ef62b8f014128b1322e2a8ac3d9 Mon Sep 17 00:00:00 2001 From: Lukas Bachschwell Date: Mon, 21 May 2018 13:00:25 +0200 Subject: [PATCH] Initial code --- index.js | 68 +++++++++++++++++++++++++++++++++++++++++++++++ package-lock.json | 19 +++++++++++++ package.json | 14 ++++++++++ 3 files changed, 101 insertions(+) create mode 100644 index.js create mode 100644 package-lock.json create mode 100644 package.json diff --git a/index.js b/index.js new file mode 100644 index 0000000..5380453 --- /dev/null +++ b/index.js @@ -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); +} diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..c34b8bb --- /dev/null +++ b/package-lock.json @@ -0,0 +1,19 @@ +{ + "name": "sumocontroller", + "version": "1.0.0", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "node-sumo": { + "version": "git+https://github.com/alronz/node-sumo.git#c619bd6e9e523dfa93901fba20977b9cea374aa3", + "requires": { + "through": "2.3.8" + } + }, + "through": { + "version": "2.3.8", + "resolved": "https://registry.npmjs.org/through/-/through-2.3.8.tgz", + "integrity": "sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU=" + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..6b016f8 --- /dev/null +++ b/package.json @@ -0,0 +1,14 @@ +{ + "name": "sumocontroller", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "Lukas Bachschwell", + "license": "ISC", + "dependencies": { + "node-sumo": "git+https://github.com/alronz/node-sumo.git" + } +}