Introduction: Portal 2 Turret Gun

--- CARA MIA! - Master Turret Control is here!! ---

Check out the Master Turret Control. A way to control you Turret gun! Control multiple turrets with a single controller.

Portal-2-Turret-Master-Turret-Control

This Christmas, I decided to design and build a working Portal turret gun from the game

Portal 2. For me, this was an exercise of properly modelling the entire assembly in Fusion 360 first, before building anything. This design uses an Arduino Nano, an MP3 player chip, distance sensor, servos, LEDs and 3D printed parts.

The goal here was to make it move in 3 "axes", with spoken sound from the game and LED's to simulate firing.

- Open the "wings" if it senses someone in front. Use a crank mechanism with sliders, just because.

- If the person is still there after opening, fire until they drop. LED's and machine gun sound.

- If the person is no longer there, run a little scanning search routine.

- Close up and go to sleep until someone else comes along.

- Use Portal turret sounds and voices from the game.

I took some liberties in the design, trying to make it appreciably the same as the one seen in the game, but functional and printable. With some basic sketches found online, I started modelling and planning...

The sounds are stored on a microSD card, which is accessible from the back side so that sounds may be updated or changed later. It is inline with the black infill strip, making it essentially invisible once installed. 18 individual expressions and sounds used in this go-round.

The lidar sensor (time-of-flight) is on a chip with a rectangular profile. This sensor is nearly invisible from the front once assembled.

Step 1: Fusion 360 Modelling

The design started from sketches found online. Using these images as canvases, I started sketching the outlines of the 3 views. Then it was a matter of extruding them into 3D, then shelling the general shape and making cuts. All electronics were built in Fusion as components that were inserted and placed where I thought it would make sense. Driving parameters were:

  • Arduino Nano had to have connector accessible for updating once fully assembled
  • MicroSD card had to be accessible in the same manner, and ideally invisible once installed
  • Time-of-flight sensor should be invisible as well
  • A 2.1mm electrical connector for power at the back
  • Printed parts to be as large as possible (not a lot of little pieces)
  • Print with no supports

After components (Nano, other chips, servos) were added to the basic shape, they were moved around and positioned as required, and the supporting structures were built to support them inside the shell.

The wing opening mechanism was a crank and slide mechanism. Why? Because I wanted to use a crank mechanism, that's why! This added some complications, but it also had a benefit; once the geometry was determined, operational repeatability would be ensured and the min and max limits were pretty much guaranteed.

Once the entire model was built and I was confident that it would work, and could be built (printed) and assembled, I went ahead and printed out the parts and built a prototype. Once that worked out, I went back to the model and made some tweaks to improve appearance and assemblability (is that a word?). This model is what came of those changes.

This was pretty taxing, as there really aren't many boxy shapes in this thing, and it closes up pretty tightly, with no real access for tweaking once put together. I learned quite a bit on this project, such as using embedded components within other components. This made manipulating and keeping sub-assemblies linked for quick access. In the end, it was worth the effort!

As for videos guides on Fusion 360, I'd recommend Lars Christensen's YouTube channel.

https://www.youtube.com/results?search_query=lars+...

I found Lars' channel along with other videos to be very helpful in coming up with new ideas and using features effectively in Fusion.

Step 2: 3D Printed Parts

Portal turret v4.zip is updated and should contain all printed parts needed to build the latest turret.

--- new "Rear test Leg". Not true to original, but it's at the back, and allows one to use a straight mini-USB connector straight up. ---

V4 parts (body and wings shown in RED) have been revised to reduce the bridge size in the body when printing and have virtually eliminated the "bump" on the front face, over the eye. This required modifying the wings to fit in the revised shell, and also required a revised pitch frame. I've also updated the infill strips to be consistently thin, and reduced the width by a hair. This makes putting it together much easier. I've also included a revised rear leg which is stretched a bit, allowing more room for the plug connector at the back.

These were printed on a Prusa Mk2, using PLA for all parts. The print orientation should be pretty evident. The body was printed in the vertical position, with no supports. There is the large gap in the sides that has to be bridged, but I really had no big issues with pretty standard settings, other than the bump. The bump on the front and rear can be virtually eliminated with good filament and some good print settings. I found that 0.2mm worked well in the slicer and produced a decent result. Any larger and openings started appearing in the body near the infill strip.

The design of channels and protrusions were done with 45 degree chamfers, so "hanging in space" elements will be minimal.

I had little cleanup to do to put the assembly together. The infill strips that slide into the channels are now pretty straightforward, with reduced width and consistent thickness. I think that one could use a thin, black material cut into strips instead of using these printed pieces (printed on edge).

