Thursday, January 24, 2013

Turret Squirt Gun: OSC iPad Control

Using a joystick is great for controlling many applications, but it requires that you have a laptop.  For this project, I thought it would be interesting to see if another control device could be used to run the squirt gun turret.  I found that Processing supports the OSC protocol, which sends packets over UDP (a protocol which runs over IP but without the error checking of TCP).  I used the TouchOSC application to create an interface on an iPad to run motors, the squirt gun, and the pan/tilt servos.  There is a library called oscP5 for Processing.

The TouchOSC interface is simple to use and completely customizable.  The interface I made is shown at left.    Every fader, button, or xyPad has an "address", shown on the left, and has customizable values.  For example, I setup the highlighted fader (which has the address /1/fader3) to have possible values between -100 and 100.  There is an app which you can download from the iStore for the iPad/iTouch/iPhone.  In the app, you set the IP address of the host computer.  Then you choose "sync" in the TouchOSC program, and the program sends your interface to the app on the iPad.  The iPad screens looks exactly like the interface you made in TouchOSC.

Once the iPad is setup with the IP address of the host computer, they can talk to  each other over any network as long as they are both on the web.  This means that as long as the computer is networked and is in the same location as the robot, the robot can be controlled from anyplace that the iPad can get an IP address.

The Processing code to read the OSC is shown below.  It basically parses the OSC packet to read the value of each fader, xygrid or button.    To download the code, click here.

I found that the communication protocol was not super robust.  For example, it worked with an iPad but not with an iTouch or an iPhone.  It worked very well with an iPad when the turret gun was connected to the host computer directly through an FTDI cable (see the video of the gun in action on this post).  However, behavior was erratic when the FTDI was replaced with Xbees... the gun, turret, and motors would randomly move or turn on when they were not commanded to.  This happened enough that I abandoned this interface and reverted to the joystick, which was much more reliable.  Nevertheless, for applications which are more tolerant of potential errors, this would be a fun system to use.

No comments:

Post a Comment