Ejemplo n.º 1
0
def main():
    wanderer = Tortoise()

    while True:
        #pass
        wanderer.moveForward(100)
        print wanderer.getSensorData(enums.SensorType.light, 1)
Ejemplo n.º 2
0
def main():
    wanderer = Tortoise()

    while True:

        touchSensor_1 = wanderer.getSensorData(enums.SensorType.touch, 1)
        touchSensor_2 = wanderer.getSensorData(enums.SensorType.touch, 2)
        touchSensor_3 = wanderer.getSensorData(enums.SensorType.touch, 3)

        if touchSensor_1 == 1:
            print "Switch 1 is on"
        else:
            print "Switch 1 is off"

        if touchSensor_2 == 1:
            print "Switch 2 is on"
        else:
            print "Switch 2 is off"

        if touchSensor_3 == 1:
            print "Switch 3 is on"
        else:
            print "Switch 3 is off"

        print

        time.sleep(1)
Ejemplo n.º 3
0
def main():
    wanderer = Tortoise()

    while True:
        #print "Light 1: " + str(wanderer.getSensorData(enums.SensorType.light, 1))
        print "Light 2: " + str(wanderer.getSensorData(enums.SensorType.light, 2))
        #print
        time.sleep(0.5)
Ejemplo n.º 4
0
def main():
    wanderer = Tortoise()

    wanderer.setLEDValue(1, 1)
    wanderer.setLEDValue(2, 1)
    wanderer.setLEDValue(3, 1)
    wanderer.setLEDValue(4, 1)

    while True:

        wanderer.moveForwards(2000)
Ejemplo n.º 5
0
def main():
    wanderer = Tortoise()

    while True:

        print "Blinking LED 1 and 2"
        wanderer.blinkLEDs([1, 2], 3, 0.3, blocking=False)
        #        print "\tPress enter to continue"
        #        raw_input()

        print "Blinking LED 1 and 3"
        wanderer.blinkLEDs([3, 1], 3, 0.3, blocking=False)
        #        print "\tPress enter to continue"
        #        raw_input()

        print "Blinking LED 1 and 4"
        wanderer.blinkLEDs([1, 4], 3, 0.3, blocking=False)
        #        print "\tPress enter to continue"
        #        raw_input()

        print "Blinking LED 2 and 3"
        wanderer.blinkLEDs([3, 2], 3, 0.3, blocking=False)

        print "Blinking LED 2 and 4"
        wanderer.blinkLEDs([4, 2], 3, 0.3, blocking=False)
        #        print "\tPress enter to continue"
        #        raw_input()

        print "Blinking LED 3 and 4"
        wanderer.blinkLEDs([3, 4], 3, 0.3, blocking=False)
        #        print "\tPress enter to continue"
        #        raw_input()

        print "Blinking LED 1, 2 and 3"
        wanderer.blinkLEDs([2, 1, 3], 3, 0.3, blocking=False)

        print "Blinking LED 1, 2 and 4"
        wanderer.blinkLEDs([2, 1, 4], 3, 0.3, blocking=False)
        #        print "\tPress enter to continue"
        #        raw_input()

        print "Blinking LED 1, 3 and 4"
        wanderer.blinkLEDs([3, 1, 4], 3, 0.3, blocking=False)
        #        print "\tPress enter to continue"
        #        raw_input()

        print "Blinking LED 2, 3 and 4"
        wanderer.blinkLEDs([4, 2, 3], 3, 0.3, blocking=False)
        #        print "\tPress enter to continue"
        #        raw_input()

        print "Blinking LED 1, 2, 3 and 4"
        wanderer.blinkLEDs([3, 4, 1, 2], 3, 0.3, blocking=False)
Ejemplo n.º 6
0
def main():
	Bob=Tortoise()
	while True:
		if Bob.getSensorData(SensorType.light,1)<4:
			Bob.doRandomStep()
			print "where are you?"
		elif Bob.getSensorData(SensorType.light,1)<9:
			Bob.moveForward(30)
			print "ah-ha!"
		else :
			Bob.moveBackward(30)
			print "Burning burning!"
