示例#1
0
    def __init__(self, laser, ir, navigator):
        self.laser = laser
        self.ir = ir
        self.navigator = navigator
        self.state = STATE_MEASURING
        self.mapping_state = MAPPING_STATE_FOLLOWING_OUTER_WALL
        self.current_section = Section(NORTH)
        self.saved_sections = []
        self.map_data = [(0, 0)]
        self.current_x = 0
        self.current_y = 0
        self.kitchen_start_x = 0
        self.kitchen_start_y = 0
        self.kitchen_num_mapped = 0
        self.num_kitchen_turns = 0

        self.kitchen_mapping = {}
        self.invalid_kitchens = []
        self.island_data = []
        self.edges_data = []

        self.num_ok_close = 0
        self.num_ok_far = 0

        EventBus.subscribe(CMD_TURN_STARTED, self.on_turning_started)
        EventBus.subscribe(CMD_TURN_FINISHED, self.on_turning_finished)
def set_motor_speed(left_speed, right_speed=None):
    if right_speed is None:
        right_speed = left_speed

    EventBus.post(
        STYR_ADDR,
        Event(message_id=CMD_SET_MOTOR_SPEED,
              arguments=[left_speed, right_speed]))
示例#3
0
def main():
    global busy, last_request

    setup()

    while True:
        EventBus.receive()
        request_data()
示例#4
0
def main():
    setup()
    while True:
        laser.read_data()
        gyro.read_data()
        ir.request_data()

        EventBus.receive()
        position.update()
        navigator.navigate()
示例#5
0
  def new_conn(self):
    if len(self.conns) <= self.max_conn:
      eb = EventBus("http://{}/eventbus".format(self.host))
      self.conns.append(eb)
      def onopen(message):
        print "onopen"
        eb.registerHandler(self.address, handler)

      def handler(message, replyTo):
        print(message)

      eb.addEventListener("open", onopen)
      threads.deferToThread(eb.connect)
    def navigate(self):
        self.data['driver'].update()
        if self.mode == Navigator.AUTONOMOUS:
            next_state = self.state.run(self.data)

            curr_type = type(self.state)
            next_type = type(next_state)

            if curr_type is not Turn and next_type is Turn:
                EventBus.notify(CMD_TURN_STARTED)

            if curr_type is Stabilize and next_type is not Stabilize:
                EventBus.notify(CMD_TURN_FINISHED, self.state.is_right_turn)

            self.state = next_state
示例#7
0
def update():
    global gui, last_data_request_time, curr_test_corn, bt_client
    if not gui.exit_demanded:
        if gui.finished_setup:
            EventBus.receive()
            if (datetime.datetime.now() - last_data_request_time) > datetime.timedelta(
                    milliseconds=DATA_REQUEST_INTERVAL):
                if bt_client is not None and bt_client.is_connected:
                    request_data()

                last_data_request_time = datetime.datetime.now()
        else:
            gui.setup_after_main_loop()
        gui.canvas.after(UPDATE_INTERVAL, update)
    else:
        print("Exit gui in client main")
        outbound.bt_restart()
        while bt_client is not None and not bt_client.restart_demanded:
            pass
        gui.close_window()
def bt_request_servo_data():
    EventBus.post(BLUETOOTH_ADDR, BT_task(BT_REQUEST_SERVO_DATA))
def bt_request_sensor_data():
    EventBus.post(BLUETOOTH_ADDR, BT_task(BT_REQUEST_SENSOR_DATA))
示例#10
0
def request_ip():
    EventBus.post(BLUETOOTH_ADDR, BT_task(REQUEST_PI_IP))
示例#11
0
def setup():
    global eventBus
    eventBus = EventBus()

    global soundHandler
    soundHandler = SoundHandler()
    eventBus.addCoinCollectedListener(soundHandler)
    eventBus.addKeyCollectedListener(soundHandler)
    eventBus.addDoorOpeningListener(soundHandler)
    eventBus.addPlayerFootstepListener(soundHandler)
    eventBus.addMapTransitionListener(soundHandler)
    eventBus.addEndGameListener(soundHandler)
    eventBus.addLifeLostListener(soundHandler)
    eventBus.addWaspZoomingListener(soundHandler)
    eventBus.addBeetleCrawlingListener(soundHandler)
    eventBus.addCheckpointReachedListener(soundHandler)
    eventBus.addPlayerFallingListener(soundHandler)
    eventBus.addBladesStabbingListener(soundHandler)
    eventBus.addBoatMovingListener(soundHandler)
    eventBus.addTitleShownListener(soundHandler)
    eventBus.addGameStartedListener(soundHandler)

    global registryHandler
    registryHandler = RegistryHandler()
    eventBus.addCoinCollectedListener(registryHandler)
    eventBus.addKeyCollectedListener(registryHandler)
    eventBus.addDoorOpenedListener(registryHandler)
    eventBus.addBoatStoppedListener(registryHandler)
    eventBus.addCheckpointReachedListener(registryHandler)

    global musicPlayer
    musicPlayer = MusicPlayer()
