Ultrasonic Rocket launcher

rocket launcher diagramThis is the code and diagram to fire the big trak rockets using the ultra sonic sensor on the Pi. The aim is to have the the rocket pod attached to Big Trak with the sensor at the front.The code is simple it will ask for a distance i normally say 80 (8cm).It will then print out the measurements every second until there is one below 80 then it`s fires the rockets , takes a picture using the call function and switches the LED on. This code is a work in progress so if you see any way to improve it I would like to hear.

Diagram in PDF 

#!/usr/bin/python
#
#
# Author : Julian and Kyle Milligan
# Date : 09/01/2013
# Import required Python libraries
import time
import RPi.GPIO as GPIO
from subprocess import call
# Use BCM GPIO references
# instead of physical pin numbers
GPIO.setmode(GPIO.BCM)
# Define GPIO to use on Pi
GPIO_TRIGGER = 23
GPIO_ECHO = 24
GPIO_FIRE = 4
#
print "Ultrasonic Measurement"
#
# Set pins as output and input
GPIO.setup(GPIO_TRIGGER,GPIO.OUT) # Trigger
GPIO.setup(GPIO_ECHO,GPIO.IN) # Echo
GPIO.setup(GPIO_FIRE,GPIO.OUT) # Fire
# Set trigger to False (Low)
GPIO.output(GPIO_TRIGGER, False)
# GPIO.output(GPIO_FIRE, False)
#
# Allow module to settle
time.sleep(0.5)
#
# set distance to trigger
setdistance = input('Please enter a value to trigger the camera:')#on screen prompt to fire
while True:
time.sleep(0.1)
GPIO.output(GPIO_TRIGGER, True)
time.sleep(0.00001)
GPIO.output(GPIO_TRIGGER, False)
start = time.time()
s = start
quit =0
#
while quit ==0:
quit = GPIO.input(GPIO_ECHO)
start = time.time()
if start - s > 0.1:
quit = 1
#
if start - s < 0.1:
while GPIO.input(GPIO_ECHO) == 1:
stop = time.time()
#
elapsed = stop-start
#
distance = elapsed * 34300
distance = distance / 2
#
print "Distance : %.1f" % distance
#
if distance < setdistance:
call (["raspistill -o image.jpg"], shell=True) # take a picture with Pi Camera
print "Fire"
GPIO.output(GPIO_FIRE,True) ## Turn on GPIO pin 7 fire the rockets
#
# Reset GPIO settings
GPIO.cleanup()

  
Tagged , . Bookmark the permalink.

Comments are closed.