This is the third of five articles on my 2017 laser science project “Rock, Paper, Lasers.”
WEAR GOGGLES.
To use this code you should have read part one, for servo control, and part two for laser control.
DO NOT DELETE THE PART OF THE CODE THAT REMINDS YOU TO WEAR GOGGLES.
After the project was completed, I used this to make lines and squares. I want to go back and make stars and circles too.
DID I MENTION THE RIGHT COLOR GOGGLES ARE REALLY IMPORTANT?
I started playing with different ways to make the lasers visible too, I got a lot of advice from people, and some of it worked out well. In the end, only a real fog machine was able to do the work.
DON’T FORGET THE GOGGLES.
The little fog machines for science kits and projects didn’t make enough fog, my dad broke my “fog gun,” and other methods were less than successful, although some of them made my new makerspace smell really funny. Big fog machines are fun to play with.
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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
#!/usr/bin/python #import libraries import os import time import picamera import RPi.GPIO as GPIO #start camera camera = picamera.PiCamera() #get timestamp timeStamp = time.strftime("%Y%m%d_%H%M-%S",time.gmtime()) #set scalar variables for top tilt, bottom tilt, angle increment, start of fire in seconds, counts seconds, seconds per cycle, and Pan (side movement) topHat = 20 bottomHat = 11 angleHat = 1 startHat = 2 endHat = 30 stepHat = 2 sideHat = 31 #naming array of colors and their values - port on GPIO, name, and what color goggles colorHat = { "r" : { "port" : 29, "name" : "red", "goggles" : "blue"}, "b" : { "port" : 35, "name" : "blue", "goggles" : "red"}, "g" : { "port" : 33, "name" : "green", "goggles" : "red or blue"} } # Start the servo motors #startServod = "--step-size=40us --cycle-time=100000us " # not in use startServod = " " os.system('sudo /home/pi/PiBits/ServoBlaster/user/servod ' + startServod) # send camera output to video file in "discobunnies" directory camera.start_recording('discoBunnies/video_' + timeStamp + '.h264') time.sleep(2) #variable to start servo at bottom of tilt ai = bottomHat #move servos to starting position os.system("echo 1=" + str(sideHat) + "% > /dev/servoblaster") os.system("echo 0=" + str(bottomHat) + "% > /dev/servoblaster") time.sleep(0.5) #open LASER GPIO ports GPIO.setmode(GPIO.BOARD) for myPort in colorHat.keys() : # same as ["r","b","g"] GPIO.setup(colorHat[myPort]["port"], GPIO.OUT) GPIO.output(colorHat[myPort]["port"], False) #what colors can we use? (its an array) colorsAvail = ('r','g','b') # add start delay to total of seconds seconds=startHat # fire lasers for seconds counted as set above while (seconds <= endHat): #fire each color laser for color in colorHat.keys() : #display laser fire and seconds elapsed print "Okay I will fire the " + colorHat[color]["name"] + " laser for " + str(seconds) + " seconds" #move servo to next increment again (safety) os.system("echo 0=" + str(ai) + "% > /dev/servoblaster") #wait half a second for servo time.sleep(0.5) #prompt user to start firing, display goggles warning raw_input("Press Return To Fire, please wear your " + colorHat[color]["goggles"] + " now...") #fire laser code try and except if program is interrupted - SAFETY try : GPIO.output(colorHat[color]["port"], True) time.sleep(seconds) GPIO.output(colorHat[color]["port"], False) except : GPIO.output(colorHat[color]["port"], False) os.system('sudo killall servod') camera.stop_recording() #increase angle for next firing ai = (ai + angleHat) #add used seconds to total seconds seconds = (seconds + stepHat) #display all clear prompt print "Firing complete, remove goggles." #stop firing just in case -- safety only GPIO.output(29, False) GPIO.output(35, False) GPIO.output(33, False) # move servos back to bottom - safety only os.system("echo 0=" + str(bottomHat) + "% > /dev/servoblaster") time.sleep(0.5) #stop camera camera.stop_recording() #stop servo control system os.system('sudo killall servod') |
WATCH THE FUN VIDEOS. IF YOU DO THIS IN PERSON WEAR GOGGLES. USE VIDEO TO VIEW IT IN FULL LATER.
This one is a view of the lasers firing with the fog machine running for a few seconds at the beginning and then again at the end of the video.
This one is a view from the pi-camera inside the fire box :
Pingback: Tales of a 6th Grade Maker: Tribulations of a Laser Cutting Science Fair Project | Make:
Pingback: Raspberry Pi, Servos, Lasers & Legos : Science Project 2017 – Not A Bomb