The one area that does require finesse is the slider pins in the pitch frame. Straight pins (nails) in the bore holes that are chased with a 1/8" drill bit and some lube will go a long way.

Step 3: Components

V4 (Red turret) has smaller bridging, requiring v4 wings and Pitch frame.

Once the model was complete, and I was happy with my prototype, I printed rev 2 with the plastic components as shown. Everything here is PLA, with Black and design colour (Blue in this case), and a tiny bit of translucent PLA for the central "Lens" or laser eye.

This photo pretty well captures the components, with the exception of the wiring.

Step 4: Electronics

The build uses the following components:

  • Arduino Nano (1)
  • DFPlayer Mini MP3 player (or MP3-TF-16P) (1)
  • VL53L0X Time-of-Flight Ranging Sensor (1)
  • Generic SG90 micro servos (3)
  • 5mm red LEDs (5)
  • 220 Ohm resistors for LEDs (5)
  • 1kOhm resistor (1)
  • 4cm speaker, 4Ohm, 3 Watt (1)
  • 2.1mm power connector (1)
  • 3" long framing nails (4)
  • M2 x 6 screws (8)
  • M2.5 x 8 screws (2)
  • M3 x 8 screws (4)
  • M3 x 12 screws (4)
  • M3 x 16 screws (2)
  • shrink wrap
  • small tie wraps

All components are readily available from Amazon or Banggood and other sources.

The screws were sourced from an assortment kit. It's a pain in the butt to get them otherwise...

Step 5: Mechanical Assembly

Most of the mechanically assembly is reasonable. The printed parts are printed with the holes tapped where necessary, so a quick chase with a screw before final assembly will be helpful and made assembly of the screwed components pretty easy.

The Arduino and the MP3 chip snap into the cradle without hardware. The VL53LOX will slip into the front shell without fasteners. Trial fit first, then remove and install once wired up.

The slider assembly uses 4 framing nails as slider rails. They are about 1/8" in diameter, with the heads clipped. These were taken from a strip of DeWalt framing nails used with their electric framing nailer. Needless to say, smooth nails are a must.

The servos mount as shown. Orientation is important. The pitch and the pivot servos are "centred" when installing into their pieces. The crank is installed such that, when in the open position, it will close by rotating counter-clockwise direction, when viewing from the front. Open position is rods and crank straight in line, with another 10 degrees rotation till lock.

The leg assembly is the easiest part. 2-2.5mm screws, with the leg caps snapping over the elbows of each leg. Use fasteners than don't protrude above the top of the leg plate. That way, the pivoting body won't bind if you tweak the rotation range.

All servo connections to printed parts are made using the short white crank that comes with the servos. These cranks just press into the printed parts. I tried printing the splined bore in the parts that connected to each servo, but had limited, repeatable success. Much easier using the cranks that come with the servos.

The crank assembly uses the longer 2.5mm screws. The crank rods should not be squeezed between the crank halves. In fact, you could try using shorter screws without the Crank2 part. That should work as well (hopefully no appreciable torque here if the wings slide freely).

The speaker is captured by a servo mount (2 pieces) which capture the speaker. Speaker between these "legs", and held in position by securing them to the pitch servo. This servo then connected to the pitch (slider) assembly, followed by the crank assembly with rods. All of this is assembled before being installed in the LHS body with 4 small screws.

Once the main guts are installed, with the Arduino and MP3 player temporarily located, then the fun begins - wiring!

Step 6: Wiring

V5 - Radio option (Red turret photos). This includes an nRF24L01 radio chip. Completely changes the Arduino pin wiring to accommodate all the connections. Details to come...

The final packaging is tight, so spending some time here figuring out wire lengths is well worth it. Most interconnecting wires I ended up with were between 3" - 4".

The LEDs are wired with the 220 Ohm resistors directly, followed by some shrink wrap, and some wiring twisting, then put aside, after they have been tested. I used light gauge wiring here as I had some lying around (CAT5 type communication wiring) and didn't want the visible wiring to be obtrusive.

The mechanical bits are mock fit in the shell, then wire routing is figured out, then cutting and prepping the wires is next.

I built the servo connectors so that I could plug in and replace servos if I ever messed something up and stripped the gears. This was definitely helpful after messing up during my first prototype.

Once happy with the bulk of the wiring, the LEDs were soldered up at the end. Then it's time to carefully stuff the wired assembly into one half of the shell. The last step is to solder the power connector to the power wires once it is all inside.

