This repository was archived by the owner on Nov 17, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstartup_test.py
More file actions
86 lines (77 loc) · 2.45 KB
/
startup_test.py
File metadata and controls
86 lines (77 loc) · 2.45 KB
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
#!/bin/env python3
'''
***************************************************
* THIS VERSION HAS BEEN DEPRECATED
* This version was used only for testing purposes
* Refer to rocket-camera-module.py for official script
***************************************************
'''
import sys
#import RPi.GPIO as GPIO
import os
#import picamera
from time import sleep
'''
# Configure pulse-width modulation for servo motor
GPIO.setmode(GPIO.BCM)
GPIO.setup(18, GPIO.OUT)
Servo = GPIO.PWM(18,50)
# Configure pull-up microswitch
GPIO.setmode(GPIO.BCM)
GPIO.setup(17, GPIO.IN, pull_up_down=GPIO.PUD_UP)
# Configure camera library and output path
camera = picamera.PiCamera
os.chdir("/home/pi/rocket/New/Pictures")
'''
# Programmer-Defined Functions
def InitialDelay():
# Length to be changed to match the length of the flight
sleep(2)
print("Delay successful")
'''
# One second start/stop to confirm the rotation of the servo motor
Servo.start(99)
sleep(1)
Servo.stop()
sleep(1)
Servo.start(99)
'''
def GetSwitchReading(RotatedServo, SwitchStatus):
# Allows for the photo to be taken if servo has rotated and switch is depressed
if (RotatedServo) and (SwitchStatus == 0):
return True
return False
def IsResetEligible(SwitchStatus):
# Resets the ability to take a new photo if the servo has rotated
if (SwitchStatus == 1):
return True
return False
def main():
InitialDelay()
PicCounter = 0 # Initialize photo counter
d = 1 # Photo naming scheme
RotatedServo = True # Initialize as ready to take a new photo
while PicCounter < 16:
#SwitchStatus = GPIO.input(17) # 0-Button pressed, 1-Not Pressed
SwitchStatus = int(input("Input status (0-Button pressed, 1-Not Pressed): "))
# Calls method to reset eligibility
if (RotatedServo == False):
RotatedServo = IsResetEligible(SwitchStatus)
# Main conditional construct that takes action when all conditions are satisfied
if GetSwitchReading(RotatedServo, SwitchStatus) == True:
#Servo.stop()
sleep(0.1) # Allows time for camera to be still
#with picamera.PiCamera() as camera:
# camera.capture("Image_%d.jpg" % d)
print("Image_%d.jpg successfully saved" % d)
# Increment the naming scheme/photo counter, reset conditions
d += 1
PicCounter += 1
RotatedServo = False
#Servo.start(99)
sleep(0.1)
# Turn off Pi after full iterations of loop
from subprocess import call
call("sudo poweroff", shell=True)
#Start Program with Main
main()