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.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)
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) else: Walter.moveBackwards(100)
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)
# 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 if (learnAssoc > 0.8 and assocFlag == 0): assocFlag = 1 Cora.setLEDValue(2, 1) elif (learnAssoc < 0.2 and assocFlag == 1): assocFlag = 0 Cora.setLEDValue(2, 0) # trigger response if associated if assocFlag == 1: responseFlag = 1 if responseFlag == 1: Cora.moveForwards(100) else: if random.random() < 0.5: Cora.turnOnTheSpot(10, Direction.backwards_right) else: Cora.turnOnTheSpot(10, Direction.backwards_left)
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 Name=Tortoise() lastFrontSwitch = 0 lastBackSwitch = 0 while True: currentFrontSwitch = Name.getSensorData(SensorType.touch,3) currentBackSwitch = Name.getSensorData(SensorType.touch,1) forwards = abs(lastBackSwitch - currentBackSwitch) backwards = abs(lastFrontSwitch - currentFrontSwitch) if forwards==1 and backwards==0: lastFrontSwitch=currentFrontSwitch print "Moving forwards" Name.moveForwards(5) if backwards ==1 and forwards==0: lastbackSwitch=currentBackSwitch print "Moving backwards" Name.moveBackwards(5) else: print "No switches on"
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()
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: print "No obstacle detected" Elmer.setLEDValue(1, 0) #self.setLEDValue(position, value) Elmer.setLEDValue(2, 0) #self.setLEDValue(position, value)
from tortoise import Tortoise from enums import Direction, SensorType, ActuatorType Name = Tortoise() lastFrontSwitch = 0 lastBackSwitch = 0 while True: currentFrontSwitch = Name.getSensorData(SensorType.touch, 3) currentBackSwitch = Name.getSensorData(SensorType.touch, 1) forwards = abs(lastBackSwitch - currentBackSwitch) backwards = abs(lastFrontSwitch - currentFrontSwitch) if forwards == 1 and backwards == 0: lastFrontSwitch = currentFrontSwitch print "Moving forwards" Name.moveForwards(5) if backwards == 1 and forwards == 0: lastbackSwitch = currentBackSwitch print "Moving backwards" Name.moveBackwards(5) else: print "No switches on"
# 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 if (learnAssoc > 0.8 and assocFlag == 0): assocFlag = 1 Cora.setLEDValue(2, 1) elif (learnAssoc < 0.2 and assocFlag == 1): assocFlag = 0 Cora.setLEDValue(2, 0) # trigger response if associated if assocFlag == 1: responseFlag = 1 if responseFlag == 1: Cora.moveForwards(100) else: if random.random()<0.5: Cora.turnOnTheSpot(10,Direction.backwards_right) else: Cora.turnOnTheSpot(10,Direction.backwards_left)
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)
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: print "No obstacle detected" Elmer.setLEDValue(1, 0) #self.setLEDValue(position, value) Elmer.setLEDValue(2, 0) #self.setLEDValue(position, value)
backwardSwitch = Name.getSensorData(SensorType.touch, 2) # 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 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 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)
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" Walter.setLEDValue(1, 1) #self.setLEDValue(position, value) Walter.setLEDValue(2, 1) #self.setLEDValue(position, value) if lastMove == "forward": Walter.moveForwards(100) else: Walter.moveBackwards(100)
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()
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 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)