コード例 #1
0
    def __init__(self, name, tasks=None):
        super(Memory, self).__init__(name, tasks)

        self.builtin_tasks = [
            Task(name='cue_receiver', callback=self.receive_cue),
            Task(name='learner', callback=self.receive_broadcast)
        ]
コード例 #2
0
    def __init__(self, tasks=None):
        super(OXPlayerEnvironment, self).__init__(tasks=tasks)
        self._board = Board.blank_board()
        self._turn = PLAYER1
        self._player1 = partial(np.random.choice, a=self._board.blanks)
        self._player2 = OXPlayerEnvironment.receive_move

        self.builtin_tasks = [
            Task(name='update_env', callback=self.update),
            Task(name='publish_board', callback=self.publish_board),
            Task(name='publish_turn', callback=self.publish_turn)
        ]
コード例 #3
0
    def __init__(self, tasks=None):
        super(ActionSelection, self).__init__("action_selection", tasks)

        self.behavior_net = BehaviorNetwork()

        self.builtin_tasks = [
            Task("cand_recv_task", callback=self.receive_candidates),
            Task("behav_sel_task", callback=self.select_behavior),
            Task("behav_pub_task", callback=self.publish_selected_behavior),
            Task("decay_task", callback=self.decay),
            Task("learn_task", callback=self.learn)
        ]

        # The candidate_behaviors queue is used for the temporary storage of a set of instantiated
        # candidate behaviors.  These will be processed by a background task to determine
        # which (if any) will be selected for execution.
        self.candidate_behaviors = LocalMessageQueue()

        # The selected_behaviors queue is used for the temporary storage of a set of selected
        # behaviors.  These will be published to sensory motor memory for execution.
        self.selected_behaviors = LocalMessageQueue()
コード例 #4
0
    def test_background_task(self):
        class CallBack(object):
            def __init__(self):
                self.count = 0

            def __call__(self):
                self.count += 1

        callback_cls = CallBack()

        bg_task = Task(name='test', callback=callback_cls, exec_count=100)
        bg_task.start()
        bg_task.wait_until_complete()

        # Verify that execution count matches expected number of executions
        self.assertEqual(100, callback_cls.count)
コード例 #5
0
    if not action:
        action = STOP

    wheel_cmd = WheelCommand()
    wheel_cmd.angle = action.angle
    wheel_cmd.force = action.direction * float(
        lidapy.get_param('wheel_force', section='action_execution'))

    ACTUATOR.send(wheel_cmd)

    # Sleep to let wheel command execution occur for the expected duration before
    # changing commands
    sleep(action.duration)


# Initialize the lidapy framework
lidapy.init(Config(file_path=argv[1], use_param_service=True),
            log_level=lidapy.LOG_LEVEL_DEBUG)

processes = [
    LIDAProcess('action_execution',
                [Task('action_execution', execute_action)]),
    LIDAProcess('action_selection',
                [Task('action_selector', determine_action)]),
    LIDAProcess('stuck_detector', [Task('stuck_detector', detect_stuck)]),
    LIDAProcess('path_detection', [Task('path_detector', detect_path)])
]
for p in processes:
    p.start()
    sleep(1)
コード例 #6
0
    def __init__(self, tasks=None):
        super(GlobalWorkspace, self).__init__("global_workspace", tasks)

        self.builtin_tasks = [
            Task(name="coalition_receiver", callback=self.receive_coalitions)
        ]
コード例 #7
0
dorsal_turn_topic = lidapy.Topic('oxplayer/player2/dorsal/turn')


def see_board():
    board_state = board_state_topic.receive()
    lidapy.loginfo('Received board_state:' + str(board_state))
    if board_state:
        board_state = ast.literal_eval(board_state)
        blank = first_blank(board_state)
        lidapy.loginfo('blank position:' + str(blank))
        blank_position.send(blank)


def dorsal_update():
    turn = turn_topic.receive()
    lidapy.loginfo('Received turn:' + str(turn))
    if turn == PLAYER1 or turn == PLAYER2:
        dorsal_turn_topic.send(turn)
        lidapy.loginfo('Published to ' + str(dorsal_turn_topic) + ': ' +
                       str(turn))


sensory_memory = SensoryMemory()
agent_config = Config()
agent_config.set_param('rate_in_hz', 1)
lidapy.init(config=agent_config)

sensory_memory.tasks.append(Task(name='see_board', callback=see_board))
sensory_memory.tasks.append(Task(name='dorsal_stream', callback=dorsal_update))
sensory_memory.start()
コード例 #8
0
sms = SensoryMotorMemory()
sms.turn = PLAYER1


def make_move():
    msg = blank_position.receive()
    lidapy.loginfo('Received blank_position:'+str(msg))
    lidapy.loginfo('Current turn:'+str(sms.turn))
    if msg is not None and sms.turn == PLAYER2:
        lidapy.loginfo(msg)
        lidapy.loginfo('motor move:'+str(msg))
        action_topic.send(msg)


def receive_turn():
    turn = dorsal_turn_topic.receive()
    lidapy.loginfo('Received turn:'+str(turn))
    if turn:
        sms.turn = int(turn)


agent_config = Config()
agent_config.set_param('rate_in_hz', 1)
lidapy.init(config=agent_config)

sms.tasks.append(Task(name='make_move', callback=make_move))
sms.tasks.append(Task(name='receive_turn', callback=receive_turn))

sms.start()