Example #1
0
def update_reference_distance():
	ttg.blink_both()
	d = ttg.get_distance()
	time.sleep(0.2)
	d += ttg.get_distance()
	time.sleep(0.2)
	d += ttg.get_distance()
	m = d/3
	return m
Example #2
0
# main loop
while True:

	# Check if user has pressed the shutdown button
	if shutdown_request:
		ttg.clean()
		subprocess.call(["shutdown", "-h", "now"])

	# Update reference distanc if requested
	if memorize_request:
		m = update_reference_distance()	
		memorize_request = False
		
	# Get distance from ultrasonic sensor
	d = ttg.get_distance()
	b = eqdistance(d, m)
	ttrest.ttwrite('Distance',str(d))

	# State 0 is listening for a distance lecture out of 
	# range. Once found, it will initialize some data for the
	# sate 1.
	if state == 0:
		print "i'm on state 0"
		if not b:
			state = 1
			samp_neg = 0 # negative samples
			samp_total = 0
	# On State 1, we will collect some more samples and then 
	# calculate an average of positives vs negatives. Regarding
	# the result, we will go back or forward.