示例#12
0
def bt_return_sensor_data(data):
    EventBus.post(BLUETOOTH_ADDR, BT_task(BT_RETURN_SENSOR_DATA, data))
示例#13
0
def bt_forward_left():
    EventBus.post(BLUETOOTH_ADDR, BT_task(BT_DRIVE_FORWARD_LEFT))
示例#14
0
def bt_drive_back():
    EventBus.post(BLUETOOTH_ADDR, BT_task(BT_DRIVE_BACK))
示例#15
0
def set_right_motor_speed(speed):
    EventBus.post(
        STYR_ADDR,
        Event(message_id=CMD_SET_RIGHT_MOTOR_SPEED, arguments=[speed]))
示例#16
0
def bt_forward_right():
    EventBus.post(BLUETOOTH_ADDR, BT_task(BT_DRIVE_FORWARD_RIGHT))
示例#17
0
def notify_mode_changed(new_mode):
    EventBus.post(BLUETOOTH_ADDR, BT_task(CMD_MODE_SET, new_mode))
示例#18
0
def bt_return_map_data(data):
    EventBus.post(BLUETOOTH_ADDR, BT_task(BT_RETURN_MAP_DATA, data))
示例#19
0
def bt_return_servo_data(data):
    EventBus.post(BLUETOOTH_ADDR, BT_task(BT_RETURN_SERVO_DATA, data))
示例#20
0
def bt_request_map_data():
    EventBus.post(BLUETOOTH_ADDR, BT_task(BT_REQUEST_MAP_DATA))
示例#21
0
def bt_restart():
    EventBus.post(BLUETOOTH_ADDR, BT_task(BT_SERVER_RESTART))
示例#22
0
def bt_drive_forward():
    EventBus.post(BLUETOOTH_ADDR, BT_task(BT_DRIVE_FORWARD))
示例#23
0
def bt_switch_to_manual():
    EventBus.post(BLUETOOTH_ADDR, BT_task(MANUAL_MODE))
示例#24
0
def bt_turn_right():
    EventBus.post(BLUETOOTH_ADDR, BT_task(BT_TURN_RIGHT))
示例#25
0
def bt_return_ip(ip):
    EventBus.post(BLUETOOTH_ADDR, BT_task(RETURN_PI_IP, ip))
示例#26
0
def bt_turn_left():
    EventBus.post(BLUETOOTH_ADDR, BT_task(BT_TURN_LEFT))
示例#27
0
def startGame(cont = False):
    global eventBus
    eventBus = EventBus()

    # create registry handler
    global registryHandler
    if cont:
        registryHandler.switchToSnapshot()
    else:
        #registry = Registry("unit", (4, 6), 1)
        registry = Registry("central", (6, 22), 2)
        #registry = Registry("central", (22, 20), 3)
        #registry = Registry("east", (10, 18), 1)
        #registry = Registry("wasps", (12, 10), 5)
        registryHandler = RegistryHandler(registry)
    # grab this for later
    registry = registryHandler.registry
    # add event listeners
    eventBus.addCoinCollectedListener(registryHandler)
    eventBus.addKeyCollectedListener(registryHandler)
    eventBus.addDoorOpenedListener(registryHandler)
    eventBus.addCheckpointReachedListener(registryHandler)
    
    global soundHandler
    soundHandler = SoundHandler()
    eventBus.addCoinCollectedListener(soundHandler)
    eventBus.addKeyCollectedListener(soundHandler)
    eventBus.addDoorOpeningListener(soundHandler)
    eventBus.addPlayerFootstepListener(soundHandler)
    eventBus.addMapTransitionListener(soundHandler)
    eventBus.addEndGameListener(soundHandler)
    eventBus.addLifeLostListener(soundHandler)
    eventBus.addWaspZoomingListener(soundHandler)
    eventBus.addBeetleCrawlingListener(soundHandler)
    eventBus.addCheckpointReachedListener(soundHandler)
    eventBus.addPlayerFallingListener(soundHandler)
    
    # create fixed sprites
    global fixedSprites
    fixedSprites = pygame.sprite.Group()
    fixedCoin = FixedCoin((27, 3))
    coinCount = CoinCount(registry.coinCount, (38, 3))
    keyCount = KeyCount(registry.keyCount, (0, 3))
    lives = Lives(2, (3, 3))
    checkpointIcon = CheckpointIcon((-11, -11))
    fixedSprites.add(fixedCoin, lives, coinCount, keyCount, checkpointIcon)
    
    # create player
    global player
    player = Ulmo()
    player.coinCount = coinCount
    player.keyCount = keyCount
    player.lives = lives
    player.checkpointIcon = checkpointIcon
    # create the map
    rpgMap = parser.loadRpgMap(registry.mapName)
    player.setup("ulmo", rpgMap, eventBus)
    # set the start position
    player.setTilePosition(registry.playerPosition[0],
                           registry.playerPosition[1],
                           registry.playerLevel)

    # return the play state
    return PlayState()
