Wednesday, August 21, 2013

Marble Maze: The makening

A quick, hopefully simple guide on how to make a servo controlled marble maze!  Pictures for each step will hopefully be coming soon, once I get a chance to take some photos.

Materials Needed:


1x Wooden Marble Labyrinth
2x HiTec 322HD servos
1x 2.5x5.5mm barrel jack
1x 2x10 0.100" through hole male pin header
4x #8-32 x 1-1/2 inch machine screws
6x ~2.5 inch lengths of 0.100" diameter wire
6x pieces of electrically non-conducive heatshrink
Solder

Tools Needed:


Needle-nose pliers
Drill press
Power drill
Drill bits of various sizes
Phillips head screwdriver
Soldering iron
Heat gun (in a pinch, a hair dryer and a funnel)

Method:


The method for modifying the marble maze can be broken down into a series of relatively simple steps.  The control knobs will be removed from each axis, rotated around so that the flat side of the knob is facing away from the maze, the small wheel arm will be attached to the flat side of the control knob, and the servo will be attached to the box.  For the wiring, a 2x3 header is used.  On one side, the 3 pin connector from the servos will be attached.  On the other, wires will be soldered to connect power and ground to the DC power barrel jack, and power, ground, and pwm control signals to the Launchpad.  Step by step instructions for this process are as follows:
  1. Remove the control knobs from each rod:  Start with the knob on the x-axis.  Rotate the y-axis such that the edge of the maze nearest to the knob on the x-axis is tilted down as far as it can go.  Use the needle-nose pliers to stabilize the shaft and pull on the x-axis control knob.  The control knob is only secured to the shaft by friction, so it should pull off pretty easily.  The y-axis control knob is a bit harder to remove, as you can't tilt the board in such a fashion as to make an opening wide enough to get access to the shaft with the pliers.  If your pliers are small enough, you can use hole 34 or 36 to get access to the shaft.  Again, stabilize the shaft with the pliers and pull off the control knob
  2. Extend the mounting hole on the control knob:  Unfortunately, I didn't record what size drill bit was necessary for this step, but it is easy to determine.  Insert a drill bit that looks to be about the right size into the hole that rod used to occupy.  When you get to one that fits, use that drill bit on the drill press to extend the hole all the way through the control knob.
  3. Secure the small wheel arm to the control knob:  Use a 1/16" drill bit and the drill press to expand two of the holes that already exist on the small wheel arm.  Place the small wheel arm on the flat side of the control knob and use a pencil to mark the location of the expanded holes.  Use a drill press and the 1/16" drill bit to drill all the way through the control knob.  Use two of the servo mounting screws that came with the 322HD to secure the small wheel arm to the control knob.  Be careful with this step, as it is very easy to strip the heads of the servo mounting screws.
  4. Reattach the control knob to the marble maze:  Again starting with the x-axis, use the pliers to stabilize the rod and push the control knob onto the rod with the flat side (which now has the small wheel arm attached) facing outward.  Note that there is a flange on the rod that keeps the rod from extending too far outside of the marble maze housing.  Use the pliers to make sure this flange is snug against the wall of the maze.  Repeat this process for the y-axis, again using hole 34 or 36 to get access to the rod on the y-axis.
  5. Secure the servo to the marble maze:  The small karbonite gear on the HD322 should easily click into the small wheel arm that is now connected to the control knob.  Rotate the servo such that the wiring coming out of it is pointed towards the ball return of the marble maze.  Attach the 1/16" drill bit to the power drill.  Make sure the servo is level, and use one of the four mounting brackets on the servo as a guide to drill a hole into the side of the marble maze, making sure to drill all the way through the wall.  This will create a hole that is slightly smaller in width than the #8-32 machine screws.  Line the servo up with the hole, then use a hand screwdriver to screw one of the #8-32 machine screws into the hole.  It is important to use a 1-1/2" screw here, as you need to get the head of the screw flush with the mounting hole of the servo, but if the screw extends past the wall on the interior of the marble maze, it will limit the range of motion on that axis.  Now that the servo is held in place with one screw, use mounting bracket as a guide again and drill a second hole into the box, then a second #8-32 machine screw to affix the servo to the side of the box.  Repeat this process for the second servo.
  6. Wire the servo to the Launchpad and barrel jack:  Snip off a 2x3 section of the 0.100" pitch male pin header block.  Solder a wire to electrically short the two columns of the first row.  This will be used to create a four point node for connecting ground from the DC barrel jack to the launchpad and servos.  Solder a wire to electrically short the two columns of the second row.  This will be used to create a four point node for connecting 5V from the DC barrel jack to the launchpad and servos.  Solder a wire to connect ground from the barrel jack to the column one, row one of the header.  Solder a wire with a 0.100" pitch to column two, row one of the header.  Solder a wire to connect the tip of the barrel jack (5V) to column one, row two of the header.  Solder a wire with a 0.100" pitch to column two, row two of the header.  Solder a wire with a 0.100" pitch to column one, row three of the header.  Solder a wire with a 0.100" pitch to column two, row three of the header.  If possible, use an electrically non-conductive heat shrink on each solder joint to ensure that you don't accidentally short 5V to ground, the two PWM signals to each other, or the PWM signals to 5V.  Connect the wire at column two, row one of the header to either pin 1 of J2 or pin 2 of J3 on the bottom (female portion) of the launchpad XL header (GND).  Conenct the wire at column two, row two of the header to pin 1 of J3 on the bottom (female portion) of the launchpad XL header (VBUS, which is 5V).  Connect the wire at column one, row three of the header to pin 3 of J3 on the bottom of the launchpad (PD0, pwm for y-axis).  Connect the wire at column two, row three of the header to pin 4 of J3 on the bottom of the launchpad (PD1, pwm for x-axis).  Connect the three pin connector from the servo on the y-axis to column one of the header such that the black wire is on row one, the red wire is on row two, and the yellow wire is on row three.  Connect the three pin connector from the servo on the x-axis to column two of the header such that the black wire is on row one, the red wire is on row two, and the yellow wire is on row three.
  7. Calibrate the servo:  Unscrew the machine screws and detach the servo from both control knobs.  Plug in the launchpad (and program it if you have not already done so).  On startup, the launchpad will set the servo to its 90 degree position.  Manually move the control knob for each axis so that the marble maze is level.  With the launchpad still on (which will hold the servo at 90 degrees), reattach the karbonite gear of the servo to the control knob, taking care to keep the maze level while doing so.  Reattach the servo to the maze using the machine screws.  The 90 degree position of the servos should now correlate to a position in which the marble maze is level on each axis.
You now have a fully functional, launchpad and servo controlled marble maze!

Tuesday, August 6, 2013

Amazing Sensors!

A new project!

Lately, I've been working with different sensors as part of my day job at TI.  TI happens to have recently released a booster pack for the Stellaris and Tiva launchpads that contains (among other things) an accelerometer, a gyroscope, and a magnetometer.  I figured I'd use my recent experience to do something fun with sensors in my free time :)


Using only the highest quality cell phone cameras and engineering studio production values, I made a quick video describing the system and showing it in action

Project Overview


  • Accelerometer, gyroscope, and magnetometer fused via direct cosine matrix to observe roll, pitch, and yaw of hand held transmitter
  • RemoTI software stack used to pair and transmit data over Zigbee RF4CE protocol between transmitter and receiver
  • Software generated PWM signal used to control servos attached to X and Y axis of marble maze based on roll and pitch data received
  • Source code and bill of materials can be found on my github

Hardware

The key piece of hardware that made this project possible was the SensorHub Booster Pack.  The booster pack comes with an MPU 9150, which provides 3-axis data from a gyroscope, an accelerometer, and a magnetometer.  The communication between the MCU and these sensors is handled with an interrupt driven I2C interface.

An additional bonus of using the SensorHub booster pack is that it was designed to contain a set of EM headers.  For this project, I connected a CC2533 radio transceiver to those headers, which enables short range (~5 meters) radio communication between two modules.  It was a bit tricky to set up the CC2533, as there was not a plethora of sample code for using it in conjunction with a Stellaris, but fortunately I was able to find a spare development kit that made learning and debugging the radio interface much easier.

