Пример #1
0
			print "I think I'm stuck on something."
			print "dist_log =", dist_log
			Lobsang.voice.say("I think I am stuck")
			loops_since_last_check = 0
			# Obstacle detected, so move back a bit.
			Lobsang.wheels.both(-9)
			time.sleep(1)
			# Stop moving.
			Lobsang.wheels.both(0)
			# Measure, compare, then turn to face the direction with the most forward movement available.
			turn_optimum_direction()
		
		# Randomly recheck if the current direction still has the furthest distance.
		if loops_since_last_check > loops_before_recheck:
			if random.randint(0, 10) == 0: # One in ten chance.
				print "Decided to recheck optimum route."
				Lobsang.voice.say("Rechecking route")
				loops_since_last_check = 0
				Lobsang.wheels.both(0)
				turn_optimum_direction()
		
		else:
			loops_since_last_check += 1
			# Drive straight forward.
			Lobsang.wheels.both(12)
		time.sleep(1.0 / LPS)
except:
	# Ctrl+C or error in code.
	print "Halting obstacle avoidance code."
	Lobsang.quit()
				elif event.key == K_d:
					right = False
			
			if event.type == QUIT or (event.type == KEYDOWN and event.key == K_ESCAPE):
				current_time = time.time()
				Lobsang.wheels.both(0, ramped=False)
				Lobsang.launcher.disconnect()
				Lobsang.head.laser(False)
				Lobsang.oled.clear_buffer()
				Lobsang.oled.write("Halting Skittles Challenge code.") 
				Lobsang.oled.refresh(blackout=False)
				print "Skittles Challenge: Main loop ran for %s seconds or %i times, with average time per loop of %fs and %s loops per second." %(str(int((current_time - start_time) * 100.0) / 100.0), total_loops, (current_time - start_time) / total_loops, str(int(1 / ((current_time - start_time) / total_loops) * 100.0) / 100.0))
				print "Skittles Challenge: Halting."
				time.sleep(0.5)
				pygame.quit()
				Lobsang.quit(screensaver=False)
				sys.exit()
		
		left_motor_speed = 0
		right_motor_speed = 0
		if forward and not True in (left, right, backward): # Only forward key pressed
			left_motor_speed = 16
			right_motor_speed = 16
			#calibration = -0.6
		
		elif backward and not True in (forward, left, right): # Only backward key pressed
			left_motor_speed = -16
			right_motor_speed = -16
		
		elif left and not True in (forward, right, backward): # Only left key pressed
			left_motor_speed = -9
Пример #3
0
					cursor_position = 0
					render_menu(menu_position, cursor_position)
				
				elif option_command == "SHUTDOWN":
					print "Menu: Shutting down Lobsang..."
					pygame.quit()
					Lobsang.halt()
					time.sleep(10)
									
				elif option_command == "EXIT":
					print "Menu: Halting menu."
					Lobsang.oled.clear_buffer()
					Lobsang.oled.write("Halting menu...")
					Lobsang.oled.refresh()
					pygame.quit()
					Lobsang.quit(False)
					sys.exit()
				else:
					# If the option's command is one for the terminal, run it as one.
					print "Menu: Running %s..." %string.lower(option_name)
					pygame.quit() # Halt the pygame window because only one pygame window can be open at once, and so you can see any terminal messages printed by script run below.
					os.system(option_command)
					print "Menu: Finished running %s. Continuing running menu." %string.lower(option_name)
					pygame.init() # After the script has finished, restart the pygame window to continue getting keyboard events.
					display = pygame.display.set_mode(window_size)
					render_menu(menu_position, cursor_position)
			
			elif event.key == K_UP:
				# Up key pressed. Scroll the menu options up one line, or the cursor up one line.
				if menu_position > 0 and cursor_position == 0:
					menu_position -= 1