How about a voice activated indoor drone?
Instruct the drone to take off, land, move forward or flip. I used Raspberry Pi and PubNub to connect the drone and Amazon Echo.
Stuff you need:- Amazon Echo - To host the Alexa Skills Kit
- Raspberry Pi 3 - Bluetooth capabilities of Raspberry Pi 3 can connect to Rolling Spider Drone
- Rolling Spider Drone - I name him Echobot
I started a new skill and name him Echobot
Here are the Intents
{
"intents": [
{
"intent": "GetUp",
"slots": [
{
"name": "Height",
"type": "NUMBER"
}
]
},
{
"intent": "TakeOff",
"slots": []
},
{
"intent": "Land",
"slots": []
},
{
"intent": "Initiate",
"slots": []
},
{
"intent": "Flip",
"slots": []
}
]
}
Here are the Utterances
Initiate Initiate Drone
Initiate Initiate
Initiate Start Drone
Initiate Wake up Spider
Initiate Wake up
Initiate Blink
TakeOff Take Off
TakeOff Fly
TakeOff Fly the drone
TakeOff Hover
TakeOff Go Up
TakeOff Blink
Land Land the drone
Land Stop
Land Sleep
Land Go Down
Land Land
Step 2: Create PubNub AccountGo to https://www.pubnub.com/
Just create a new keyset and use the free tier. Save your keys:
Create the Lambda app
Here's the link: https://github.com/rondagdag/echobot/tree/master/echoApp
I'm using some libraries from npm to connect to pubnub.
npm install pubnub --save
Then Modify index.js to include your pubnub keys.
var pubnub = require("pubnub")({
ssl : true, // <- enable TLS Tunneling over TCP
publish_key : "pub-c-....bd09a3eff137",
subscribe_key : "sub-c-.....02ee2ddab7fe"
});
Zip up files then use this when you create your lambda app.
Then link the ARN number to Alexa Skill Endpoint:
The Lambda app is simple, when it receives the "Initiate" intent it would do this:
Send to pubnub channel - "my_channel" the initialMessage object which has the command "Initiate" and the sessionID.
Initiate: function (intent, session, response) {
var initiateMessage = {
"command" : "initiate",
"sessionId" : session.sessionId
};
console.log(pubnub.get_version());
pubnub.publish({
channel : 'my_channel',
message : initiateMessage,
callback : function(e) {
console.log( "SUCCESS!", e );
response.tell("Drone is ready to fly");
},
error : function(e) {
response.tellWithCard("Could not connect", "Drone", "Could not connect");
console.log( "FAILED! RETRY PUBLISH!", e ); }
});
},
I do the same for TakeOff or Landing, just send the correct command message and pass the callback so Alexa can respond properly
TakeOff: function (intent, session, response) {
var takeOffmessage = {
"command" : "takeOff",
"sessionId" : session.sessionId
};
console.log(pubnub.get_version());
pubnub.publish({
channel : 'my_channel',
message : takeOffmessage,
callback : function(e) {
console.log( "SUCCESS!", e );
response.tell("Drone is flying");
},
error : function(e) {
response.tellWithCard("Could not connect", "Drone", "Could not connect");
console.log( "FAILED! RETRY PUBLISH!", e ); }
});
},
Land: function (intent, session, response) {
var landMessage = {
"command" : "land",
"sessionId" : session.sessionId
};
console.log(pubnub.get_version());
//response.setShouldEndSession(true);
pubnub.publish({
channel : 'my_channel',
message : landMessage,
callback : function(e) {
console.log( "SUCCESS!", e );
response.tell("Going down");
},
error : function(e) {
response.tellWithCard("Could not connect", "Drone", "Could not connect");
console.log( "FAILED! RETRY PUBLISH!", e ); }
});
},
I was sending the publishing to pubnub and Amazon Echo was not responding properly or crashing. Took me awhile to figure it out, but the important concept is that you have to pass callback to pubnub.publish. And when it receives a response from pubnub, you have to tell Alexa what to say if it's successful or if it failed by calling response.tell
Step 4: Create a Rolling Spider NodeJS app in Raspberry PiMake sure you have NodeJS on Raspberry Pi. I found out that there's an npm module for Parrot Rolling Spider Drone: https://www.npmjs.com/package/rolling-spider
So I created an app. Here's the link: https://github.com/rondagdag/echobot/tree/master/droneApp
These are my npm dependencies:
"dependencies": {
"noble": "^1.0.2",
"pubnub": "^3.7.13",
"rolling-spider": "",
"temporal": "^0.4.0"
},
Edit rollingspider.js and plug in your pubnub credentials:
var pubnub = require("pubnub")({
ssl : true, // <- enable TLS Tunneling over TCP
publish_key : "pub-c-....-bd09a3eff137",
subscribe_key : "sub-c-....-02ee2ddab7fe"
});
At the end of the day after the raspberry pi was able to connect to the drone, It would initiate and subscribe to pubnub channels.
Since the Raspberry Pi does not have an external IP address that AWS Lambda can connect to, It's just easier to subscribe to messages and have AWS Lambda publish the events in pubnub.
The code subscribes to "my_channel" and would start receiving messages. It would read the message.command property that could either be "initiate", "takeOff" or "land". It would then relay the message to the rolling spider.
var RollingSpider = require("rolling-spider");
var rollingSpider = new RollingSpider('d2edda91562142e988ffcb4a595f8cd9');
var temporal = require('temporal');
// NEW CODE BELOW HERE
rollingSpider.connect(function () {
rollingSpider.flatTrim();
rollingSpider.startPing();
rollingSpider.flatTrim();
console.log('Connected to drone', rollingSpider.name);
pubnub.subscribe({
channel : "my_channel",
callback : function(message) {
console.log( " > ", message );
console.log(message.command);
switch(message.command) {
case "initiate":
//code block
console.log("initiate");
rollingSpider.flatTrim();
rollingSpider.startPing();
rollingSpider.flatTrim();
break;
case "takeOff":
//code block
console.log("take Off");
rollingSpider.takeOff();
rollingSpider.flatTrim();
break;
case "land":
//code block
rollingSpider.land();
break;
default:
//default code block
}
}
});
});
That's it. To Run
node RollingSpider.js
Then say - "Alexa, tell Echobot to fly"
If this project made you interested into developing Amazon Echo Skill or Rolling Spider drone, please add respect and follow me. Thank you.
Comments