Пример #1
0
    def _get_initial_positions_frame(self):
        '''Returns the position of each robot and ball for the initial frame'''
        pos_frame: Frame = Frame()

        def x():
            return random.uniform(-1.5, 1.5)

        def y():
            return random.uniform(1.5, -1.5)

        pos_frame.ball = Ball(x=x(), y=y())
        factor = (pos_frame.ball.y / abs(pos_frame.ball.y))
        offset = 0.115 * factor
        angle = 270 if factor > 0 else 90
        pos_frame.robots_blue[0] = Robot(x=pos_frame.ball.x,
                                         y=pos_frame.ball.y + offset,
                                         theta=angle)
        shooter = np.array(
            [pos_frame.robots_blue[0].x, pos_frame.robots_blue[0].y])
        recv_x = x()
        while abs(recv_x - pos_frame.ball.x) < 1:
            recv_x = x()
        receiver = np.array([recv_x, -pos_frame.ball.y])
        vect = receiver - shooter
        recv_angle = np.rad2deg(np.arctan2(vect[1], vect[0]) + np.pi)

        pos_frame.robots_blue[1] = Robot(x=receiver[0],
                                         y=receiver[1],
                                         theta=recv_angle)

        return pos_frame
Пример #2
0
    def _get_commands(self, actions):
        commands = []
        self.actions = {}

        for i in range(self.n_robots_control):
            self.actions[i] = actions[i]
            v_wheel0, v_wheel1 = self._actions_to_v_wheels(actions[i])
            commands.append(
                Robot(yellow=False, id=i, v_wheel0=v_wheel0,
                      v_wheel1=v_wheel1))

        for i in range(self.n_robots_control, self.n_robots_blue):
            actions = self.action_space.sample()
            v_wheel0, v_wheel1 = self._actions_to_v_wheels(actions)
            commands.append(
                Robot(yellow=False, id=i, v_wheel0=v_wheel0,
                      v_wheel1=v_wheel1))

        atk_action = self.opp.get_action(self._opp_obs())
        v_wheel0, v_wheel1 = self._actions_to_v_wheels(atk_action)
        commands.append(
            Robot(yellow=True, id=0, v_wheel0=v_wheel1, v_wheel1=v_wheel0))
        for i in range(1, self.n_robots_yellow):
            actions = self.action_space.sample()
            v_wheel0, v_wheel1 = self._actions_to_v_wheels(actions)
            commands.append(
                Robot(yellow=True, id=i, v_wheel0=v_wheel0, v_wheel1=v_wheel1))

        return commands
Пример #3
0
    def _get_commands(self, actions):
        commands = []
        self.actions = {}

        # Send random commands to the other robots
        for i in range(self.n_robots_control):
            self.actions[i] = actions[i]
            v_wheel0, v_wheel1 = self._actions_to_v_wheels(actions[i])
            commands.append(
                Robot(yellow=False, id=i, v_wheel0=v_wheel0,
                      v_wheel1=v_wheel1))

        for i in range(self.n_robots_control, self.n_robots_blue):
            actions = self.ou_actions[i].sample()
            v_wheel0, v_wheel1 = self._actions_to_v_wheels(actions[0])
            commands.append(
                Robot(yellow=False, id=i, v_wheel0=v_wheel0,
                      v_wheel1=v_wheel1))

        for i in range(self.n_robots_yellow):
            actions = self.ou_actions[self.n_robots_blue + i].sample()
            v_wheel0, v_wheel1 = self._actions_to_v_wheels(actions[0])
            commands.append(
                Robot(yellow=True, id=i, v_wheel0=v_wheel0, v_wheel1=v_wheel1))

        return commands
Пример #4
0
    def _get_initial_positions_frame(self):
        '''Returns the position of each robot and ball for the initial frame'''
        # TODO

        pos_frame: Frame = Frame()

        pos_frame.ball = Ball(x=-0.1, y=0.)

        pos_frame.robots_blue[0] = Robot(x=0., y=0., theta=180.)

        pos_frame.robots_yellow[0] = Robot(x=self.node_0, y=0., theta=180.)
        pos_frame.robots_yellow[1] = Robot(x=self.node_1, y=0., theta=180.)
        pos_frame.robots_yellow[2] = Robot(x=self.node_2, y=0., theta=180.)
        pos_frame.robots_yellow[3] = Robot(x=self.node_3, y=0., theta=180.)

        return pos_frame