示例#28
0
def bt_shutdown():
    EventBus.post(BLUETOOTH_ADDR, BT_task(BT_SERVER_SHUTDOWN))
示例#29
0
def setup():
    Safety.setup_terminal_abort()
    EventBus.subscribe(BT_REQUEST_SENSOR_DATA, communicator.send_sensor_data)
    EventBus.subscribe(BT_REQUEST_SERVO_DATA, communicator.send_servo_data)
    EventBus.subscribe(BT_REQUEST_MAP_DATA, communicator.send_map_data)
    EventBus.subscribe(BT_DRIVE_FORWARD, communicator.drive_forward)
    EventBus.subscribe(BT_DRIVE_BACK, communicator.drive_backward)
    EventBus.subscribe(BT_TURN_RIGHT, communicator.turn_right)
    EventBus.subscribe(BT_TURN_LEFT, communicator.turn_left)
    EventBus.subscribe(BT_DRIVE_FORWARD_RIGHT,
                       communicator.drive_forward_right)
    EventBus.subscribe(BT_DRIVE_FORWARD_LEFT, communicator.drive_forward_left)
    EventBus.subscribe(AUTONOMOUS_MODE,
                       (lambda: navigator.set_mode(Navigator.AUTONOMOUS)))
    EventBus.subscribe(MANUAL_MODE,
                       (lambda: navigator.set_mode(Navigator.MANUAL)))
    EventBus.subscribe(CMD_TOGGLE_MODE, navigator.toggle_mode)
    EventBus.subscribe(REQUEST_PI_IP, communicator.send_ip)
    EventBus.subscribe(CMD_RETURN_SENSOR_DATA, ir.sensor_data_received)
    Laser.initialize()
    Gyro.initialize()
示例#30
0
def bt_switch_to_auto():
    EventBus.post(BLUETOOTH_ADDR, BT_task(AUTONOMOUS_MODE))
示例#31
0
def startGame(cont=False):
    global eventBus
    eventBus = EventBus()

    # create registry handler
    global registryHandler
    if cont:
        registryHandler.switchToSnapshot()
    else:
        #registry = Registry("unit", (4, 6), 1)
        registry = Registry("central", (6, 22), 2)
        #registry = Registry("central", (22, 20), 3)
        #registry = Registry("east", (10, 18), 1)
        #registry = Registry("wasps", (12, 10), 5)
        registryHandler = RegistryHandler(registry)
    # grab this for later
    registry = registryHandler.registry
    # add event listeners
    eventBus.addCoinCollectedListener(registryHandler)
    eventBus.addKeyCollectedListener(registryHandler)
    eventBus.addDoorOpenedListener(registryHandler)
    eventBus.addCheckpointReachedListener(registryHandler)

    global soundHandler
    soundHandler = SoundHandler()
    eventBus.addCoinCollectedListener(soundHandler)
    eventBus.addKeyCollectedListener(soundHandler)
    eventBus.addDoorOpeningListener(soundHandler)
    eventBus.addPlayerFootstepListener(soundHandler)
    eventBus.addMapTransitionListener(soundHandler)
    eventBus.addEndGameListener(soundHandler)
    eventBus.addLifeLostListener(soundHandler)
    eventBus.addWaspZoomingListener(soundHandler)
    eventBus.addBeetleCrawlingListener(soundHandler)
    eventBus.addCheckpointReachedListener(soundHandler)
    eventBus.addPlayerFallingListener(soundHandler)

    # create fixed sprites
    global fixedSprites
    fixedSprites = pygame.sprite.Group()
    fixedCoin = FixedCoin((27, 3))
    coinCount = CoinCount(registry.coinCount, (38, 3))
    keyCount = KeyCount(registry.keyCount, (0, 3))
    lives = Lives(2, (3, 3))
    checkpointIcon = CheckpointIcon((-11, -11))
    fixedSprites.add(fixedCoin, lives, coinCount, keyCount, checkpointIcon)

    # create player
    global player
    player = Ulmo()
    player.coinCount = coinCount
    player.keyCount = keyCount
    player.lives = lives
    player.checkpointIcon = checkpointIcon
    # create the map
    rpgMap = parser.loadRpgMap(registry.mapName)
    player.setup("ulmo", rpgMap, eventBus)
    # set the start position
    player.setTilePosition(registry.playerPosition[0],
                           registry.playerPosition[1], registry.playerLevel)

    # return the play state
    return PlayState()
