Skip to content

Instantly share code, notes, and snippets.

@agrublev
Forked from bearoff/dronefly.js
Last active June 24, 2018 23:12
Show Gist options
  • Save agrublev/b3321bc797a1f942ef7004db5a3aba49 to your computer and use it in GitHub Desktop.
Save agrublev/b3321bc797a1f942ef7004db5a3aba49 to your computer and use it in GitHub Desktop.
drone FORK!
const pdrone = require('pdrone');
const drone = pdrone({id: 'mambo', debug: false});
/** Helper function */
function sleep(ms) {
return new Promise(a => setTimeout(a, ms));
}
// DIRECTIONS
// - up / down / left / right /forward /back
// distance is 0-10 in the chosen direction
// time is how long it travels in that direction
async function move(direction, distance, time) {
return new Promise(async function (resolve, reject) {
await sleep(1000);
var opts = {
roll: 0, // -100/100 negative is left positive is rogjt
pitch: 0, // -100/100 positive forward negative back
yaw: 0, // -100/100 100 yar is 90 degree rotation
gaz: 0, // -100/100, = throttle GOES UP
};
if (direction == "up") {
opts.gaz = distance * 10;
} else if (direction == "down") {
opts.gaz = distance * -10;
} else if (direction == "left") {
opts.roll = distance * -10;
} else if (direction == "right") {
opts.roll = distance * 10;
} else if (direction == "forward") {
opts.pitch = distance * 10;
} else if (direction == "back") {
opts.pitch = distance * -10;
}
drone.fly(opts);
await sleep(time * 1000);
drone.fly({
roll: 0, // -100/100 negative is left positive is rogjt
pitch: 0, // -100/100 positive forward negative back
yaw: 0, // -100/100 100 yar is 90 degree rotation
gaz: 0, // -100/100, = throttle GOES UP
});
await sleep(2000);
resolve();
});
}
drone.on('connected', async () => {
drone.takeOff();
drone.flatTrim(); // use flatTrim() everytime you want the drone to calm down
await sleep(1500);
await move("forward", 10, 1.3);
await move("back", 10, 1);
drone.flip({direction: 'left'});
await sleep(1000);
drone.flip({direction: 'right'});
await sleep(1000);
drone.safeLandingAndExit();
drone.on('sensor', function (event) {
console.log(event);
});
});
//
// drone.fly({
// roll: 0, // -100/100 negative is left positive is rogjt
// pitch: 0, // -100/100 positive forward negative back
// yaw: 0, // -100/100 100 yar is 90 degree rotation
// gaz: 100, // -100/100, = throttle GOES UP
// });
// await sleep(2000);
// drone.fly({
// roll: 0, // -100/100 negative is left positive is rogjt
// pitch: 0, // -100/100 positive forward negative back
// yaw: 0, // -100/100 100 yar is 90 degree rotation
// gaz: 0, // -100/100, = throttle GOES UP
// });
// // drone.lights({mode:"FIXED",intensity:100});
// // drone.fly({
// // roll: 0, // -100/100
// // pitch: 0, // -100/100
// // yaw: 0, // -100/100
// // gaz: 0, // -100/100, = throttle
// // });
// drone.autoTakeOff(); // will start propellers in low mode and wait for you to throw it in the air (gently)
// drone.flip({direction: 'right'}); // front/back/right/left
// drone.flatTrim();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment