Monday, September 3, 2012

Quick diversion: how to use ngx-queue

In my last blog post, I noted that I was working on Reflecta which is a communications protocol for talking from a PC to an Arduino.  I also alluded to the fact that I was using Reflecta from nodejs.  When I controlled RocketBot during Maker Faire, the logic was half Arduino and half C#.  A Windows app was running on a netbook receiving input from an XBox controller and the Arduino, making decisions, and sending commands down to the Arduino.  Since then I've been rewriting this logic in Javascript on the nodejs platform principally so I can move my control app from a netbook to low power computer such as a BeagleBone, Raspberry Pi, or Nexus 7 tablet.  Nodejs is a great choice because it's a functional/reactive programming environment that suites robotics well and it is small, efficient, and portable.

Nodejs is a combination of a few different technologies.  At its core is the V8 Javascript engine supplemented by a series of libraries written in C/C++ which access OS APIs such as sockets, filesystems, etc. to give you the power to talk to hardware directly and escape the javascript sandbox.  The C/C++ libraries are written in a style similar to what you see in other high reliability OS development which means no exceptions, no class hierarchies, and a lot of 'Use the Source, Luke'.

Lately I've been hammering on Reflecta, working out bugs and ensuring I have rock solid communications between the host and the Arduino.  One issue I recently ran into is when nodejs talks to the Serial Port (AKA Arduino) via the node-serialport library, occasionally it will send the data out of order.  Fixing this required me to learn the details of how nodejs buffers data for asynchronous, in order sending.  Nodejs leverages part of the nginx source code for handling queues of data in this case -- coded up in ngx-queue.h.  ngx-queue.h is a little strange compared to other queues in that you don't 'add your data to the queue entry'.  Instead you create a struct containing your data and the queue entry and then add the struct's queue entry to the queue.  This is an effective way to make a 'generic' or 'templated' queuing API using simple pointer logic.

Since it took me a few hours to figure out from the source code and example usages inside of nodejs, I figured someone else might benefit from the sample I created while learning so I created a Github Gist of it.  To compile, you'll need nodejs, npm, and node-gyp installed since that is the C++ build environment the sample uses.  Run 'node-gyp configure' and 'node-gyp build' to compile.

Friday, August 10, 2012

Much work on RocketBot and Reflecta

I've been busy updating the source code and design documentation for Rocket Bot.  You can now find:

I'm continuing to improve the documentation, samples, and unit tests.  The documentation is still in a bit rough shape due to the rapid changes I've been making to Reflecta over the past few weeks.  Things are finally settling down enough for me to start publicizing my work for other people to use.

My next project, after getting Rocket Bot documented well enough for other people to be able to reproduce my results, is to work on a high end 'inertial measurement unit' library for Arduino based around the Pololu MinIMU9v2 board.  Pololu has a great piece of hardware here and I'm excited to think about what I can do for RocketBot and other robots with such a great set of sensors.

Monday, August 6, 2012

RocketBot at Maker Faire 2012

RocketBot made appearances at Maker Faire San Mateo and Seattle.  The audience was great fun, especially the occasional 10 year old whiz kid who seemed to just have learned robotics and electronics from some form of osmosis.

Photos from the San Mateo booth


A better rocket

Carefully adding hot melt 
Ready to fire
Up and away!
It was a bit awkward trying to fire straw rockets with a range of about 75' in the very crowded fairgrounds at San Mateo.  Mostly we just aimed for trees and hoped for the best.  Over the course of two days at San Mateo, we only had one significant 'landed bonk on the top of the head, looked around angrily' incident.  To the dude in the 'Indiana Jones' hat who thought he was outsmarting the crowd by standing in the middle of the shrubbery to eat his hot dog -- I'm sorry.  Fortunately our range of 75' kept you scanning the fairgrounds for a perpetrator you thought was much, much closer so Mom was able to hurriedly shoo the five year old 'hawk-eye' sniper away before you figured things out :-)

As the day wore on, we took RocketBot on the road, navigating through crowds and following little children while surreptitiously hiding the wireless XBox controller behind our backs.  I immensely enjoyed playing a little 'interactive R2D2' with the kids and really wished I had worked more on the 'beepy sounds' and 'blinky lights'.  While the industrial warning light mounted on top was enough to get the crowd to part, the home made warning beeps (inventive use of Arduino tone(), a plastic drinking cup as a resonance chamber, and a small transistor amplifier) weren't loud enough for the crowd so it's time for more power there.

To those who come looking for the design diagrams and source code for RocketBot, I apologize for being late.  The source code for all of the robot Arduino logic is now up at https://github.com/JayBeavers/RocketBot.  I've rewritten it somewhat because as a programmer who writes code for a living I was a little embarrassed with things after a number of last minute 'hacks'.  The code is now in better shape and I've factored out the communications layer into a protocol I call 'Reflecta'.

I'm starting my notes on 'RocketBot v2' with a goal of making a number of changes for next year's Maker Faire.  High on the list are a better sound library using a dedicated sound synthesizer chip, considerably more 'blinky lights', and a drive control system which is 'safetied' so I can hand over control to all the kids who were begging to drive the robot themselves.  I've a few other changes in mind as well that I'll keep to myself until I see how they work out.

Thanks to the Maker community for having me.  I greatly enjoyed my first Maker Faires.  I'm looking forward to doing them again next year.  In the mean time, I'll be posting a bit more here as I continue to work on Reflecta and develop my CAD skills for publishing my schematics and laser cut parts.

 - jcb

Tuesday, April 10, 2012

Adding the launcher electronics

Time to wire everything up.  My first challenge was working out how to turn on the 12 volt 10 amp air compressor from an Arduino.  I have some Power MOSFETs, STP55NF06L, sitting in my shop from some previous research I did looking for a power solution for a Quadcopter.  These are more than sufficient to power the air compressor.

They turned out to be a bit more tricky than I thought getting the wiring correct.  I ended up getting help from a coworker, Jack Creasey, who understands the electronics side of things better than I.  It was nice working with Jack again, the last time we worked together was February in 2004 when we were building some early Windows PC robot prototypes.

The Festo valves are 12 volt so I also needed an amplifier for the Arduino digital out pins.  I was hoping to use some cheap transistors I had in stock,  the Fairchild PN2907A, but it turned out they didn't have the current to actuate the valves so I used two additional MOSFETs -- overkill I'm sure but it was what I had readily on hand.

The rest of the work it pretty straightforward Arduino tasks -- attaching an analog sensor & two servos.  

Circuit Diagram


Photo of the breadboard prototype

Joshua with the prototype

My son Joshua helped with the assembly, double checking all the steps and doing most of the soldering.  He impressed me with how much he has learned from working through his Make: Electronics book.  I haven't read through it yet, so I picked up a Kindle version for myself.

There's still some work left to do here -- I have a 12 volt industrial warning light that hasn't arrived yet and I have a coworker who's working on a potential design for a smoke generator.  Once I get this all locked down I'll look at moving it all over to a Maker Shield instead of a breadboard.  I don't think I'll need the breadboard for the Maker Faire booths, I'll probably stick to circuit diagrams to talk through the design there.


Tuesday, April 3, 2012

Putting the pneumatics together

While our project's genesis started from the Make Compressed Air Rocket design, I have a couple of design changes in mind.  The launcher needs to be miniaturized -- both because I want to use it indoors at Maker Faires and other events and also because I want it to fit on a robot.  I also want the launcher to be automatable, so the robot can autonomously hunt its prey -- er, I mean so it can safely launch the rocket from a distance.  Automating the launch will also help us 'tell the story' -- with countdown lights, warning buzzers, etc.

I decided to start from the FIRST 2012 Pneumatic Base Kit -- primarily because this would be my first pneumatic design and I wasn't really sure what would be safe.  I figure I can rely on the people who set up the rules & equipment for FIRST to have done their safety homework.  When I used the Make compressed air kit with my scout troop, I was constantly on edge because it was manually inflated and had no over-pressure release safety built in.  They boys continually wanted to ramp up the power, pumping up to and beyond the recommended limits.  The FIRST kit comes with a couple of safety features, a relief valve factory set to 120 PSI that limits the maximum pressure accumulation, a dump valve which can be used to manually depressurize the system, and a digital pressure switch which signals when a target pressure of 115 PSI has been reached.  I used the relief and dump valved and replaced the digital 115 PSI pressure switch with an analog 100 PSI pressure sensor from Freescale Semiconductor so I can precisely measure and vary the launch pressure.

