Initial code

This commit is contained in:
Lukas Bachschwell 2018-05-21 13:00:25 +02:00
parent 144349a24b
commit f5818f33dd
3 changed files with 101 additions and 0 deletions

68
index.js Normal file
View File

@ -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);
}

19
package-lock.json generated Normal file
View File

@ -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="
}
}
}

14
package.json Normal file
View File

@ -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"
}
}