Ejemplo n.º 7
0
def main():
    wanderer = Tortoise()

    while True:
        #pass
        wanderer.moveForward(100)
        #print wanderer.getSensorData(enums.SensorType.light, 1)
        if wanderer.getSensorData(enums.SensorType.emergencySwitch, 1) == 1:
            #print "1"
            wanderer.setActuatorValue(enums.ActuatorType.led, 1, 1)
        else:
            #print "0"
            wanderer.setActuatorValue(enums.ActuatorType.led, 1, 0)
Ejemplo n.º 8
0
def main():
    wanderer = Tortoise()

    while True:

        wanderer.moveForwards(500)
        time.sleep(0.5)
        #wanderer.gentleTurn(1000, enums.Direction.forward_left)
        #time.sleep(1)
        #wanderer.moveMotors(1000, enums.Direction.forward_right)
        #time.sleep(1)
        wanderer.moveBackwards(500)
        time.sleep(0.5)
Ejemplo n.º 9
0
def main():
    Mike = Tortoise()

    while True:
        if Mike.getSensorData(SensorType.light, 1) < 6:
            Mike.doRandomStep()
            print "Where's the light?"
        elif 6 <= Mike.getSensorData(SensorType.light,
                                     1) and Mike.getSensorData(
                                         SensorType.light, 1) < 9:
            print "Found Light"
            Mike.moveForward(30)
        else:
            print "Argh! Too much light!"
            Mike.moveBackward(30)
def main():
    wanderer = Tortoise()

    while True:

        proximitySensor_1 = wanderer.getSensorData(enums.SensorType.proximity,
                                                   4)

        if proximitySensor_1 == 1:
            print "Proximity sensor 1 is ON"
        else:
            print "Proximity sensor 1 is OFF"

        print

        time.sleep(0.1)
Ejemplo n.º 11
0
def main():
    wanderer = Tortoise()

    while True:

        wanderer.setLEDValue(1, 1)
        wanderer.setLEDValue(2, 0)
        wanderer.setLEDValue(3, 1)
        wanderer.setLEDValue(4, 0)

        print "LEDs 1 and 3 set"
        print
        print "\tPress enter to continue"
        raw_input()

        print "Blinking LED 1, 2, 3 and 4"

        wanderer.blinkLEDs([3, 4, 1, 2], 3, 0.3, blocking=False)

        print "Check status of LEDs after blinking"
        print
        print "\tPress enter to continue"
        raw_input()

        wanderer.setLEDValue(1, 1)
        wanderer.setLEDValue(2, 1)
        wanderer.setLEDValue(3, 1)
        wanderer.setLEDValue(4, 1)

        print "LEDs 1, 2, 3 and 4 set"
        print
        print "\tPress enter to continue"
        raw_input()

        print "Blinking LED 1, 2, 3 and 4"

        wanderer.blinkLEDs([3, 4, 1, 2], 3, 0.3, blocking=False)

        print "Check status of LEDs after blinking"
        print
        print "\tPress enter to continue"
        raw_input()
Ejemplo n.º 12
0
def main():
    wanderer = Tortoise()

    while True:

        proximitySensor_1 = wanderer.getSensorData(enums.SensorType.proximity,
                                                   1)
        proximitySensor_2 = wanderer.getSensorData(enums.SensorType.proximity,
                                                   2)
        proximitySensor_3 = wanderer.getSensorData(enums.SensorType.proximity,
                                                   3)
        proximitySensor_4 = wanderer.getSensorData(enums.SensorType.proximity,
                                                   4)

        if proximitySensor_1 == 1:
            print "Proximity sensor 1 is ON"
        else:
            print "Proximity sensor 1 is OFF"

        if proximitySensor_2 == 1:
            print "Proximity sensor 2 is ON"
        else:
            print "Proximity sensor 2 is OFF"

        if proximitySensor_3 == 1:
            print "Proximity sensor 3 is ON"
        else:
            print "Proximity sensor 3 is OFF"

        if proximitySensor_4 == 1:
            print "Proximity sensor 4 is ON"
        else:
            print "Proximity sensor 4 is OFF"

        print

        time.sleep(1)
Ejemplo n.º 13
0
def main():
    wanderer = Tortoise()

    while True:

        print "Blinking LED 1"
        wanderer.blinkLEDs(1, 3, 0.5, blocking = False)
        print "\tPress enter to continue"
        raw_input()

        print "Blinking LED 2"
        wanderer.blinkLEDs(2, 3, 0.5, blocking = False)
        print "\tPress enter to continue"
        raw_input()

        print "Blinking LED 3"
        wanderer.blinkLEDs(3, 3, 0.5, blocking = False)
        print "\tPress enter to continue"
        raw_input()

        print "Blinking LED 4"
        wanderer.blinkLEDs(4, 3, 0.5, blocking = False)
        print "\tPress enter to continue"
        raw_input()
Ejemplo n.º 14
0
# IMPORT MODULES FROM SUBFOLDERS #
""" It's neccesary in order to import modules not in the same folder, but in a different one.
This is the way to tell python the location on those subfolders: """
import os, sys, inspect

cmd_folder = os.path.realpath(os.path.abspath(os.path.split(inspect.getfile( inspect.currentframe() ))[0]))
if cmd_folder not in sys.path:
	sys.path.insert(0, cmd_folder)

sys.path.append('../')
# ------------------------------ #

from tortoise import Tortoise
import enums
import time

t = Tortoise()

while(True):

    t.doRandomMovement()
Ejemplo n.º 15
0
from tortoise import Tortoise
from enums import Direction, SensorType

#In this version they fix the values and fill in the else.

# Change this to 1 when you've calibrated and have some values for not enough light, good light and too much light.
calibrated = 1;


# Name your tortoise here.
Frankie = Tortoise()

if (calibrated==0):
	print "Let's use different levels of light to see what calibrated readings we get"
	raw_input("First let's see what the room gives us, press enter when you're done")
	print Frankie.getSensorData(SensorType.light,1)
	raw_input("Now try it with a light source right up close and press enter when you're done")
	print Frankie.getSensorData(SensorType.light,1)
	raw_input("And now try somewhere in the middle")
	print Frankie.getSensorData(SensorType.light,1)

while True and (calibrated==1):
	# First we need a reading from the light sensor
	lightSensorReading = Frankie.getSensorData(SensorType.light, 1)

	# Can you tune the light sensor values for the conditions based on your calibration findings?
	if lightSensorReading < 4:
		Frankie.doRandomStep()
		print "Where's the light?"
	elif 4<= lightSensorReading  and lightSensorReading <9:
		# What should we be printing here?
Ejemplo n.º 16
0
from tortoise import Tortoise
from enums import Direction, SensorType, ActuatorType

Name = Tortoise()

while True:

    touchSensor = Name.getSensorData(SensorType.touch, 1)
    print "Front switch is:"
    print touchSensor
    touchSensor2 = Name.getSensorData(SensorType.touch, 3)
    print "Back switch is: "
    print touchSensor2
    if touchSensor == 1:
        print "Switch is on"
        Name.moveBackwards(30)
        Name.setLEDValue(1, 1)  #self.setLEDValue(position, value)
        Name.setLEDValue(2, 0)  #self.setLEDValue(position, value)
        touchSensor2Loop = Name.getSensorData(SensorType.touch, 3)
        print "Back switch as read inside loop: "
        print touchSensor2Loop
        if touchSensor2 == 1:
            print "Back switch has been hit"
            Name.moveForwards(30)
            Name.setLEDValue(2, 0)  #self.setLEDValue(position, value)
            if touchSensor == 0:
                break
# else:
#print "Switch is off"
#Name.moveForwards(30)
#Name.setLEDValue(1, 0) #self.setLEDValue(position, value)
Ejemplo n.º 17
0
from tortoise import Tortoise
from enums import Direction, SensorType, ActuatorType
import random

Cora = Tortoise()

learnAssoc = 0.0
assocFlag = 0

while True:

    Cora.setLEDValue(1, 0)
    responseFlag = 0

    responseSensor = Cora.getSensorData(SensorType.touch, 1)
    stimulusSensor = Cora.getSensorData(SensorType.touch, 2)

    print "Resp=%f stim=%f learn=%f assoc=%f" % (
        responseSensor, stimulusSensor, learnAssoc, assocFlag)

    # response always triggered by main sensor
    if responseSensor == 1:
        responseFlag = 1

    if stimulusSensor == 1:
        # update accumulator
        if responseSensor == 1:
            learnAssoc = 0.6 * learnAssoc + 0.4
            Cora.setLEDValue(1, 1)
        else:
            learnAssoc = 0.75 * learnAssoc
Ejemplo n.º 18
0
from turtle import Screen
from tortoise import Tortoise
from level import Level
from game_over import GameOver
from car import Car
import time
SCREEN_SIZE = 600

screen = Screen()
screen.bgcolor("white")
screen.colormode(255)
screen.tracer(0)
screen.setup(width=SCREEN_SIZE, height=SCREEN_SIZE)
sleep_time = .1

tim = Tortoise()
level = Level()
num_of_cars = 5
car_list = []

for c in range(0, num_of_cars):
    car_list.append(Car())

screen.update()
screen.listen()
screen.onkeypress(tim.jump, "Up")

game_on = True
while game_on:
    time.sleep(sleep_time)
    screen.update()
Ejemplo n.º 19
0
def record_working_loop(name='default_rec'):
    t = Tortoise()
    t.task = RecordingTask(name)
    t.walk()
Ejemplo n.º 20
0
def main():
    wanderer = Tortoise()

    while True:

        print "Moving forwards"
        wanderer.moveForwards(500)
        time.sleep(0.5)

        print
        print "\tPress enter to continue"
        print
        raw_input()

        print "Moving backwards"
        wanderer.moveBackwards(500)
        time.sleep(0.5)

        print
        print "\tPress enter to continue"
        print
        raw_input()

        print "Turning on the spot forwards_left"
        wanderer.turnOnTheSpot(500, enums.Direction.forwards_left)
        time.sleep(0.5)

        print
        print "\tPress enter to continue"
        print
        raw_input()

        print "Turning on the spot forwards_right"
        wanderer.turnOnTheSpot(500, enums.Direction.forwards_right)
        time.sleep(0.5)

        print
        print "\tPress enter to continue"
        print
        raw_input()

        print "Turning on the spot backwards_left"
        wanderer.turnOnTheSpot(500, enums.Direction.backwards_left)
        time.sleep(0.5)

        print
        print "\tPress enter to continue"
        print
        raw_input()

        print "Turning on the spot bakwards_right"
        wanderer.turnOnTheSpot(500, enums.Direction.backwards_right)
        time.sleep(0.5)

        print
        print "\tPress enter to continue"
        print
        raw_input()

        print "Turning naturally forwards_left"
        wanderer.turn(200, 500, enums.Direction.forwards_left)
        time.sleep(0.5)

        print
        print "\tPress enter to continue"
        print
        raw_input()

        print "Turning naturally backwards_left"
        wanderer.turn(200, 500, enums.Direction.backwards_left)
        time.sleep(0.5)

        print
        print "\tPress enter to continue"
        print
        raw_input()

        print "Turning naturally forwards_right"
        wanderer.turn(500, 200, enums.Direction.forwards_right)
        time.sleep(0.5)

        print
        print "\tPress enter to continue"
        print
        raw_input()

        print "Turning naturally backwards_right"
        wanderer.turn(500, 200, enums.Direction.backwards_right)
        time.sleep(0.5)

        print
        print "\tPress enter to continue"
        print
        raw_input()

        print "Gyrating clockwise"
        wanderer.shuffleOnTheSpot(500, enums.Direction.clockwise)
        time.sleep(0.5)

        print
        print "\tPress enter to continue"
        print
        raw_input()

        print "Gyrating counter clockwise"
        wanderer.shuffleOnTheSpot(500, enums.Direction.counterClockwise)
        time.sleep(0.5)

        print
        print "\tPress enter to continue"
        print
        raw_input()
Ejemplo n.º 21
0
from tortoise import Tortoise
from enums import Direction, SensorType, ActuatorType
Walter=Tortoise()

lastMove = "forward"

while True:

    frontSwitch = Walter.getSensorData(SensorType.touch, 1)
    backSwitch = Walter.getSensorData(SensorType.touch, 2)

    if frontSwitch ==1 and backSwitch ==0:

        print "Obstacle in front - moving backwards"    
        Walter.setLEDValue(1, 0) #self.setLEDValue(position, value)
        Walter.setLEDValue(2, 1) #self.setLEDValue(position, value)
        lastMove = "back"

    elif backSwitch ==1 and frontSwitch ==1:

        print "Can't move!"    

    elif frontSwitch ==0 and backSwitch ==1:

        print "Obstacle behind - moving forwards"    
        Walter.setLEDValue(1, 1) #self.setLEDValue(position, value)
        Walter.setLEDValue(2, 0) #self.setLEDValue(position, value)
        lastMove = "forward"

    else:
        print "Exploring"
