Welcome to the world of LEGO MINDSTORMS EV3 and voice with Alexa! These instructions will allow you to build SNOOMBA - THE SNOW CLEARING ROBOT.
Here is what is included in this documentation:
- Setup: Get your EV3 development environment setup.
- Mission 1: Get your EV3 Brick connected to a compatible Echo device, and reacting to the wake word.
- Mission 2: Build EV3RSTORM's legs, and react to music played from your Echo device.
- SNOOMBA: Build and run SNOOMBA using ALEXA commands.
At this point, you should have completed the Setup Guide, Mission 1, and Mission 2 to get your EV3 Brick connected to your Echo device and reacting to Alexa. You're on a roll!
In this mission, you will explore how to create custom interactions between your EV3 Brick and an Alexa skill. An Alexa skill is like an app for Alexa, and is built using code stored in the cloud. You will:
- Download SNOOMBA code and build instructions
- Build SNOOMBA
- Create an Alexa skill to control SNOOMBA
- Make SNOOMBA react to custom commands triggered by your voice
In the end, SNOOMBA can react to an Alexa skill like this:
Download SNOOMBA code and build instructionsPlease download SNOOMBA code and build instructions. SNOOMBA code and build instructions are present in the folder /ev3-snoomba.
Under /ev3-snoomba
please refer snoomba-build-instructions-1.0.pdf to build it. The build should look like this:
With the Amazon Developer account you used in Mission 1 handy, you can create your Alexa skill. This skill will react to voice commands and direct the way your robot should move, using commands like, “move forward”, “move back”, “sound the alarm”, and more!
While the code for your gadget is written in Python 3, the code for your skill is written in Node.js in order to take advantage of the Alexa-hosted option for your Skill.
Note: At the time of writing, the Python option for Alexa-Hosted skills was not available, but this method will work. We will work to add a guide for Python-based skills in the future. In the meantime, you can reference the Color Cycler Alexa skill for the Raspberry Pi sample to get started.
Let’s walk through the steps of creating your Skill:
1. Sign in to developer.amazon.com.
2. In the top header, hover over Alexa, and click on Alexa Skills Kit.
3. In the upper-right of the screen, click on Create Skill.
4. Enter a Skill Name, maybe “MINDSTORMS”. The name you give your Skill will also be the way you open the Skill. For example, “Alexa, open mindstorms”, or, “Alexa, tell mindstorms to go forward”. You can modify this later.
5. Select your default language. Make sure the language select matches the language used on your Echo device.
6. Select Custom for the “Choose a model to add to your skill” option.
7. Select Alexa-Hosted for the “Choose a method to host your skill's backend resources” option.
Note: At the time of writing, the Python option for Alexa-Hosted skills was not available, but this method will work. We will work to add a guide for Python-based skills in the future. In the meantime, you can reference the Color Cycler Alexa skill for the Raspberry Pi sample to get started.
8. Click Create skill in the upper-right.
9. Once you click Create skill, you will see a modal while your skill is being prepared to be customized.
Enable the Custom Interface ControllerThe Custom Interface Controller allows you to send custom commands to your EV3Brick (Custom Directives), and receive events from your EV3 Brick (Custom Events). For this mission, you will need to enable the Custom Interface Controller, so you can use Custom Directives:
1. Click on Interfaces in the left navigation of the Alexa Developer Console.
2. Toggle Custom Interface Controller to ON.
3. Scroll to the top of the page and click Save Interfaces
That’s it! With Custom Interface Controller toggled on, you can write code that sends custom directives to your EV3 Brick and program how you want it to react. Learn more about Custom Interfaces.
Define the Skill Interaction ModelThe Skill Interaction Model defines how you can speak to your skill, and what kind of commands it can expect to respond to. The interaction model includes intents, slots, sample utterances that you define, and program against in your skill’s code. Learn more about the Skill Interaction Model.
1. In the Alexa Developer Console, under Interaction Model, click on JSON Editor.
2. In the /ev3-snoomba
folder, you will see a folder called skill-nodejs
. Within that folder, there is a model.json
file. Copy the interaction model JSON from that file, and paste it into the editor, or drag and drop the JSON file onto the drop zone to upload it.
After pasting the JSON into the Alexa skill JSON Editor, click Save Model, and then Build Model presented at the top of the console interface. It may take some time for the model to build, so be patient.
Implementing the Skill LogicThere’s a lot to learn about creating skills, but for the purpose of this mission, we’ll guide you through using the Alexa-Hosted skill option you selected earlier, and share additional resources at the end. With an Alexa-Hosted skill, you can start writing code for your skill directly in the Alexa Developer Console:
1. Click on Code in the top navigation bar of the Alexa Developer Console.
2. In VS Code, open the index.js
file in the ev3-snoomba/skill-nodejs/lambda
folder.
3. Copy the code in the index.js
file into the index.js
file in the Alexa Developer Console Code Editor.
4. Copy the contents of the package.json
and util.js
files to the respective files in the Alexa Skill Code Editor.
5. Create a new file by clicking the New File icon in the upper-left of the Code Editor, and fill in the path and file name as /lambda/common.js
6. With the common.js
file created, make sure the file is open, and then copy the code in the common.js
file from the ev3-snoomba/skill-nodejs/
folder in VS Code to the common.js
file in the Alexa Skill Code Editor.
1. Click Deploy in the upper-right of the Alexa Skill Code Editor. Wait for the deployment process to complete.
2. In the top navigation bar of the Alexa Developer Console, click on Test.
3. You can choose to enable the microphone on your computer or not.
4. Switch the testing from Off to Development using the dropdown under the navigation bar.
5. In the panel on the left, you can either type “open mindstorms”, or say that utterance when you press the microphone button (you will have opted to enable the microphone on your computer for this to work).
6. You should get a response along the lines of, “I couldn't find an EV3 Brick connected to this Echo device. Please check to make sure your EV3 Brick is connected, and try again”, which you specified in the LaunchRequestHandler
.
Your skill is working! Let’s complete the other side of the experience by reviewing and running the EV3 code to get SNOOMA to react to your skill.
Registration and capabilitiesWith your skill created, it’s time to review and run the code that can react to the Alexa skill you created. Using the same VS Code workspace from Mission 2, open the ev3-snoomba
. You should see a familiar series of files: an INI file, and Python file. This will be a common pattern for all the missions you will be working through.
As with the other missions, the first thing you need to do is add your Amazon ID and Alexa Gadget Secret for your registered gadget, and add a new capability to your gadget specified in the initialization file. You can access the code you need to run on the EV3 Brick at /ev3-snoomba
. Within this folder, open the snoomba.ini
file, which should look like:
[GadgetSettings]
amazonId = YOUR_GADGET_AMAZON_ID
alexaGadgetSecret = YOUR_GADGET_SECRET
[GadgetCapabilities]
Custom.Mindstorms.Gadget = 1.0
The above should look familiar. Replace YOUR_GADGET_AMAZON_ID
and YOUR_GADGET_SECRET
with the ID and Secret tied to the Alexa Gadget you registered in the Amazon Developer Console.
With those changes, your EV3 Brick will be able to connect to your Echo device as an Alexa Gadget, and you’ll see a different capability has been specified. The Custom.Mindstorms.Gadget
should look familiar from the skill code you were working with when the commands to send to your EV3 Brick were being constructed. Custom Interfaces are different because YOU get to define what data is sent to and from your gadget, rather than Alexa. The naming convention for adding a Custom Interface is as follows:
Custom.<namespace> = <version>
This can be broken down as:
Custom.
is constant prefix that is always appended to the namespacenamespace
is defined by you. It can be any arbitrary string. In this example, you are usingMindstorms.Gadget
as the namespace of our interface. Note that namespace is not case sensitiveversion
is set to 1.0 since this is the currently supported version of your Custom Interface. It can’t, and shouldn’t need to, be changed.
With the Custom Interface added to your EV3 Brick’s Gadget Capabilities, you can respond to custom directives sent to your EV3 Brick sent via the Alexa skill you created.
Test SNOOMBA with the Alexa skillNow that you’ve created your skill, and reviewed the Python code that will cause SNOOBA to react to that skill, you’re ready to test out the experience. You will need to run the Python code before starting the skill:
1. Make sure VS Code is connected to your EV3 Brick. You should see a green dot next to your EV3 Brick’s name in the EV3 DEVICE BROWSER.
2. Copy the ev3-snoomba folder in your computer workspace to your EV3 Brick. Click on the Send workspace to device button next to the EV3DEV DEVICE BROWSER text that shows up when you hover over the text.
When you click this button, you will see the status of the files being copied in the bottom-right of VS Code.
3. Once the files have copied over to your EV3 Brick, you can run the Python code by navigating to the Python file in the EV3 DEVICE BROWSER , right-click on the Python file, and select Run.
4. Once the program starts, you should see a prompt in the debug console when your EV3 Brick connects to your Echo device.
You will also see a message displayed on your EV3 Brick's screen.
Now comes the fun part! Make some room for SNOOMBA, Sprinkle some salt or snow in front of SNOOMBA and try the following commands to see how SNOOMBA reacts:
“Alexa, open mindstorms”
Alexa should respond acknowledging the skill session is active and listening for commands. The skill must be in session in order for the other following commands to work.
“Clear Snow”
Alexa should acknowledge the command, and SNOOMBA should move forward and clear snow.
“Brake”
This will make SNOOMBA stop.
Comments