Exemple #1
0
class MyAgent(ACTR):
    focus = Buffer()
    body = grid.Body()
    motor = MotorModule()
    obstacle = ObstacleModule()

    def init():
        focus.set('wander')

    def wandering_forward(focus='wander',
                          motor='busy:False',
                          obstacle='ahead:False'):
        motor.go_forward()

    def wandering_left(focus='wander',
                       motor='busy:False',
                       obstacle='left:False'):
        motor.go_left()

    def wandering_right(focus='wander',
                        motor='busy:False',
                        obstacle='right:False'):
        motor.go_right()

    def wandering_dead_end(focus='wander',
                           motor='busy:False',
                           obstacle='right:True left:True ahead:True'):
        motor.go_right()
Exemple #2
0
class VacuumAgent(ACTR):
    goal = Buffer()
    body = grid.Body()
    motorInst = MotorModule()
    cleanSensor = CleanSensorModule()

    def init():
        goal.set("rsearch left 1 0 1")
        self.home = None

    #----ROOMBA----#

    def clean_cell(cleanSensor="dirty:True",
                   motorInst="busy:False",
                   utility=0.6):
        motorInst.clean()

    def forward_rsearch(goal="rsearch left ?dist ?num_turns ?curr_dist",
                        motorInst="busy:False",
                        body="ahead_cell.wall:False"):
        motorInst.go_forward()
        print(body.ahead_cell.wall)
        curr_dist = str(int(curr_dist) - 1)
        goal.set("rsearch left ?dist ?num_turns ?curr_dist")

    def left_rsearch(goal="rsearch left ?dist ?num_turns 0",
                     motorInst="busy:False",
                     utility=0.1):
        motorInst.turn_left(2)
        num_turns = str(int(num_turns) + 1)
        goal.set("rsearch left ?dist ?num_turns ?dist")

    #Once the agent has turned 3 times (enough to be facing the starting direction,
    #it increases the distance it travels in a straight line, causing it to spiral.
    def spiral(goal="rsearch left ?dist 3 ?curr_dist",
               motorInst="busy:False",
               utility=0.1):
        new_dist = str(int(dist) + 1)
        goal.set("rsearch left ?new_dist 0 ?curr_dist")

    #Once it is facing a wall, it turns a random amount between 90 and 270
    #degrees, moves forward, then begins as if it was starting fresh but with
    #a slightly larger spiral radius (to better get to the middle of the room).
    def wall(goal="rsearch left ?dist ?num_turns ?curr_dist",
             motorInst="busy:False",
             utility=0.6,
             body="ahead_cell.wall:True"):
        rand = random.randint(2, 6)
        motorInst.turn_left(rand)
        motorInst.go_forward()
        goal.set("rsearch left 2 0 1")
class MuddyDog(ACTR):
    focus=Buffer()
    body=grid.Body()
    def init():
        focus.set('wander')
    def wandering_forward(focus='wander'):
        body.go_forward()
        body.cell.dirty=True

    def wandering_left(focus='wander'):
        body.turn_left()

    def wandering_right(focus='wander'):
        body.turn_right()
Exemple #4
0
class VacuumAgent(ACTR):
    goal = Buffer()
    body = grid.Body()
    motorInst = MotorModule()
    cleanSensor = CleanSensorModule()
    obstacle = ObstacleModule()

    def init():
        goal.set("rsearch left 1 0 1")
        self.home = None

    #----ROOMBA----#

    def clean_cell(cleanSensor="dirty:True", utility=0.6):
        motorInst.clean()

    def forward_rsearch(goal="rsearch left ?dist ?num_turns ?curr_dist",
                        motorInst="busy:False",
                        body="ahead_cell.wall:False"):
        motorInst.go_forward(
            int(num_turns)
        )  #go further as the number of turn increases to make a spiral pattern
        print(body.ahead_cell.wall)
        curr_dist = str(int(curr_dist) - 1)
        goal.set("rsearch left ?dist ?num_turns ?curr_dist")

    def left_rsearch(
        goal="rsearch left ?dist ?num_turns 0",
        motorInst="busy:False",
        utility=0.1
    ):  #change direction when it finishes part of the spiral pattern
        motorInst.turn_left(2)  #turn left 90 degrees
        num_turns = str(int(num_turns) + 1)  #increase number of turns
        goal.set("rsearch left ?dist ?num_turns ?dist"
                 )  #set the number of spaces to go

    def wall_rsearch(goal="rsearch left ?dist ?num_turns ?curr_dist",
                     obstacle="ahead:True",
                     utility=0.6):  #bounce when it hits the wall
        motorInst.go_left(3)  #wall tracing
        goal.set(
            "rsearch left 1 2 1"
        )  #set number of turns larger than 0 to keep it away from wall

    def wall2_rsearch(goal="rsearch left ?dist ?num_turns ?curr_dist",
                      obstacle="ahead:True",
                      utility=0.6):  #bounce when it hits the wall
        motorInst.go_left(5)  #wall tracing with different distance
        goal.set("rsearch left 1 1 1"
                 )  #use different parameters to prevent circling in same area
class MyAgent(ACTR):
    focus=Buffer()
    body=grid.Body()
    motor=MotorModule()

    def init():
        focus.set('wander')

    def wandering_forward(focus='wander',motor='busy:False'):
        motor.go_forward()

    def wandering_left(focus='wander',motor='busy:False'):
        motor.go_left()

    def wandering_right(focus='wander',motor='busy:False'):
        motor.go_right()
Exemple #6
0
class MyAgent(ACTR):
    focus = Buffer()
    body = grid.Body()
    motor = MotorModule()
    obstacle = ObstacleModule()

    visual = Buffer()
    vision = Memory(visual)
    visionScanner = grid.VisionScanner(body, vision)

    def init():
        focus.set('wander')
        visual.clear()

    def wandering_forward(focus='wander',
                          motor='busy:False',
                          obstacle='ahead:False'):
        motor.go_forward()

    def wandering_left(focus='wander',
                       motor='busy:False',
                       obstacle='left:False'):
        motor.go_left()

    def wandering_right(focus='wander',
                        motor='busy:False',
                        obstacle='right:False'):
        motor.go_right()

    def wandering_dead_end(focus='wander',
                           motor='busy:False',
                           obstacle='right:True left:True ahead:True'):
        motor.go_right()

    def look_for_dirt(focus='wander', vision='busy:False', visual=None):
        vision.request('dirty:True')

    def found_dirt(focus='wander', visual='dirty:True x:?x y:?y'):
        focus.set('go to ?x ?y')
        visual.clear()

    def go_to_location(focus='go to ?x ?y', motor='busy:False'):
        motor.go_towards(x, y)

    def arrived(focus='go to ?x ?y', body='x:?x y:?y'):
        motor.clean()
        focus.set('wander')
Exemple #7
0
class MyAgent(ACTR):
    focus=Buffer()
    body=grid.Body()

    def init():
        focus.set('wander')

    def wandering_forward(focus='wander'):
        body.go_forward()

    def wandering_left(focus='wander'):
        body.turn_left()
        body.go_forward()

    def wandering_right(focus='wander'):
        body.turn_right()
        body.go_forward()