Ejemplo n.º 22
0
#主函数
import turtle
from maze import Maze
from tortoise import Tortoise
from control import controller
maze_list = [[1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1],
             [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
             [1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1],
             [1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1],
             [1, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1],
             [1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1],
             [1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1],
             [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1],
             [1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1],
             [1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1],
             [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1],
             [1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1],
             [1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1]]
Maze(maze_list)
tortoise = Tortoise(maze_list, 0, 5, 12, 7)
controller(tortoise.go_up, tortoise.go_down, tortoise.go_left,
           tortoise.go_right)
turtle.done()
Ejemplo n.º 23
0
from tortoise import Tortoise
from enums import Direction, SensorType, ActuatorType

Elsie = Tortoise()

while True:

    proxSensor = Elsie.getSensorData(SensorType.proximity, 2)

    if proxSensor == 1:

        print "Obstacle detected behind"
        Elsie.setLEDValue(2, 1)  #self.setLEDValue(position, value)
        Elsie.moveForwards(150)

    else:

        print "No obstacle detected"
        Elsie.setLEDValue(2, 0)  #self.setLEDValue(position, value)
        Elsie.doRandomMovement()
Ejemplo n.º 24
0
from tortoise import Tortoise
from enums import Direction, SensorType, ActuatorType

Grey = Tortoise()

while True:

    touchSensor = Grey.getSensorData(SensorType.touch, 1)

    if touchSensor == 1:

        print "Switch is on"
        Grey.setLEDValue(1, 1)  #self.setLEDValue(position, value)
        Grey.moveForwards(50)

    else:

        print "Switch is off"
        Grey.setLEDValue(1, 0)  #self.setLEDValue(position, value)
Ejemplo n.º 25
0
from tortoise import Tortoise
from enums import Direction, SensorType, ActuatorType

Dennis=Tortoise()

while True:

    Dennis.setLEDValue(1, 0)
    Dennis.setLEDValue(2, 0)

    rightSensor = Dennis.getSensorData(SensorType.proximity,1)
    leftSensor = Dennis.getSensorData(SensorType.proximity,2)

    if rightSensor == 1:

        print "Obstruction right"
        Dennis.setLEDValue(1, 1) 
        Dennis.turnOnTheSpot(20,Direction.backwards_right)

    elif leftSensor == 1:

        print "Obstruction left"
        Dennis.setLEDValue(2,1)
        Dennis.turnOnTheSpot(20,Direction.backwards_left)

    else:

        print "I'm wandering..."
        Dennis.moveForwards(30)

Ejemplo n.º 26
0
def main():
    wanderer = Tortoise()

    while True:
        wanderer.moveForward(100)
Ejemplo n.º 27
0
from tortoise import Tortoise
from enums import Direction, SensorType, ActuatorType

Elmer = Tortoise()

while True:

    proxSensor = Elmer.getSensorData(SensorType.proximity, 1)
    proxSensor2 = Elmer.getSensorData(SensorType.proximity, 2)

    if proxSensor == 1 and proxSensor2 == 0:

        print "Obstacle detected in front"
        Elmer.setLEDValue(1, 1)  #self.setLEDValue(position, value)
        Elmer.setLEDValue(2, 0)  #self.setLEDValue(position, value)
        Elmer.moveBackwards(150)

    elif proxSensor == 1 and proxSensor2 == 1:

        print "Obstacles detected in front and behind!"
        Elmer.setLEDValue(1, 1)  #self.setLEDValue(position, value)
        Elmer.setLEDValue(2, 1)  #self.setLEDValue(position, value)

    elif proxSensor == 0 and proxSensor2 == 1:

        print "Obstacle detected behind"
        Elmer.setLEDValue(1, 0)  #self.setLEDValue(position, value)
        Elmer.setLEDValue(2, 1)  #self.setLEDValue(position, value)
        Elmer.moveForwards(150)

    else: