node-parrot-drone
v0.1.0
Published
extendable node module to allow control of any Parrot Mini Drone
Downloads
10
Maintainers
Readme
node-parrot-drone for node
A fully featured implementation of the Parrot SDK for node.js so you can do stuff with drones!
Control Any Parrot Drone
This is the core module for connecting to and controlling any
Parrot drone with JavaScript via node! It is designed to be extended with new drone projects, classes and commands as they are created by Parrot.
This module contains the core code for such extensions with all shared information and commands. It is responsible for connecting, receiving and sending messages, automated responses, parsing data and populating drone status as well as dispatching drone events, updates and status changes.
Contributing
- Star
- Fork
- Make awesome changes
- Merge from this repo's Master branch to make sure you don't have conflicts
- Submit a PR
- Have a beer, milkshake, raw juice, or just feel good inside knowing you helped move the JS drone community forward!
This module is Beta as of February 2017
To use the module install it via npm
npm i node-parrot-drone
Connecting to a drone
const parrot=require('node-parrot-drone');
const drone=new parrot.Wifi;
function connected(){
console.log('connected');
}
//the drone will emit a connected event
drone.on(
'connected',
connected
);
//optionally you can pass a callback to the connect method if you prefer
drone.connect(connected);
Listening for all messages from the drone
There will be a lot of messages, but you can check for the ones you like using the projectID, classID and commandName. This is especially useful when debugging or hacking a new drone.
drone.on(
'message',
function(message){
console.log(message);
}
);
Listening for changes on specific drone argument sets
This is probably the most useful way to monitor your drones state.
//debug or see non automatic messages (pings, pongs, etc. are not bubbled)
drone.on(
'message',
function(message){
console.log(message);
}
);
drone.on(
'responseError',
function(message){
console.log('The drone sent a malformed message. Probably not important.');
console.log(message);
}
);
drone.on(
'messageSent',
function(data){
console.log('Debug your messages if needed.');
console.log(data);
}
);
drone.on(
'*',
function(type,data){
console.log('OMG listening to all events...');
console.log(type,data);
}
);
function batteryStateChanged(commandRef){
//commandRef is a reference to the command itself in the project state
console.log('battery is now at %d percent',commandRef.percent);
}
//listen for changes on the command state
drone.projects.common.BatteryStateChanged.on(
'change',
batteryStateChanged
);
//or listen for the specific event on the drone
drone.on(
'batteryStateChanged',
batteryStateChanged
);
Sending commands or updating values on your drone
const project=drone.projects.common;
//build a message requesting all settings
const getSettingsState=drone.message.build(
project.id,
project.settings.id,
project.settings.allSettings
);
//build a message requesting all common states, like battery percent :)
const getCommonState=drone.message.build(
project.id,
project.common.id,
project.common.allStates
);
//update the magnetoCalibration value on the project state
drone.message.command=project.calibration.magnetoCalibration;
//build a message with the updated value
const calibrate=drone.message.build(
project.id,
project.calibration.id,
project.calibration.magnetoCalibration
);
//send all the commands to the drone
drone.message.send(getSettingsState);
drone.message.send(getCommonState);
drone.message.send(calibrate);
Really verbose logging about messages and drone connectivity
Put these lines in before connecting to see detailed TCP and UDP info.
drone.discovery.config.silent=false;
drone.d2c.config.silent=false;
License
DBAD