Пример #5
0
    def _get_initial_positions_frame(self):
        '''Returns the position of each robot and ball for the initial frame'''
        half_len = self.field.length / 2
        half_wid = self.field.width / 2
        pen_len = self.field.penalty_length
        half_pen_wid = self.field.penalty_width / 2
        pos_frame: Frame = Frame()
        def x(): return random.uniform(pen_len, half_len - pen_len)
        def y(): return random.uniform(-half_pen_wid, half_pen_wid)
        
        pos_frame.robots_blue[0] = Robot(x=0, y=0, theta=0.)
        enemy_x = x()
        enemy_y = y()

        pos_frame.ball = Ball(x=enemy_x-0.1, y=enemy_y)
        pos_frame.robots_yellow[0] = Robot(x=enemy_x, y=enemy_y, theta=180.)

        return pos_frame
Пример #6
0
    def _get_commands(self, actions):
        commands = []

        angle = self.frame.robots_blue[0].theta
        v_x, v_y, v_theta = self.convert_actions(actions, np.deg2rad(angle))
        cmd = Robot(yellow=False, id=0, v_x=v_x, v_y=v_y, v_theta=v_theta)
        commands.append(cmd)

        return commands
Пример #7
0
    def _get_initial_positions_frame(self):
        '''Returns the position of each robot and ball for the initial frame'''
        field_half_length = self.field.length / 2
        field_half_width = self.field.width / 2

        def x():
            return random.uniform(-field_half_length + 0.1,
                                  field_half_length - 0.1)

        def y():
            return random.uniform(-field_half_width + 0.1,
                                  field_half_width - 0.1)

        def theta():
            return random.uniform(0, 360)

        pos_frame: Frame = Frame()

        pos_frame.ball = Ball(x=x(), y=y())

        min_dist = 0.1

        places = KDTree()
        places.insert((pos_frame.ball.x, pos_frame.ball.y))

        for i in range(self.n_robots_blue):
            pos = (x(), y())
            while places.get_nearest(pos)[1] < min_dist:
                pos = (x(), y())

            places.insert(pos)
            pos_frame.robots_blue[i] = Robot(x=pos[0], y=pos[1], theta=theta())

        for i in range(self.n_robots_yellow):
            pos = (x(), y())
            while places.get_nearest(pos)[1] < min_dist:
                pos = (x(), y())

            places.insert(pos)
            pos_frame.robots_yellow[i] = Robot(x=pos[0],
                                               y=pos[1],
                                               theta=theta())

        return pos_frame
Пример #8
0
    def _get_initial_positions_frame(self):
        '''Returns the position of each robot and ball for the initial frame'''
        half_len = self.field.length / 2
        half_wid = self.field.width / 2
        pen_len = self.field.penalty_length
        half_pen_wid = self.field.penalty_width / 2

        def x():
            return random.uniform(0.2, half_len - 0.1)

        def y():
            return random.uniform(-half_wid + 0.1, half_wid - 0.1)

        def theta():
            return random.uniform(0, 360)

        pos_frame: Frame = Frame()

        pos_frame.robots_blue[0] = Robot(x=0., y=0., theta=0.)

        def in_gk_area(obj):
            return obj.x > half_len - pen_len and abs(obj.y) < half_pen_wid

        pos_frame.ball = Ball(x=x(), y=y())
        while in_gk_area(pos_frame.ball):
            pos_frame.ball = Ball(x=x(), y=y())

        min_dist = 0.2

        places = KDTree()
        places.insert((pos_frame.ball.x, pos_frame.ball.y))
        places.insert((pos_frame.robots_blue[0].x, pos_frame.robots_blue[0].y))
        for i in range(self.n_robots_yellow):
            pos = (x(), y())
            while places.get_nearest(pos)[1] < min_dist:
                pos = (x(), y())

            places.insert(pos)
            pos_frame.robots_yellow[i] = Robot(x=pos[0],
                                               y=pos[1],
                                               theta=theta())

        return pos_frame
Пример #9
0
    def _get_initial_positions_frame(self):
        '''Returns the position of each robot and ball for the initial frame'''
        if self.random_init:
            half_len = self.field.length / 2
            half_wid = self.field.width / 2
            penalty_len = self.field.penalty_length

            def x():
                return random.uniform(0.3, half_len - penalty_len - 0.3)

            def y():
                return random.uniform(-half_wid + 0.1, half_wid - 0.1)

            def theta():
                return random.uniform(0, 360)
        else:

            def x():
                return self.field.length / 4

            def y():
                return self.field.width / 8

            def theta():
                return 0

        pos_frame: Frame = Frame()

        def same_position_ref(obj, ref, dist):
            if abs(obj.x - ref.x) < dist and abs(obj.y - ref.y) < dist:
                return True
            return False

        pos_frame.ball = Ball(x=x(), y=y())

        d_ball_rbt = (self.field.ball_radius + self.field.rbt_radius) * 1.1
        pos_frame.robots_blue[0] = Robot(x=x(), y=-y(), theta=theta())
        while same_position_ref(pos_frame.robots_blue[0], pos_frame.ball,
                                d_ball_rbt):
            pos_frame.robots_blue[0] = Robot(x=x(), y=y(), theta=theta())

        return pos_frame