-- Important note: Make sure the wiring stuffed behind the Nano are not pressing on the reset button!! This will obviously cause problems and prevent the unit from operating properly. --

At this point, all wiring is done, but before final assembly, it is important to upload the code to the Nano and power it up to make sure the LEDs, servos and MP3 player all worked as designed. After that, it's time to put the rest of the mechanical bits together.

Step 7: Arduino Code

Code for Radio turret now shown. Will still work without MTC, but has all the goodies baked in!

The attached file is what I came up with to drive the unit as shown in the videos. I will keep tweaking to change the Turret's character and the way it behaves. Lots of options here.

I structured the code using subroutines that I call as needed. It keeps the main body clean and was pretty helpful when I was playing around with different characteristics. It helped me manipulate the code for different behaviours.

I also used lots of variables up front which helped me tweak and adjust parking positions and min and max ranges, for example.

I used the DFMiniMP3 library in my code. I tried other libraries, like the DFRobot one, but had issues, so went back to this one. It meant that I had to keep the 'static void' pieces to keep it functional. These aren't necessary for the operation, but hey, I'm no master coder. I would love to hear of another library that is similarly as simple and neat as the VL53LOX library. Let me know if you find a better way to do this!

As for sounds, the implementation is done in a simple way, by having a folder named "mp3" on the SD card, with the files names 0001.mp3, 0002.mp3, etc. The first four digits must be in this format, but you can add any suffix after that to help identify the particular sounds. See https://www.dfrobot.com/blog-277.html for an example. I've included a pic of my file names as used on the folder. The numbers correspond to the call-outs in the code.

The sound files I pulled from the Wikipedia page on Portal Turret sounds. The code pics a random sound file (1 of 2, or 3 sounds) to keep things from getting stale.

Would love to hear or see cool implementations of other code. One idea I think I might try is to interconnect 2 or 3 of them wirelessly, such that triggering one turret will make them all wake up! Maybe adding a simple RF chip to the assembly? There's still some room in there... :)

Step 8: Final Body Assembly

This part is a bit tricky because of the black infill strips. The scale of the final assembly is small enough such that the strips and receiving grooves are tiny. This necessitated chasing the channel with a pointer or other small scraping implement to make sure the strips would fit with little resistance before trying to put the other side on.

Tying the wires together neatly and tie-wrapping as required will make this far easier.

I have put a couple of these together now and find it easier to put the two halves together first, then insert the infill strips. Insert one side into the half with the "shelf" that prevents the infill strip from falling in, then lightly pry open and gently press in. Not too bad now.

This was one of the trickier parts. Maybe one day, I'll rethink this assembly, but I do like the way it looks when done, and it is pretty robust.

Step 9: Wing Assemblies

Now that the body is together, with the wing LEDs sticking out, it is time to prep the wings and assemble.

It is imperative that the slider holes are chased with a 1/8" drill bit, then cleaned out. Clip the heads off the nails using bolt cutters, vise-grips, hacksaw or favorite nail-cutting tool. The slider pins (clipped nails) are installed into the wings by press fitting them into each wing piece. Straight, de-burred and smoothed nails are the key to making this work. The wing sliders and holes should be lubricated and tested before connecting the crank rods and running. Dry graphite, or other PLA suitable lubricant is recommended. I find that a small tube of personal lubricant works really well, and is cheap. It's really slick. It also requires for some 'splainin' when your partner or parent comes in and asks what exactly you need that for at the workbench!!

Start by figuring out which wing part goes where, and trial sliding that part first. Then fit the top and bottom halves together once the pins are installed, apply some lubricant (a q-tip works well for this) and make sure the wings slide well. This can be tricky, but without making sure the wings slide effortlessly, without binding, you'll be in for a frustrating time. Trust me...

Once the wings are good to go, it's just a matter of sliding them into place, locating the connecting rod over the hole in the wing and assembling with a single screw. Then, the LEDs are inserted into the gun holes, wires are tucked against the wing and you're ready to go! You can also use some hot glue to lock them into place once everything is tested.

Step 10: Scare and Shock Your Friends!!

The last little caveat on this design is that an angled plug is a great idea, since it doesn't interfere with the back leg when pivoting. The revised rear leg (v3) has been stretched to give a little more room.

Once built and plugged in (5V or suitable for Nano), it will sit quietly until someone is detected within the programmed distance, then spring to life and slay anyone who enters its domain!!

Let me know if you build one (or more) and if you come up with new features or concepts!

Step 11:

Toys Contest

Grand Prize in the
Toys Contest