示例#32
0
def startGame():
    global eventBus
    eventBus = EventBus()

    # create registry
    global registry
    registry = Registry()
    eventBus.addCoinCollectedListener(registry)
    eventBus.addKeyCollectedListener(registry)
    eventBus.addDoorOpenedListener(registry)
    
    global soundHandler
    soundHandler = SoundHandler()
    eventBus.addCoinCollectedListener(soundHandler)
    eventBus.addKeyCollectedListener(soundHandler)
    eventBus.addDoorOpeningListener(soundHandler)
    eventBus.addPlayerFootstepListener(soundHandler)
    eventBus.addMapTransitionListener(soundHandler)
    eventBus.addEndGameListener(soundHandler)
    eventBus.addLifeLostListener(soundHandler)
    eventBus.addWaspZoomingListener(soundHandler)
    eventBus.addBeetleCrawlingListener(soundHandler)
    
        # create fixed sprites
    global fixedSprites
    fixedSprites = pygame.sprite.Group()
    fixedCoin = FixedCoin((27, 3))
    coinCount = CoinCount(0, (38, 3))
    keyCount = KeyCount(0, (VIEW_WIDTH - 3, 3))
    lives = Lives(2, (3, 3))
    fixedSprites.add(fixedCoin, lives, coinCount, keyCount)
    
    # create player
    global player
    player = Ulmo()
    player.coinCount = coinCount
    player.keyCount = keyCount
    player.lives = lives
    # create the map
    rpgMap = parser.loadRpgMap("central")
    player.setup("ulmo", rpgMap, eventBus)
    # set the start position
    #player.setTilePosition(2, 16, 2)
    player.setTilePosition(6, 20, 2)
    #player.setTilePosition(30, 21, 3)
    #player.setTilePosition(5, 3, 4)

    # return the play state
    return PlayState()
示例#33
0
def setup():
    global eventBus
    eventBus = EventBus()

    global soundHandler
    soundHandler = SoundHandler()
    eventBus.addCoinCollectedListener(soundHandler)
    eventBus.addKeyCollectedListener(soundHandler)
    eventBus.addDoorOpeningListener(soundHandler)
    eventBus.addPlayerFootstepListener(soundHandler)
    eventBus.addMapTransitionListener(soundHandler)
    eventBus.addEndGameListener(soundHandler)
    eventBus.addLifeLostListener(soundHandler)
    eventBus.addWaspZoomingListener(soundHandler)
    eventBus.addBeetleCrawlingListener(soundHandler)
    eventBus.addCheckpointReachedListener(soundHandler)
    eventBus.addPlayerFallingListener(soundHandler)
    eventBus.addBladesStabbingListener(soundHandler)
    eventBus.addBoatMovingListener(soundHandler)
    eventBus.addTitleShownListener(soundHandler)
    eventBus.addGameStartedListener(soundHandler)

    global registryHandler
    registryHandler = RegistryHandler()
    eventBus.addCoinCollectedListener(registryHandler)
    eventBus.addKeyCollectedListener(registryHandler)
    eventBus.addDoorOpenedListener(registryHandler)
    eventBus.addBoatStoppedListener(registryHandler)
    eventBus.addCheckpointReachedListener(registryHandler)

    global musicPlayer
    musicPlayer = MusicPlayer()