Пример #10
0
    def _get_commands(self, actions):
        commands = []

        angle = self.frame.robots_blue[0].theta
        v_x, v_y, v_theta = self.convert_actions(actions, np.deg2rad(angle))
        cmd = Robot(yellow=False, id=0, v_x=v_x, v_y=v_y, v_theta=v_theta,
                    kick_v_x=self.kick_speed_x if actions[3] > 0 else 0., 
                    dribbler=True if actions[4] > 0 else False)
        commands.append(cmd)

        return commands
Пример #11
0
    def _get_commands(self, actions):
        commands = []
        actions[1] = actions[1] if abs(actions[1]) > 0.5 else 0
        self.actions = actions
        cmd = Robot(yellow=False,
                    id=0,
                    v_x=0,
                    v_y=0,
                    v_theta=actions[0] * self.max_w,
                    kick_v_x=actions[1] * self.max_kick_x,
                    dribbler=True if actions[2] > 0 else False)
        commands.append(cmd)

        cmd = Robot(yellow=False,
                    id=1,
                    v_x=0,
                    v_y=0,
                    v_theta=0,
                    kick_v_x=0,
                    dribbler=True)
        commands.append(cmd)

        return commands
Пример #12
0
    def _get_commands(self, actions):
        commands = []
        actions[0][3] = actions[0][3] if abs(actions[0][3]) > 0.5 else 0
        actions[1][3] = actions[1][3] if abs(actions[1][3]) > 0.5 else 0

        for i in range(self.n_robots_blue):
            angle = self.frame.robots_blue[i].theta
            v_x, v_y, v_theta = self.convert_actions(actions[i],
                                                     np.deg2rad(angle))
            cmd = Robot(yellow=False,
                        id=i,
                        v_x=v_x,
                        v_y=v_y,
                        v_theta=v_theta,
                        kick_v_x=actions[i][3] * self.max_kick_x,
                        dribbler=True if actions[i][4] > 0 else False)
            commands.append(cmd)

        return commands
Пример #13
0
    def _get_initial_positions_frame(self):
        '''Returns the position of each robot and ball for the inicial frame'''
        field_half_length = self.field_params['field_length'] / 2
        field_half_width = self.field_params['field_width'] / 2

        def x():
            return random.uniform(-field_half_length + 0.1,
                                  field_half_length - 0.1)

        def y():
            return random.uniform(-field_half_width + 0.1,
                                  field_half_width - 0.1)

        def theta():
            return random.uniform(-180, 180)

        pos_frame: Frame = Frame()

        pos_frame.ball.x = x()
        pos_frame.ball.y = y()
        pos_frame.ball.v_x = 0.
        pos_frame.ball.v_y = 0.

        agents = []
        for i in range(self.n_robots_blue):
            pos_frame.robots_blue[i] = Robot(x=x(), y=y(), theta=theta())
            agents.append(pos_frame.robots_blue[i])

        for i in range(self.n_robots_yellow):
            pos_frame.robots_yellow[i] = Robot(x=x(), y=y(), theta=theta())
            agents.append(pos_frame.robots_blue[i])

        def same_position_ref(x, y, x_ref, y_ref, radius):
            if x >= x_ref - radius and x <= x_ref + radius and \
                    y >= y_ref - radius and y <= y_ref + radius:
                return True
            return False

        radius_ball = 0.2
        radius_robot = 0.2
        same_pos = True

        while same_pos:
            for i in range(len(agents)):
                same_pos = False
                while same_position_ref(agents[i].x, agents[i].y,
                                        pos_frame.ball.x, pos_frame.ball.y,
                                        radius_ball):
                    agents[i] = Robot(x=x(), y=y(), theta=theta())
                    same_pos = True
                for j in range(i + 1, len(agents)):
                    while same_position_ref(agents[i].x, agents[i].y,
                                            agents[j].x, agents[j].y,
                                            radius_robot):
                        agents[i] = Robot(x=x(), y=y(), theta=theta())
                        same_pos = True

        pos_frame.robots_blue[0] = agents[0]
        pos_frame.robots_blue[1] = agents[1]
        pos_frame.robots_blue[2] = agents[2]
        pos_frame.robots_yellow[0] = agents[3]
        pos_frame.robots_yellow[1] = agents[4]
        pos_frame.robots_yellow[2] = agents[5]

        return pos_frame