My son Jan, who is 12 years old, and I built Alexa powered LEGO MINDSTORMS T-Rex dinosaur. Jan built T-Rex out of LEGO MINDSTORMS EV3 set, and I developed Alexa skill and Python application that runs on EV3 brick.
This is our first Hackster.io challenge we participated in and we are very happy with the project we built. Feel free to check out our demo video and read on to see how we built it!
Demo VideoPrerequisitesI recommend you take a look at the Voice Challenge Setup tutorial in order to set up your EV3 brick and Amazon Echo. Once this is done you can easily use code from the provided repository. In order to build your T-Rex robot please see the attached schematics.
T-Rex Actions With AlexaAlexa powered T-Rex is capable of performing following actions:
- movement in direction
- movement in direction with duration
- guard mode
- basketball
When skill is started Alexa will check is EV3 connected and if everything looks good user will be greeted with a message "Welcome to T Rex skill!".
Movement in direction is performed with voice command:
{direction} now
Following directions are supported:
- forwards
- backwards
- left
- right
- brake
If you ask T-Rex to turn left of right, it'll first turn by 90 degrees and afterwards move forward in that direction.
Movement in direction with duration is performed with voice commands:
{direction} {duration} seconds
move {direction} for {duration} seconds
Example: "Move forward for 2 seconds!"
Guard mode is started with voice command:
activate guard mode
activate guard
While in guard mode T-Rex will monitor changes via IR sensor and if intruder is detected it'll try to bite it.
Basketball is just an "easter egg" we added, you can ask T-Rex to play basketball with following voice commands:
T-Rex play basketball
play basketball
basketball
Alexa will reply "T Rex doesn't like that!" and you'll hear T-Rex roar. ππ¦
AudioFor this project we used audio from Alexa Skills Kit Sound Library and you can find it on following link: https://developer.amazon.com/en-US/docs/alexa/custom-skills/ask-soundlibrary.html
This sound library is great resource for any project you are making with Alexa and for our project we managed to found several dinosaur sounds we could choose from to make our T-Rex more interactive.
Code HighlightsYou can find all code in the linked repository, here are some explanations and highlights.
Main motors are set to ports A and D, and you can find this defined in Python script. Those motors are used to move T-Rex around.
self.drive = MoveTank(OUTPUT_A, OUTPUT_D)
T-Rex mouth uses medium motor and it is connected to the port B.
self.mouth = MediumMotor(OUTPUT_B)
Mouth works with simple loop that is used to open and close it three times in a row,
for i in range(3):
self.mouth.on_for_rotations(SpeedPercent(70), 0.15)
self.mouth.on_for_rotations(SpeedPercent(70), -0.15)
For our "basketball" feature we added additional intent in Alexa skill.
// Basketball
const BasketballIntentHandler = {
canHandle(handlerInput) {
return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest'
&& Alexa.getIntentName(handlerInput.requestEnvelope) === 'BasketballIntent';
},
handle: function (handlerInput) {
return handlerInput.responseBuilder
.speak("T Rex doesn't like that!"+ SOUND_ROAR_LOW)
.getResponse();
}
};
You'll notice that audio is combined with responses, so audio constants are defined at the start of the code.
const SOUND_ROAR_LOUD = '<audio src="soundbank://soundlibrary/animals/dinosaurs/dinosaurs_12"/>';
const SOUND_ROAR_LOW = '<audio src="soundbank://soundlibrary/animals/dinosaurs/dinosaurs_13"/>';
Most of the code should be self-explanatory, in case there are some doubts feel free to ask in the comments.
SummaryLEGO MINDSTORMS is great educative toy and in combination with Amazon Echo device it can provide a lot of fun. Even MINDOSTORMS is easy to use, this whole set up would be challenging for young children, but if you are looking for some "son & dad weekend project" this is defiantly a great idea to try it out! π
Comments