Skip to content

Instantly share code, notes, and snippets.

@saval
Forked from agrublev/dronefly.js
Last active June 24, 2018 19:13
Show Gist options
  • Save saval/0526f7462436bdfe2c53083ffe59729a to your computer and use it in GitHub Desktop.
Save saval/0526f7462436bdfe2c53083ffe59729a 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));
}
drone.on('connected', async () => {
// drone.flatTrim(); // use flatTrim() everytime you want the drone to calm down
drone.takeOff();
await sleep(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: 100, // -100/100, = throttle GOES UP
});
await sleep(300);
//jumping up-down
drone.fly({
roll: 0, // -100/100
pitch: 0, // -100/100
yaw: 0, // -100/100
gaz: -50, // -100/100, = throttle
});
await sleep(300);
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: 50, // -100/100, = throttle GOES UP
});
await sleep(300);
drone.fly({
roll: 0, // -100/100
pitch: 0, // -100/100
yaw: 0, // -100/100
gaz: -50, // -100/100, = throttle
});
await sleep(300);
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: 50, // -100/100, = throttle GOES UP
});
await sleep(300);
drone.fly({
roll: 0, // -100/100
pitch: 0, // -100/100
yaw: 0, // -100/100
gaz: -50, // -100/100, = throttle
});
await sleep(300);
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: 50, // -100/100, = throttle GOES UP
});
await sleep(300);
drone.fly({
roll: 0, // -100/100
pitch: 0, // -100/100
yaw: 0, // -100/100
gaz: -50, // -100/100, = throttle
});
await sleep(300);
//dancing left - right
drone.fly({
roll: -50, // -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(300);
drone.fly({
roll: 100, // -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(300);
drone.fly({
roll: -100, // -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(300);
drone.fly({
roll: 100, // -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(300);
drone.fly({
roll: -50, // -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(300);
//rotation
drone.fly({
roll: 0, // -100/100 negative is left positive is rogjt
pitch: 0, // -100/100 positive forward negative back
yaw: 100, // -100/100 100 yar is 90 degree rotation
gaz: 0, // -100/100, = throttle GOES UP
});
drone.fly({
roll: 0, // -100/100 negative is left positive is rogjt
pitch: 0, // -100/100 positive forward negative back
yaw: 100, // -100/100 100 yar is 90 degree rotation
gaz: 0, // -100/100, = throttle GOES UP
});
drone.fly({
roll: 0, // -100/100 negative is left positive is rogjt
pitch: 0, // -100/100 positive forward negative back
yaw: 100, // -100/100 100 yar is 90 degree rotation
gaz: 0, // -100/100, = throttle GOES UP
});
drone.fly({
roll: 0, // -100/100 negative is left positive is rogjt
pitch: 0, // -100/100 positive forward negative back
yaw: 100, // -100/100 100 yar is 90 degree rotation
gaz: 0, // -100/100, = throttle GOES UP
});
//revert direction rotation
drone.fly({
roll: 0, // -100/100 negative is left positive is rogjt
pitch: 0, // -100/100 positive forward negative back
yaw: -100, // -100/100 100 yar is 90 degree rotation
gaz: 0, // -100/100, = throttle GOES UP
});
drone.fly({
roll: 0, // -100/100 negative is left positive is rogjt
pitch: 0, // -100/100 positive forward negative back
yaw: -100, // -100/100 100 yar is 90 degree rotation
gaz: 0, // -100/100, = throttle GOES UP
});
drone.fly({
roll: 0, // -100/100 negative is left positive is rogjt
pitch: 0, // -100/100 positive forward negative back
yaw: -100, // -100/100 100 yar is 90 degree rotation
gaz: 0, // -100/100, = throttle GOES UP
});
drone.fly({
roll: 0, // -100/100 negative is left positive is rogjt
pitch: 0, // -100/100 positive forward negative back
yaw: -100, // -100/100 100 yar is 90 degree rotation
gaz: 0, // -100/100, = throttle GOES UP
});
drone.flatTrim();
//moving by diagonal
drone.fly({
roll: -50, // -100/100 negative is left positive is rogjt
pitch: 50, // -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(300);
drone.fly({
roll: 100, // -100/100 negative is left positive is rogjt
pitch: -100, // -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(300);
drone.fly({
roll: -100, // -100/100 negative is left positive is rogjt
pitch: 100, // -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(300);
drone.fly({
roll: 50, // -100/100 negative is left positive is rogjt
pitch: -50, // -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(300);
drone.flatTrim();
drone.fly({
roll: 50, // -100/100 negative is left positive is rogjt
pitch: -50, // -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(300);
drone.fly({
roll: -100, // -100/100 negative is left positive is rogjt
pitch: 100, // -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(300);
drone.fly({
roll: 100, // -100/100 negative is left positive is rogjt
pitch: -100, // -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(300);
drone.fly({
roll: -50, // -100/100 negative is left positive is rogjt
pitch: 50, // -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(300);
drone.flatTrim();
// 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
await sleep(1000);
drone.flatTrim();
drone.land();
await sleep(1000);
drone.emergency(); // immediately stops the drone, that's what is inside stop.js
await sleep(1000);
process.exit();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment