AWS Robotics Blog
Build an Alexa controlled robot with AWS RoboMaker
This blog references AWS RoboMaker Integrated Development Environment (IDE), a feature that has been deprecated. To follow along with this blog post, use the AWS Cloud9 IDE. See our updated blog on how to Build and simulate robotics applications in AWS Cloud9.
Introduction
Alexa is Amazon’s cloud-based voice service and Alexa-compatible devices allow users to control their smart devices with voice commands. Today, Alexa is available on hundreds of millions of devices from Amazon echo devices to third-party devices. Alexa Skill Kit (ASK) provides a way for robot developers and manufacturers to build a natural voice interface for their robots. AWS RoboMaker is a cloud robotics solution that provides a customized development environment, a fully-managed simulation infrastructure, and built-in cloud extensions making it easy to build and test robot applications and integrate them with other AWS services. In this blog post, I will show you how to use AWS RoboMaker to develop and test an Alexa-controlled robot.
Overview of Solution
Alexa provides a set of built-in capabilities, referred to as skills. A robot controller skill receives the customer’s voice command through an Alexa enabled device like Amazon Echo and converts the command to a text message. The text message is published to an IoT topic in an Alexa skill AWS Lambda code hook. The robot receives the text command through the subscribed AWS IoT topic and executes the command. AWS RoboMaker is used to develop and simulate the voice-controlled robot.
Walkthrough
Building an Alexa-controlled robot in AWS RoboMaker involves the following steps:
- Create an IoT thing in AWS IoT.
- Create an Alexa skill.
- Create a robot application in AWS RoboMaker.
- Simulate the robot in AWS RoboMaker simulations.
Prerequisites
For this walk through, you need to have the following prerequisites:
- An AWS account
- An Alexa developer account
- A Region that supports AWS RoboMaker. This blog uses us-west-2 (Oregon) Region.
Step 1: Create a IoT thing in AWS IoT
First, create an IoT thing in AWS IoT Core Service. The IoT thing represents a robot in AWS IoT, and the command sends from Alexa to the robot through the IoT topic. For more details, see Create a thing.
- Log in to AWS IoT Core Console, select Onboard, then select Get Started. Click Onboard a device.
- Select Linux/OSX as your platform and select Python as the AWS IoT Device SDK, then click Next.
- Create a name for your IoT thing. For example: VoiceControlledRobot, then click Next.
- Select Linux/OSX to download the IoT connection kit package. Use the IoT thing certificates in the downloaded package to create the IoT MQTT client in the following steps. Click Next Step.
- Review the Configure and test your device section, then click Done.
- Go to AWS IoT Core, select Manage and then select Things. Select Create IoT thing and select Interact. Save the Rest API Endpoint of the IoT thing. The IoT thing endpoint is used to create the IoT MQTT client in the following steps.
Step 2: Create an Alexa skill
Here we build a new robot skill that converts voice commands to text message and sends the command to the robot. For more details, see Build Skills with the Alexa Skills Kit.
- Log in to Alexa Developer Console, then click Create Skill.
- Create a skill name, and select Alexa-Hosted(Python) as the method to host your skill’s back end resources, then click Create Skill.
- Select default Hello World Skill as template, then select Continue with template to create a new skill.
- Select + Add Intent in the intents section to create a name for the new intent, for example, MoveForwardIntent.
- Select Create Custom Intent and create a new MoveForwardIntent.
Add sample utterances to MoveForwardIntent:
tell robot to move forward
move forward
forward
- Select Save Model and then select Build Model.
- Select the Code tab at the top of the page. Add Amazon Root CA1 and AWS IoT Certificates downloaded in Step 1 to lambda folder. These certificates are used to build the IoT MQTT connection’
8. Add IoT MQTT Client and intent handler to existing lamba_funtion.py.
This sample Python script shows how to publish the command to an IoT Topic in MoveForwardIntent Handler. For more details about MQTT, see here.
- Repeat previous Step 2 to add a MoveBackwardIntent.
Step 3: Create a robot application with AWS RoboMaker
Create a sample Robot application in AWS RoboMaker. You can find the source code in this aws-robotics GitHub repo. For more information, see Creating a Robot Application and Sample Robot Application.
- Go to AWS RoboMaker console, select Development, and then select Robot applications. Click Create robot application.
- Enter a name for the robot application. For ROS distribution, select ROS Kinetic. Use the default VPC and select a subnet. Select Create to create the AWS Cloud9 development environment.
- In the AWS Cloud9 development environment, select AWS RoboMaker Resources, then select Download samples, and then select Hello World.
- On the left, in the Environment tab, expand HelloWorld, HelloWorld, robot_ws, src, hello_world_robot. Create certificates fold and upload Amazon Root CA1 and AWS IoT Certificates downloaded in Step 1 to this folder. These certificates are used to build the IoT MQTT connection.
- Add AWS IoT dependencies to ROS.
Open a new terminal in AWS RoboMaker Development environment and run following command:
- Create a new node to receive MQTT command from Alexa and create a mqtt_listener.launch file for new created node.
This sample MQTT listener node script shows how to subscribe and receive command from IoT Topic.
Here is the sample launch file.
- Build and bundle the robotics application sources
- Create a robot application.
This command returns information about the newly created robot application.
- Create a simulation application.
The command returns information about the newly created simulation application.
Step 4: Simulate the Robot with AWS RoboMaker Simulations
- Create a simulation job role by following our AWS document here.
- Go to AWS RoboMaker console, select Simulation Jobs, and click Create simulation job.
- For ROS distribution, select ROS Kinetic. For IAM role, select the role created in step 1.
- For Networking, select default VPC, default security groups, and two subnets. Select Next.
- For Robot application, select MyRobotApplication. Usehello_world_robot as launch package name and use mqtt_listener.launch as launch file name. Click Next.
- For Simulation application, use hello_world_simulation as launch package name and use empty_world.launch as launch file. Click Next.
- Review the details and click Create to create a simulate job.
- Select the new create simulation job and connect to Gazebo. A simulation window opens up.
- Go to Alexa Developer Console, select the new created skill, and select Test.
- Enter “Ask <invocation name> to move forward” and the robot moves forward in the simulation window.
Conclusion
In this blog, we demonstrated and walked you through the process on how to build a voice-controlled robot with an Alexa skill kit and AWS RoboMaker. To learn more about AWS IoT, visit https://aws.amazon.com/iot/. To learn more about Alexa Skill Kit, visit https://developer.amazon.com/en-US/alexa/alexa-skills-kit. To learn more about AWS RoboMaker, visit https://aws.amazon.com/robomaker/.