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)
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()
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()
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(1, 1) #self.setLEDValue(position, value) Elsie.moveForwards(150) else: print "No obstacle detected" Elsie.setLEDValue(1, 0) #self.setLEDValue(position, value) Elsie.doRandomMovement()
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)
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) Walter.moveBackwards(100) 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) Walter.moveForwards(100) lastMove = "forward" else: print "Exploring" Walter.setLEDValue(1, 1) #self.setLEDValue(position, value) Walter.setLEDValue(2, 1) #self.setLEDValue(position, value) if lastMove == "forward": Walter.moveForwards(100)
# if (forwardSwitch == backwardSwitch): if (forwardSwitch == 0 and backwardSwitch == 0) or (forwardSwitch == 1 and backwardSwitch == 1): print "monkey" if forwardSwitch == 1: print "Switch 1 is on" else: print "Switch 1 is off" if backwardSwitch == 1: print "Switch 2 is on" else: print "Switch 2 is off" print " " Name.moveForwards(100) Name.setLEDValue(1, 1) #self.setLEDValue(position, value) Name.setLEDValue(2, 0) #self.setLEDValue(position, value) # if (forwardSwitch != backwardSwitch): if (forwardSwitch == 1 and backwardSwitch == 0) or (forwardSwitch == 0 and backwardSwitch == 1): print "donkey" if forwardSwitch == 1: print "Switch 1 is on" else: print "Switch 1 is off" if backwardSwitch == 1: print "Switch 2 is on" else: print "Switch 2 is off"
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"
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)
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
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)
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) #Name.setLEDValue(2, 1) #self.setLEDValue(position, value)
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:
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 # check association thresholds
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()
from tortoise import Tortoise from enums import Direction, SensorType Name=Tortoise() while True: touchSensorValue = Name.getSensorData(SensorType.touch, 1) if touchSensorValue == 1: print "Touch sensor is being pressed" Name.setLEDValue(1, 1) Name.moveForwards(50) else: print "Nothing is pressing the touch sensor" Name.setLEDValue(1, 0)
from tortoise import Tortoise from enums import Direction, SensorType Name = Tortoise() while True: touchSensorValue = Name.getSensorData(SensorType.touch, 1) if touchSensorValue == 1: print "Touch sensor is being pressed" Name.setLEDValue(1, 1) Name.moveForwards(50) else: print "Nothing is pressing the touch sensor" Name.setLEDValue(1, 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) if 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) if 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: print "No obstacle detected" Elmer.setLEDValue(1, 0) #self.setLEDValue(position, value) Elmer.setLEDValue(2, 0) #self.setLEDValue(position, value)