Browse Source

Initial code

master
Lukas Bachschwell 1 year ago
parent
commit
f5818f33dd
3 changed files with 101 additions and 0 deletions
  1. +68
    -0
      index.js
  2. +19
    -0
      package-lock.json
  3. +14
    -0
      package.json

+ 68
- 0
index.js 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
- 0
package-lock.json 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
- 0
package.json 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"
}
}

Loading…
Cancel
Save