launch_ball = False
paddle_open = False

open_guide = True
opened = True
redraw = False

# Set up pygame.
pygame.init()
DISPLAYSURF = pygame.display.set_mode((1280, 800))
pygame.display.set_caption('Lobsang Skittles Challenge')
clock = pygame.time.Clock()

# Set up Lobsang.
Lobsang.begin(splashscreen=False)
Lobsang.wheels.calibrate_speeds(-0.6)
Lobsang.head.aim(1380, 1550)
#Lobsang.head.laser(True)
# Tell the Duino that the launcher is connected.
Lobsang.launcher.connect()
Lobsang.launcher.open_guide()
Lobsang.launcher.reset_paddle()

# Print the interface info on the oled.
Lobsang.oled.clear_buffer()
Lobsang.oled.write("Skittles", pos=(0, 0), size=16)
Lobsang.oled.write("Control with W, A, S, D keys.")
Lobsang.oled.write("Control paddle with K, O, P keys.")
Lobsang.oled.write("Press ESC to quit.")
Lobsang.oled.refresh()
Beispiel #2
0
print "Running obstacle avoidance code."
# Import libraries.
import Lobsang, time, random, sys

# Initialise Lobsang.
Lobsang.begin()
# Point the head straight forward.
Lobsang.head.aim(1430, 1430)

# This becomes a map of the distances from the robot's head
# each time turn_optimum_distance() is run. Length 7.
dist_map = [0, 0, 0, 0, 0, 0, 0]

# This becomes a log of the distances from the robot's head
# over a number of cycles. If lots of the measurements are
# similar but the robot is driving forward, then it has
# probably got stuck on something it can't see. Length 10.
dist_log = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

# Number of loops per second- this is only approximate.
# Real loops per sec = 1 / LPS + time loop takes to complete.
LPS = 10.0

# This is the number of loops before the random direction
# checks begin again, but initially represented in seconds.
loops_before_recheck = 2
loops_before_recheck *= LPS # To get actual number of loops.

# Number of loops done so far.
loops_since_last_check = 0
				os.system("sudo bash bash/backup.sh")
				Lobsang.oled.write("Copied data.")
				Lobsang.oled.refresh()
				time.sleep(2)
				print "Piwars Menu: Finished backing up files. Continuing running menu."
				render_menu(menu_position)
				pygame.init()
				display = pygame.display.set_mode((1280, 800))
			
			elif event.key == K_8:
				# Key '8' pressed. Shuts down the robot by running 'sudo halt' then waiting for 10 secs
				# (before this time is up the program gets stopped as the system shuts down. The delay
				# is so that this program does not exit back to 'autorun.py' as that prompts a login as the Pi shuts down!).
				print "Piwars Menu: Will now shut down robot. Halting menu."
				pygame.quit()
				Lobsang.halt()
				time.sleep(10)
				
			elif event.key == K_UP:
			# Up key pressed. Scroll the menu options up one line.
				if menu_position > 0:
					menu_position -= 1
					render_menu(menu_position)
			
			elif event.key == K_DOWN:
			# Down key pressed. Scroll the menu options down one line.
				if menu_position < len(menu_options) - 4: # Use len() to make the menu adaptable. Add and remove menu items and this will still scroll right.
					menu_position += 1
					render_menu(menu_position)
			
			if event.type == QUIT or (event.type == KEYDOWN and event.key == K_ESCAPE):
Beispiel #4
0
#!/usr/bin/env python
#
# boot.py- checks if the RasPiO Duino,
# RasPiCam and OLED are all connected.
# Returns a sys.exit() code  depending
# on what errors occurs.  0 on all ok.
#
# Created Nov 2015 by Finley Watson

import Lobsang
import sys

Lobsang.begin(0)

if not Lobsang.gpio_access:
	sys.exit(16)

import subprocess
import os
from time import sleep
import RPi.GPIO as GPIO

number_of_offline_systems = 0
binary_offline_flag = 0 # 0b001 (1) == duino offline, 0b011 (3) == oled and duino offline, 0b100 (4) == camera offline etc

oled_offline = False
duino_offline = False
camera_offline = False

Lobsang.duino.enable()
Beispiel #5
0
				if option_command == "LOAD_ALL_OPTIONS":
					menu_options = all_programs_options()
					menu_position = 0
					cursor_position = 0
					render_menu(menu_position, cursor_position)
				
				elif option_command == "LOAD_STANDARD_OPTIONS":
					menu_options = standard_menu_options
					menu_position = 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)