extendable node module to allow control of any Parrot drone.
OTHER License
A fully featured implementation of the Parrot SDK for node.js so you can do stuff with drones!
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.
To use the module install it via npm
npm i node-parrot-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);
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);
}
);
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
);
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);
Put these lines in before connecting to see detailed TCP and UDP info.
drone.discovery.config.silent=false;
drone.d2c.config.silent=false;
DBAD