SRS is a cloud-connected robot arm that subscribes to a gesture input device (Leap Motion) via the AWS IoT service. Observe metrics such as x, y, z coordinate movement and hand gestures in near real-time through a custom JavaScript application running on Amazon S3.
Simple Robot Service uses AWS IoT to send messages between a publisher and a subscriber. The publisher.py script will run on the computer connected to the LEAP motion controller. The subscriber.py script will run on the raspberry pi that has the Adafruit Servo Hat and the Robotic Arm connected.
Simple Robot Service was demonstrated during the AWS keynote address at Re:Invent 2015.
Complete list: http://www.amazon.com/registry/giftlist/10S3G6J5UJBXO
This includes:
- Need to install python (version 3.5.x). When installing python, make sure that the python executables get added to the PATH variable.
-
Click on the AWS IoT (Beta) icon in the AWS Management Console.
-
Press Getting Started.
-
There are three resources that need to be created. An IoT "Thing", a certificate and associated keys and a policy. To start, click Create a thing and then type LeapMotionController as the name of the thing. Press Create.
-
Next, download the X.509 certificates. Click Create a certificate, followed by 1-Click Certificate Create. Download the three files that are created. These files are needed to connect over TLS from both the local computer with the LEAP Motion Controller and the Raspberry Pi.
-
Now, create a policy to interact with the IoT resources. Click Create a policy. This example will be very permissive. In a real-world scenario, the policies that are created should only allow specific read/write permissions to specific IoT resources. Call the policy LeapMotionPolicy. Define the action as iot:* and the Resource as *. Press Create.
-
The final step is to attach the policy and the thing (Leap Motion Controller) to the certificate. On the AWS IoT dashboard, click the checkbox under the certificate. In the actions dropdown, click Activate followed by Attach a Policy and Attach a Thing. Attach the policy and the thing that was made in the previous steps.
NOTE: A root certificate is required to complete the TLS connection to AWS IoT from the devices. Here is the link to the AWS IoT root certificate:
Create an account at https://developer.leapmotion.com/ and download the SDK. Once done, copy over the following files to the devices/lib directory:
- Leap.py
- LeapPython.so
- libLeap.dylib
Next, setup the LEAP development environment following the guides below.
- https://developer.leapmotion.com/documentation/java/devguide/Project_Setup.html
- https://developer.leapmotion.com/documentation/python/devguide/Sample_Tutorial.html
On the Raspberry Pi, the Adafruit PWM/servo libraries are required. Download them to the Raspberry Pi from here: https://github.com/adafruit/Adafruit-PWM-Servo-Driver-Library
git clone https://github.com/adafruit/Adafruit-PWM-Servo-Driver-Library.git
- http://www.amazon.com/Adafruit-16-Channel-PWM-Servo-Raspberry/dp/B00XW2OY5A
- https://learn.adafruit.com/adafruit-16-channel-pwm-servo-hat-for-raspberry-pi/overview
The following python libraries are required:
pip install schedule paho-mqtt
To operate the robotic arm, attach the LEAP motion controller to the laptop and run: python publisher.py. Secondly, SSH into the IoT device and copy over the application files. Run python subscriber.py on the raspberry-pi. The arm should now move when gestures are made above the LEAP Motion Controller.
Visualize this data in real-time by running the web application code found in the web/ directory.
In order to visualize the data from various locations, we will need to store the data in a database. In this example, AWS IoT is used to invoke a Lambda function that writes to DynamoDB based on a defined rule. All of the resources with exception of the AWS IoT resources can be created using cloudformation. Two cloud formation scripts are included, one for custom domains that includes route53 hosted zone information (srs-with-domain.json), and one that uses AWS provided S3 URLs (srs.json). The two scripts can be found in the /cfn folder.
First, create a new DynamoDB table to store the data. The DynamoDB table should have a hash key named EventID and a range key named FrameID. The data will be stored in a JSON object in this table. This table was created via the cloud formation script.
Next, create the Lambda functions. In the folder web/lambda there are two subfolders, srsgetdata and srsputdata. In each of these folders run:
npm install
This will download and install all of the required node modules. Then, edit index.js for each function and put in the DynamoDB table name created above and an EventID. After you have edited the index.js file and the NPM install process completes, zip up the contents of that directory (make sure that index.js is in the root of the zip file).
Once the zip file is ready, follow these steps:
-
Open the Lambda console.
-
Click on the srsputdata-XXXXXXXXX function. Upload the srsputdata zip file that was created above.
-
Click on the srsgetdata-XXXXXXXXX function. Upload the srsgetdata zip file that was created above.
-
In srsgetdata, click the API Endpoints tab. Create a new endpoint for this function and enable CORS. Note the endpoint that was created.
-
First, let's create a rule. Press Create a rule. Type LeapMotionRule as the rule name and give it a description.
-
In the Rule Query Statement section, type * in the attribute field and srs in the topic filter.
-
Next, let's add an action to this rule. In the drop down list select Insert this message into a cloud function and run it (Lambda).
-
Once done, press Add Action followed by Create. Select the SRS Put Data lambda function in the drop down.
-
In the web application files, find main.js. Update the ENDPOINT variable to point to the AWS API Gateway endpoint created above.
-
Open the file Gruntfile.js and look for the following code snippet:
grunt.registerTask('publish', [ 'build', 'exec:s3push:<SRS_BUCKET_NAME>:<PROFILE>:us-east-1' ]);
-
Replace SRS_BUCKET_NAME with the name of the website bucket and PROFILE with the name of the AWS CLI profile to use. The profile can be set as default.
-
Use the command line to open the web/ directory. Here are some commands that are provided by this Gruntfile:
grunt serve # Builds the code and runs a local web server. grunt build # Builds the code grunt publish # Builds the code and publishes to S3
-
Alternatively, upload the files directly after a grunt build using the browser. Simply upload all of the files in the /dist folder to the S3 bucket.