Jacques Blog

Blog about stuff I do?

Laser Trip Wire Activated Missle Launcher!!

Yeah, I’m terrible at updating this blog. Going to work on fixing that.

Ok so a while back I got the missile turret on thinkgeek. The actual company is dreamcheaky. http://www.dreamcheeky.com/thunder-missile-launcher

It only ships with a cheap gui app to control it. However, lots of people online quickly figured out how to talk to it in their code via USB.

I also got Sparkfun’s inventors kit for Arduino recently (Yeah I’m late to the party :P) https://www.sparkfun.com/products/11227

So I decided it would be fun to combine both and make myself a laser trip wire activated missile launcher!

From what I could tell, Python was the easiest way to talk to the missile launcher. I don’t really know Python, but I was able to get something working.

I started off by cloning the stormLauncher project on GitHub https://github.com/nmilford/stormLauncher

Had to install PyUSB since it’s being used to communicate with the missile launcher. http://sourceforge.net/apps/trac/pyusb/

PyUSB uses libusb so you should make sure that’s installed. For windows use libusb-win32 http://sourceforge.net/apps/trac/libusb-win32/wiki

The wiki explains how to install it for a certain device. For the Thunder Misslie Launcher its:

1
2
idVendor=0x2123
idProduct=0x1010

Now came time to test the stormLauncher code. It didn’t seem to work for me. I don’t remember what errors I was getting so I decided to look into the code and strip it down to try and see if I can get it working.

I got a test working with this:

Test missile launcher
1
2
3
4
5
6
7
import usb.util #don't remember if this is actually needed
import usb.core
if __name__ == "__main__"
    dev = usb.core.find(idVendor=0x2123, idProduct=0x1010)
    if dev is None:
        raise ValueError('Turret not found')
    dev.ctrl_transfer(0x21,0x09,0,0,[0x02,0x10,0x00,0x00,0x00,0x00,0x00,0x00]) # Command to fire the missile

Using an arduino and photo sensor, I made a trip wire that just sends the value of the sensor through the serial cable. I used the same circuit as in this tutorial: http://arduino.cc/en/Tutorial/SwitchCase

The sketch is quite simple. Just output the light level.

Test missile launcher
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
const int sensorPin = 0;
int lightLevel, high = 0, low = 1023;

void setup()
{
    Serial.begin(9600);
}

void loop()
{
    lightLevel = analogRead(sensorPin);
    Serial.print(" Light level: ");
    Serial.println(lightLevel);
    delay(1000);
}

After that I looked up how to do serial communication with python. Basically the program reads the serial input coming from the arduino. Once the value passed by the arduino hits a certain threshold, this means the laser is no longer in contact with the light sensor so fire away! I got the light value by testing around with the laser so that might have to change. I also added a sleep time because the missile launcher isn’t the fastest. Note that I have code in there to remove the “Light level: ” part that is sent. I could/should have just ommited that so that I didn’t have to parse it out.

Like I said I don’t really know python so this was the result of playing around and reading a few things online. It works but it can be improved.

Here is the code:

Laser trip wire triggered missile launcher
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import serial
import usb.core
import usb.util
import re
import time

def main():
  # find our device
  dev = usb.core.find(idVendor=0x2123, idProduct=0x1010)
  
  # was it found?
  if dev is None:
      raise ValueError('Turret not found')

  # Set up serial communication with arduino
  sp = serial.Serial()
  sp.port = 'COM4'
  sp.baudrate = 9600
  sp.parity = serial.PARITY_NONE
  sp.bytesize = serial.EIGHTBITS
  sp.stopbits = serial.STOPBITS_ONE
  sp.timeout = 2
  sp.xonxoff = False
  sp.rtscts = False
  sp.dsrdtr = False

  sp.open()
  pattern = re.compile('[a-zA-Z: ]*([0-9]+)')
  value = None
  #confirm we are reading data from the serial port
  while not value:
      value = sp.readline()
  print value
  
  # loop and wait for wire to be tripped
  while 1:
      value = sp.readline()
      m = pattern.match(value)
      lightValue = m.group(1)
      #print lightValue
      if int(lightValue) > 100:
          print "fire in the hole"
          dev.ctrl_transfer(0x21,0x09,0,0,[0x02,0x10,0x00,0x00,0x00,0x00,0x00,0x00])
          time.sleep(5) # the missle launcher can only shoot about once every 5 seconds
  
  
  sp.close()

if __name__ == "__main__":
  main()

My next plan is hooking up the missle launcher to my RaspberryPi and and having the light sensor hooked up to an XBee Module. This way it’s more mobile.

Comments