This project started as an entry in RoboCup Junior OnStage. In RoboCup, the magic show ran autonomously with the robots triggered by timers and Bluetooth. When I saw the LEGO MINDSTORMS Voice Challenge, I wanted to reuse the robots and change them to work interactively with Alexa.
The coolest parts of my project are:
- Not1, not 2 but 3 robots! All of the examples just showed one robot but I read here that the Echo Dot could support up to 3 robots. Given that I had 3 robots, this was perfect! You can learn more under Workingwithmultiplerobots.
- Pixy2 camera. This is used to find the colour of the ball and send it back to Alexa. This gives her eyes, to make it seem like she can also see what is happening.
- Magic trick. After the Pixy2 finds the colour, it shares the colour to the Magical Box robot via Alexa. The same coloured ball then 'appears' in the hidden box (box 3) as if by magic. This trick relies on multiple bits working perfectly together so it is always very exciting to see it happen.
- InteractionwithAlexa. I have tried to make Alexa part of the performance rather than just a voice-activated remote control. In my project, Alexa is the director of the show and I am just an assistant. There are 13 unique interactions designed to create interest and give Alexa her own personality.
- Revealing of the Legendary LEGO MINDSTORMS. For most of the performance the LEGO components are hidden. At the end of the performance, an EV3 brick is finally revealed from behind the sign. I love this bit!
The following instructions for the build include the woodwork, LEGO and code. I've tried to make the instructions as clear as possible. Note: the colours of each piece don't need to be the same as the models as long as they are the right piece. I have mostly included the colours I have used so you will find it easier to compare the photos to the models. I know it's unlikely that someone will build something exactly the same but hopefully some of the ideas will inspire you in your own projects.
I am very lucky that my grandfather has an awesome workshop with a fixed table saw so the woodworking was relatively easy to do. He has taught me some valuable lessons:
- Do a design first, even prototype it with cardboard or something easy to make sure it will do the job.
- Measure and re-measure everything before you cut.
- You can't have too many clamps holding things in position while you screw things in!
Here is the video of my full routine:
How does the magic trick work?Magicians never reveal their secrets... but I'll make an exception in this case. The project is designed to hide the internal workings so the viewer can't see what is happening so the "performance" video doesn't give too much away. I have recorded a 'behind the scenes' video so you can see the trickery in action:
Coloured BallsThe balls that I used for this project are approximately 55mm in diameter. If you can't get the same size you may need to adjust measurements of the various components to suit your balls. For this trick you will need at least 8 balls (2 sets of 4 colours. e.g. pink, purple, blue and green). I also have a spare pair of yellow balls just in case our dog gets one of the other colours :)
Trapdoor robotBuild the LEGO:
I suggest starting with building the LEGO to ensure that the sizes work with the coloured balls you have. I have included build instructions using Bricklink's Studio 2.0 software. You will need to install this to be able to view them. You will find the files under the schematics section:
- Trapdoor robot - this includes the trapdoor mechanism. This includes a catch which holds the door in place until it moves to release the door.
- Magical box 1 & 2 - you need to build 2 identical boxes. They sit on top of the trapdoor table, opening and closing during the show. Note: the models are missing a single 24 tooth gear that sits on the axle from the medium motor and meshes with another 24 tooth gear to open the box lid. The tool wouldn't let me put it in place. I think I need to rotate one of the gears by a few degrees but I couldn't work out how to do this, sorry. You will see the missing gear on photos.
If your coloured balls are bigger, you may have to adjust the LEGO to suit. This will also affect other parts like the woodwork sizes so please be mindful of this.
Build Pixy2 box:
You will need a box to hold the Pixy2 camera and to place the trapdoor robot on top of. The original design was to include the EV3 brick inside the box. This didn't work out very well as you couldn't see the screen so the EV3 brick was moved outside of the box. This means the box is half empty but the lid works well to hold the trapdoor robot.
Start by cutting 12mm ply in a 250mm by 180mm rectangle as the box base. For the sides of the box cut:
- 2 x 275mm by 80mm in 12mm ply
- 2 x 180mm by 80mm in 12mm ply
The base fits inside the sides. Attach the short sides to the short side of the base first. This can be done using glue, screws or nails. Next attach the long sides to the base and the short sides you have already attached.
For the box lid, cut 12mm ply in a 280mm by 210mm rectangle. To make the lid sit on the base, cut 7mm ply in lengths at least 12mm wide that will fit inside the base:
- 2 x 248mm length
- 2 x 178mm length
Cut the ends at 45 degrees and screw into the underside of the lid as a guide for the lid to sit on the base.
At the end of this you should have a box to hold the Pixy2 camera with a lid that sits nicely on it. You will finish off the remaining bits (attach Pixy2, cable hole, hole in lid and holding bay for ball) later in the build.
Note: the following pictures include the trapdoor table base which you will build next.
Build table top, base and legs:
The build of the table top and base is the same at the beginning. Start by cutting 9mm ply in a 400mm by 330mm rectangle for the top of the table and another rectangle the same size for the base of the table.
Next you need to cut 4 rails: 2 for the table top and 2 for the base. Use 15mm ply and cut a 390mm (i.e. slightly shorter than top/base) by 30mm length. Once you have cut the rails, it is time to attach them to the table top and base. Start with the base and mark a line 10mm in from the long edge. Place the edge of the rail on this line, with a 5mm gap in from the short edge of the base. Clamp it down and then screw in from underneath the base with at least 3 screws. Repeat on the other side of the base with another rail. Your base should now be complete.
For the table top, attach 2 rails to the underside of the table the same way. It is really important that the rails on the base line up perfectly with the rails on the top so take extra care with this. Once this is done you can move onto the legs.
The four legs are also cut from 9mm ply. Mine are 210mm by 40mm but I suggest you leave them a little bit longer (e.g. 250mm) then cut down once you have checked all the other measurements. The legs are screwed into the inside of the rails on the table top about 10mm in from the rail end, with at least 2 screws per leg so the leg doesn't swivel. The bottom legs are not screwed into the rails on the base. They instead will wedge into the inside of the rails on the base to keep them in position but easily removable. You need it to be removable to be able to retrieve the ball each time.
Attaching the Pixy2 box and trapdoor LEGO:
Before you attach anything else, put the Pixy2 box onto the table base and then put the trapdoor LEGO build onto the Pixy2 box lid. Check that it looks positioned well in terms of where the trapdoor would be on the top. Once you are happy where everything sits, mark the positions and start attaching them:
- Screw the LEGO build into the lid (2 screws through beam holes, not too tightly to avoid damaging the plastic)
- Screw box base onto table base, at least 2 screws.
Finishing the Pixy2 box lid:
It is now time to create a pathway for the ball to roll from the trapdoor into the Pixy2 box. First you have to cut a 60mm hole into the Pixy2 lid. It should be near the LEGO build so that when the trapdoor drops, the ball rolls straight into it.
To make sure the ball doesn't roll away when the trapdoor drops down you will need to build a barrier box. This will have 3 sides with an open side to allow the ball to roll down from the trapdoor. It will have a top but no bottom as it is positioned on the lid above the hole. You will need to cut:
- 1 x 90mm by 90mm square of 5mm ply
- 2 x 90mm by 90mm square of 9mm ply
- 1 x 65mm by 90mm rectangle of 9mm ply
To assemble the box, start with gluing the longest sides of the 65mm x 90mm rectangle to one of the sides of the 90mm x 90mm square of 9mm ply. Repeat this on the opposite side. When you are finished, screw in from the underside of the lid so it is around the 60mm hole in the lid. You will then need to screw the 90mm x 90mm piece of 5mm ply onto the top, ensuring it is free of the LEGO build.
The ball should now roll consistently down the trapdoor into the Pixy2 box. If there are any problems with this, you will need to fix them before moving on further.
Finishing the Pixy2 box base:
When the ball goes into the Pixy2 box, it will need to be held still so the camera can detect the colour. To make this holding bay you have to cut:
- 2 x 70mm by 50mm of 9mm ply
- 1 x 80mm by 50mm of 9mm ply
Attach one of the shorter sides to the longer piece of ply on a right angle using 2 screws. Repeat for the other shorter side to create a 50mm high 3 sided box.
To make sure the ball doesn't roll out the front of the box, cut a 80mm by 15mm of 9mm ply. Screw this from the front into the side of the box with no barrier. This means that the ball will stay in place but it won't block the Pixy2 from being able to see the ball.
When you are happy with you box, locate it under the hole in the lid and mark where you want to place it. Screw it into the Pixy2 box base from underneath with at least 2 screws. Note: you will need to remove the Pixy2 box base from the trapdoor table base so you can do this and then re-attach it.
Next you have to build a stand for the Pixy2 camera. First, mount the Pixy2 to a LEGO beam - I used a beam of length 9. Build off this beam to create a sturdy base where the Pixy2 can see the ball. I suggest connecting the Pixy2 up to your computer and viewing what the Pixy2 can see to make sure that it is the right distance away and angled correctly. I also have some LEGO pieces added to stop the Pixy2 tilting too far back or forward. You should include pieces to allow the stand to be lightly screwed into the Pixy2 box base to keep it in place. I haven't included LEGO build instructions for the stand but you should be able to create something yourself with reference to the pictures.
Next you will need to cut a hole in the side of the box. It has to be big enough for 2 cables to go through; the Pixy2 to LEGO cable and the USB cable for viewing PixyMon on the computer. The Pixy2 to LEGO cable is relatively short so you need to make sure it can reach from the Pixy2 to the brick.
Finishing the trapdoor and table top:
First you will need to cut a rectangle to be the trapdoor. If you followed my instructions exactly and didn't adjust the size of the balls then you should cut the same size. Cut a 63mm by 87mm rectangle out of 9mm ply. Then attach it to the LEGO with screws from the bottom of the trapdoor as per picture.
Next you will have to cut a rectangle in the table top to provide a place for the trapdoor to sit in so it is level with the table top. The following picture shows what you need to get to.
You will need to slide the table on a little so you can see how wide the trapdoor is on the table top. Mark a line so you know where the long edges will line up and then mark where the short edges will be. To create the hole, drill 4 holes inside the corners. Once you are finished that use a saw to cut between the 4 holes to create a rough rectangle. Remember that it is always better to start small and make it slightly bigger than make it too big. If you have access to a router, this will make it easier to cut nice straight lines. Make sure you keep checking if the trapdoor fits every time you cut it. You will need at least 2mm extra gap on all sides and maybe a little more at the end where the trapdoor drops.
Attaching magical boxes:
Before you attach the boxes you have to hide the internals. My boxes were dressed up using cardboard and cloth tape. You can then add things like glitter and rhinestones if you want to make you boxes a bit MORE magical.
Next you have to attach the boxes to the table top. To do this place them in the right position on the table top. The left box needs to have the cut rectangle inside it and the right one has to be in line but with a gap between them. When you are happy with the positioning screw them in using holes in the axle connectors.
Connecting the cables:
Now that all the woodwork is in place, it is time to wire up the robot. Connect the cables as follows:
- A - Box 1 (one on the left)
- B - Box 2 (one on the right)
- C - Trapdoor Catch
- D - Trapdoor
- 1 - Pixy2 (special cable supplied with Pixy2 LEGO)
- 2 - not used
- 3 - Touch sensor on Box 1
- 4 - Touch sensor on Box 2
I strongly suggest labelling the cables in case you need to pull things apart and put it back together again.
Magical Box robotBuild the LEGO:
Again I have included build instructions using Bricklink's Studio 2.0 software. You will find the files under the schematics section:
- Seesaw - this is the mechanism which tips the right ball onto the ramp. In the model there is only one side of these. You need to make a mirror image model of this for the opposite side. Usually the colours aren't important but the colours in the buckets helps to know which ball goes in each one. Note: I didn't have pink beams so used red instead for the bucket holding the pink ball.
- Ramp & drawbridge - this is the ramp the balls roll down to get into the magical box.
- Magical Box 3 - you need to build a box identical to the ones on the Trapdoor table. There are some additions listed in the build instructions below (Build base for Magical Box 3)
Build Magical Box table base:
The woodwork for the Magical Box robot is similar to the Trapdoor and fortunately simpler! Start by cutting a rectangular base of 480mm by 300mm using 9mm ply. Cut 6 rails 300mm by 30mm using 18mm ply. Attach one rail to the base in line with one of the short edges using 3 screws. Attach a second rail to the base 80mm in from the other short edge using 3 screws. You should still have 4 rails left.
To make it easier to take the top off, the legs are attached to the base. Cut 4 legs 210mm by 30mm of 18mm ply. Attach them vertically to the inside of the rails using 2 screws for each leg. Attach 2 rails to the inside of the legs at the top with 1 screw going into each leg.
Build Magical Box table top:
Cut a rectangular top of 400mm by 300mm using 9mm ply. Attach the 2 leftover rails to the underside of the top in line with the short edges with 3 screws. The top should fit neatly onto the outside edges of the legs from the base.
Attach LEGO:
Create a platform using a 100mm by 210mm out of 18mm ply. Screw the ramp and drawbridge onto it using the spare holes. You will notice the ramp will have a slight slope for the ball to roll down. Arrange the LEGO by attaching the first seesaw using the frame holes. Then attach the ramp making sure that the balls tip onto it and they roll freely down the ramp without hitting the ends of the buckets. Attach the second seesaw the same as the first ones also checking the ball can roll freely. I also have some beams attached screwed into the base that the EV3 connects into.
Build base for Magical Box 3:
Using scrap wood, make a base for the Magical Box. You need to make sure there is enough room for the drawbridge to rest gently on the edge of the box when it is fully lowered (i.e. check height and distance from ramp). Next attach the boxes the same way as the ones on the tabletop. Ensure there is a hole for stuffing to sit in to make sure the ball doesn't bounce out. You can refer to my photos to create a base that suits your build.
Connecting the cables
Now that all the woodwork is in place, it is time to wire up the robot. Connect the cables as follows:
- A - Seesaw for Blue and Green balls
- B - Seesaw for Blue and Green balls
- C - Box 3
- D - Drawbridge
- 1 - not used
- 2 - not used
- 3 - Touch sensor on Box 3
- 4 - Touch sensor on Drawbridge
Build the LEGO:
You will find a LEGO build instruction file under the schematics section:
- Revealer - this is the robot that will push the sign forward to make it drop and reveal the Legendary LEGO MINDSTORMS EV3 brick.
There are also a few pieces to attach the wheels and motors to the leg but you can look at the photos below to work it out.
Buildingthe woodwork:
Cut a 300mm by 400mm piece out of 9mm ply for the tabletop. Then cut 4 rails 300mm x 30mm of 18mm ply. Attach 2 rails in line with both of the short edges of the top with 3 screws.
Next cut 4 legs 160mm x 30mm of 18mm ply. Attach them to the end of the inside of the rails with 2 screws in each leg. Attach the wheels to the rail similar to the photos. Make sure you have enough room for the wheels to not hit the box as they move along. We had to put the rear motorised wheels on the outside of the rail to allow for this.
Once they are attached to the rail, you need to screw the rail into the outside of the legs. It is important that the Revealer tabletop is level with the Magical Box tabletop. When you are happy use 1 screw in each leg (if you are unsure about this refer to the photos).
Attach LEGO:
The LEGO is attached to the tabletop using some free holes. The measurement is not important, I just made sure the sign was centred over the table.
The sign is just an A4 bit of paper stuck to cardboard.
Connecting the cables
Now that all the woodwork is in place, it is time to wire up the robot. Connect the cables as follows:
- A - Front motor
- B - Back motor
- C - not used
- D - Sign
Note: you might need to use longer cables for A & B. I used 1m cables.
There are no sensors for this robot.
Configuring the Pixy2 cameraIf you haven't used a Pixy2 camera before, there is lots of great information on their website: https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:start
I'll try to focus on the things specifically needed for this project. The Pixy2 camera requires configuration to make it work. To connect to the EV3, you will need the special Pixy2 LEGO cable which is available either in the "Pixy2 for LEGO" pack or sold separately.
Update firmware
The Using Pixy/Pixy2 camera for LEGO Mindstorms on the ev3dev site explains that you must use the standard firmware on the Pixy2 camera instead of the LEGO firmware when using it with ev3dev. If you bought a Pixy2 for LEGO pack, then it is likely it came with the LEGO firmware. To change:
- Download the latest Pixy2 general firmware (i.e. not LEGO firmware) from here: https://pixycam.com/downloads-pixy2/
- Update the firmware on the Pixy2 using these instructions: https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:uploading_new_firmware
Configuring for use with ev3dev
Next follow the instruction on Using Pixy/Pixy2 camera for LEGO Mindstorms to configure the Pixy2 so ev3dev can connect to it. Make sure you follow the Pixy2 instructions not the ones for the previous version.
Configuring white balance
The Pixy2 comes with the ability to automatically adjust to lighting in a room. This is called "auto white balance". Given the colour detection will occur in a dark box with very little external light (i.e. only using the light from the Pixy2 itself), you can turn off this setting to ensure consistent results. Using PixyMon, go to the Configure dialog and then Camera tab. Ensure that "Auto White Balance" and "Auto White Balance on power-up" are turned off (the latter is often turned on by default with new Pixy2 cameras).
Teach the colours to Pixy2
We are now ready to teach Pixy2 the ball colours. You need to assign each colour to a "signature" number. I did mine in alphabetical order to make it easier to remember which was which i.e. 1 = Blue, 2 = Green, 3 = Pink, 4 = Purple. It doesn't matter how you number them as long as you use this consistently in your code. Note: you can assign labels to each signature (Signatute Labels tab in Configure dialog) but this is only useful when viewing in PixyMon.
For each ball, place it into the box and close the lid so lighting is similar to what it will be in normal operation. Using the PixyMon menu, select Action and then Toggle Lamp to turn on the light. You should be able to see your ball clearly. Follow the instructions in https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:teach_pixy_an_object_2#teaching-through-pixymon to teach the colour to the Pixy2 against your assigned signature number. Once done, repeat this step for the remaining balls.
Coding forthe Pixy2
I had only previously used LEGO blocks to code for the Pixy2 so this was a completely different experience for me. The Using Pixy/Pixy2 camera for LEGO Mindstorms page includes details on how to talk to the Pixy2 and get back results. It is quite tricky as it uses the Pixy2 serial protocol - I admit that I don't really know what this means but it was explained to me that it is the lowest level that you can use to communicate with the Pixy2 (e.g. when you use LEGO blocks they actually convert instructions into this serial protocol to make it easier for you). There was a lot of trial-and-error to get this working but fortunately I didn't have to do too much coding here. One trick here is that you have to turn on the lamp before the trapdoor so it can warm up before the ball drops down. If you don't do this then the light will not be bright enough by the time you check the colour so the Pixy2 won't be able to work out the right colour of the ball.
Here is a snippet of the code from the trapdoor Python program with most of the instructions related to the Pixy2:
bus = SMBus(3)
address = 0x54
# turn on lamp
data = [174, 193, 22, 2, 1, 1]
bus.write_i2c_block_data(address, 0, data)
# move catch and drop trapdoor
self.catch.on_for_degrees(speed=15,degrees=-25)
self.trapdoor.on_for_degrees(speed=5,degrees=75)
sleep(1)
# return catch and raise trapdoor
self.trapdoor.on_for_degrees(speed=25,degrees=-100)
self.catch.on_for_degrees(speed=25,degrees=25)
self.trapdoor.on_for_degrees(speed=20,degrees=25)
# find colour
data = [174, 193, 32, 2, 255, 1]
bus.write_i2c_block_data(address, 0, data)
block = bus.read_i2c_block_data(address, 0, 20)
logger.info("colour: " + str(block[6]))
# turn off lamp
data = [174, 193, 22, 2, 0, 0]
bus.write_i2c_block_data(address, 0, data)
# send colour to Alexa
self.send_custom_event('Custom.Mindstorms.Trapdoor', "ColourFound", {'colour': block[6]})
Configuring AlexaFor anyone attempting this project, it is assumed that you have already completed the setup and 4 missions in the LEGO MINDSTORMS Voice Challenge. This will give you a basic Alexa setup and understanding of how things work. I will just point out items specific to this project.
The documented missions use node.js for coding but I don't know how to code in this nor did I know Python. Given that I needed to learn Python for the ev3dev side, I was keen to instead use the Python option on the Alexa side. I found a post by Franklin Lobb which included a link to Python-based versions of mission 3 & 4. This was a great help as it meant I could focus on learning one new language rather than two. I have used some of the code from this as a base for my project. Given I am just learning Python, it is quite possible I have not written things as well as I could have or I might have code which I have just copied from somewhere else which is not actually needed. My apologies in advance - I was just really happy to get it working!
When you did the LEGO missions you already have an Amazon Developer account. You will need to configure Alexa in a way similar to what is in Mission 3 except:
- Create your Alexa skill. Create a new Alexa skill called 'Magic Show', pick the language that matches your Alexa device, select Custom model and select the method of hosting as Alexa-Hosted (Python).
- Enable the Custom Interface Controller. Do the same as mission 3.
- Define the Skill Interaction Model. There is a JSON file called Alexa Interaction Model under the Code section in my project. You need to use this file and do the same as in Mission 3.
- Implementing the Skill Logic. Find the file called Alexa lambda_function.py under the Code section in my project. Copy this and paste it into the Code tab in your new Alexa skill. Deploy and test.
For anyone attempting this project, it is assumed that you have already completed the setup and 4 missions in the LEGO MINDSTORMS Voice Challenge. This will give you a basic EV3 setup and understanding of how things work. I will just point out items specific to this project.
So you should already have ev3dev working on your EV3 and be using Visual Studio Code. You should also already know your Amazon ID and Alexa Gadget Secret. Do the following to get your Trapdoor EV3 running with my code:
- Download the files Trapdoor.ini and Trapdoor.py into a folder and then open them in Visual Studio Code.
- Change the Trapdoor.ini file to include your Amazon ID and Alexa Gadget Secret.
- Within Visual Studio Code, send the workspace to the device and run Trapdoor.py
- For the first time only, you will need to follow the pairing instructions as per the missions.
Repeat the same for:
- Magical Box EV3 using magicalbox.ini and magicalbox.py
- Revealer EV3 using revealer.ini and revealer.py
Your EV3s should now be running the correct programs so you are now ready to try out the project.
Working with multiple robotsOne of the tricky things of my project is working with multiple robots whereas the sample projects only have one robot each. The problems included:
- Knowing which robot was which; and
- Sending information from one robot to another.
Knowing which robot was which:
I found that the sample code I had actually returns all the endpoints but was just using the first one. Sometimes the first one found would be different, possibly dependent on when they connect to the Echo device.
I was able to workaround this by giving each EV3 a different value in the given.ini file under [GadgetCapabilities]. Here is the value in trapdoor.ini:
[GadgetCapabilities]
Custom.Mindstorms.Trapdoor = 1.0
When Alexa connects to each EV3, it gets data on each endpoint which includes the [GadgetCapabilities] value under a tag called "interface". By checking the value, I was able to know which endpoint was which robot. I then stored these in session attributes for use in communicating directives to specific robots during the show. Here is a snippet of code from the Alexa skill:
system = handler_input.request_envelope.context.system
api_access_token = system.api_access_token
api_endpoint = system.api_endpoint
# Get connected gadget endpoint ID.
endpoints = get_connected_endpoints(api_endpoint, api_access_token)
logger.debug("Checking endpoint..")
if not endpoints:
logger.debug("No connected gadget endpoints available.")
return (handler_input.response_builder
.speak("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.")
.set_should_end_session(True)
.response)
# Store endpoint ID for using it to send custom directives later.
session_attr = handler_input.attributes_manager.session_attributes
for ep in endpoints:
if ep["capabilities"][0]["interface"] == "Custom.Mindstorms.Trapdoor":
session_attr["endpoint_trapdoor"] = ep["endpointId"]
elif ep["capabilities"][0]["interface"] == "Custom.Mindstorms.MagicalBox":
session_attr["endpoint_magicalbox"] = ep["endpointId"]
elif ep["capabilities"][0]["interface"] == "Custom.Mindstorms.Revealer":
session_attr["endpoint_revealer"] = ep["endpointId"]
Sending informationfrom one robot to another:
For my project, I wanted to send the colour found by the Trapdoor robot to the Magical Box robot. I used to the Mission 4 example (and Franklin Lobb's Python version) to work out how to do it.
The first part was:
- Sending the colour from the Trapdoor EV3 to Alexa using an 'event'
# send colour to Alexa
self.send_custom_event('Custom.Mindstorms.Trapdoor', "ColourFound", {'colour': block[6]})
- Catching the event in my Alexa skill code and storing it in a session attribute
def events_received_request_handler(handler_input: HandlerInput):
logger.info("== Received Custom Event ==")
custom_event = handler_input.request_envelope.request.events[0]
payload = custom_event.payload
name = custom_event.header.name
speak_output = ""
if name == "ColourFound":
session_attr = handler_input.attributes_manager.session_attributes
colour = int(payload.get("colour"))
session_attr["colour"] = colour
Then, as part of a later intent, I was able to:
- Get the colour from my session attribute.
- Send the colour in the payload of a directive to the Magical Box EV3.
session_attr = handler_input.attributes_manager.session_attributes
colour = session_attr.get("colour", 3)
endpoint_id = session_attr.get("endpoint_magicalbox", [])
payload = {
"colour": colour
}
directive = build_send_directive(NAMESPACE_MagicalBox, "seesaw", endpoint_id, payload)
There is more code on the Alexa side to handle events, a lot of which I just copied from example projects. I expect there is some stuff that doesn't do anything and could be removed but I didn't want to risk that it would break my project!
Begin Magic Show!Say "Alexa begin magic show" to start and then follow this running sheet to complete the show. Make sure to watch the video to see how the show works. Note: When box 2 opens it says the colour of the ball that you put in RANDOMLY. The same coloured ball will then appear in box3.
I'm really happy with how my project turned out but there are some things that I could improve on with more time and knowledge:
- This project was challenging for me because I coded using Python for the first time. I could have definitely simplified some of the code so take care just copying what I have done.
- I have made a LEGO model for all of my robots. Unfortunately I haven't had time to make step by step instructions but you will be able to build them by referring to the models.
- To make this skill better, I could get Alexa to keep track of which step we are up to using session attributes. However I found it was easier for when I was testing to be able to do them in any sequence.
Comments