The final hardware component was the marble maze itself.  I actually was able to find this already pre-fabricated.  A TI field engineer did a project very similar to this, but using the accelerometer on an msp430 Chronos watch and an lm3s9b96 for the maze control.  Unfortunately, that demo was starting to show its age: it used the SimpliciTI stack for wireless communication, which is no longer supported, the 9b96 was from back when the Stellaris line was controlled by Luminary Micro, meaning it had no Texas Instruments branding, and the 9b96 used for the PWM control is part of the now, sadly, NRND'd m3 line.  As a result of these factors, the demo was languishing in a marketing office, and hadn't been used for a trade show in years :(

Software

Once I procured the hardware, I set about to looking for example code.  I came across a project a coworker of mine created, the wireless air mouse demo, that was a great help.

The sensor communication was the easiest part to cover (due in no small part to the fact that I've spent the past year and change working with these exact same sensors for a different project within TI).  TI has a really great sensor library that is available in the current Tivaware C series release that handles a large part of the sensor functionality.  The air mouse demo already handled taking the sensor data and feeding it into a direct cosine matrix, which generates the eigenvectors needed to determine the roll, pitch, and yaw of the device at a given time.  Once I had this data being reliably generated, I moved on to the radio transmission portion of the code.

The radio portion of the project was by far the most difficult.  I opted to use the RemoTI RF4CE software stack, because a) that's what the air mouse demo used, and b) it sounded like an interesting topic to learn more about.  The RF4CE protocol basically classifies each node on the RF network as being either a target or a controller, and sets up a very robust algorithm for pairing and sending data between two devices.  Unfortunately, the airmouse demo only covered the controller side of the code; for that demo a CC2531 USB dongle was used to handle the target side of the communication, the source code for which I was unable to find.  It took a few weeks of reading up on the RemoTI documentation and learning about how the on board MCU on the CC2533 works, but I was eventually able to get a hello world program running, which quickly gave way to transferring roll, pitch, and yaw data from the hand held controller down to the maze controlling target.

The servo communication was fairly straightforward: each is controller by a pulse width modulated signal with a base of 20 ms and an active time of between 1 and 2 ms to rotate it to either extreme.  I was hoping to use a Tiva Launchpad for this purpose, as it contains a hardware PWM module, but I was not able to find one lying around the lab, so I opted to just use a general purpose timer to create a software based PWM signal for the servos.  Once I had roll and pitch data coming over the radio interface, all I had to do was to normalize the rotation between -1 and 1, use that to generate an active time for the PWM, and generate the signal.  I ended up adding a multiplier to each axis to get the demo to make a bit more sense, as the launchad is longer along the Y axis than it is the X axis, so it takes a greater effort to change the pitch on the board than it does the roll.  As a result, without a different multiplier on each axis, the controller gave the impression that it required more effort to get the board to move in the Y axis than it did to get the same motion on the X axis.

As always, the source code for this project can be found on my github.

Future Steps

I have a few ideas for where to go from here, but nothing concrete on the horizon.  My first thought was that it would be really easy to modify this code to instead control a POV camera gimble.  Something like using the target side MCU to control a gimble that has a go-pro attached to sync the camera movement to the movement of a launchpad attached to a hat.  Then maybe finding a way to stream a low res version of that video to an RC car or quadcopter to allow for POV control of the remote vehicle without requiring line of sight.  Still thinking about what hardware would be ideal for this, maybe giving me an excuse to buy a beaglebone black.  For now, though, I'm quite happy with my little marble maze demo :)