I like the fact that FIRST teaches students how to build using professional grade equipment.  Since I'm building this project with Joshua, my 16 year old son who is looking to start an early career as a machinist at a local community college, I want him to get experience working with good components.  The FIRST equipment uses nice push-to-connect fittings for the tubing so we can experiment and change designs without damaging the parts.  When using PVC piping which is glued together, any design change or mistake and you have to start with a fresh set of parts.

Our first assembled prototype:



The initial build went well.  We were able to manually activate the Festo valve and tested a few rockets inside the house at 20 and 40 PSI.  20 PSI gives a respectable launch, about as fast as you'd throw the rocket.  40 PSI is just at the edge of putting a dent in the plasterboard of the walls or ceiling.

The design goal is to fit the launch system on top of a robot.  Our current robotic platform of choice at work is the Parallax Eddie which has an 18" round disk as its platform.  I'm designing our platform so it can be either mounted on top of the Eddie or carried onsite.  It also needs some simple waterproofing since here in the Pacific Northwest we can't always wait for a sunny day for our outdoor scouting events.  Next steps will be to add the Arduino control system and the 18" base plates.

Parts List


If I was going to rebuild from scratch again, I'd consider a few changes, notably:
  • Save money by ordering just the parts used ($190) instead of the full kit ($281) from AndyMark.Com.
  • Look for a potentially better compressor.  The VIAIR is a bit weak and noisy.  Were this system to be used for evil, say hunting cubicle coworkers, the noise of the air compressor firing up would give it away.
  • The Festo valve is quite pricey and is more difficult to use than expected (more on this later).  I'd look for an equivalently small & light valve that is simpler to use -- something like a small version of the sprinkler valve from the Make kit.  One reason I went with the Festo valve is it has a fast activation speed (7 milliseconds) and I'm hoping to limit air output by using the Arduino to give very short bursts of air, so any replacement would need to be equivalently fast.

Monday, April 2, 2012

In the Beginning: Paper Air Rockets

Two years ago, we gave my son Joshua a compressed air rocket launcher kit from Make Magazine.  You wouldn't think that a bicycle pump, some PVC pipe, and a water sprinkler valve would be the beginning of a multi-year project...



After launching a few rockets in our back yard, I realized that these paper rockets were just as much fun as the Estes model rockets of my youth.  At 90 PSI, these rockets could shoot as high as the eye could see.  Since they are made of cheap paper, glue, and tape, kids could make as many as they wanted in whatever form they want.


That fall, I attended a training event for Boy Scouts leaders called Wood Badge which takes a group of women & men and has them form a troop and patrols and act like they're scouts for a couple of weekends.  The idea is to teach how a well run Boy Scout troop works by doing -- each adult becomes a scout in a patrol and the patrols are led through a series of activities that a well run troop would do together.  My patrol, the Beaver patrol naturally, participated in a water rockets competition


bringing home top honors.


One of the most impactful lessons I learned in that training was that the fun & enjoyment we have with activities like this comes not only from the activity itself but as much from the production we make of it. The mechanics of the competition was little more than a soda bottle, bicycle pump, rubber stopper, and duct tape.


The real fun came from the people dressed up as rocket scientists, the radio chatter with mission control, the elaborate setup of the launch pad, etc.  I figured that with a little forethought & some choice props, I could repeat that great experience with my own scout troop.





Which brings me to the reason for starting this blog.  My day job is writing software for Microsoft, most recently for the robotics team.  How can I repeat, improve, and share on my experience with pneumatic rockets with my scout troop?  I've decided to combine a few technologies together in search for more fun & teamwork, specifically:
  • Compressed Air Rockets in the spirit of the Make Magazine article & kit
  • A new automated pneumatic launch system based on the FIRST 2012 Pneumatic Base Kit.
  • An Arduino microcontroller to automate the launch system.
  • A robot.
  • A few additional surprises along the way, including some fun experimentation from my coworkers at Microsoft.
As I make progress, I'll post the details here so you can follow along and replicate my journey and results.  Along the path, I'll be asking for feedback on whether I've kept the 'fun quotient' intact.  I'll be showing off the project first at the Microsoft Garage which is our own version of a hackerspace and I'm hoping to be at both Makerfaire Bay Area & Makerfaire Seattle.