def __init__(self, seed=None):
    self.screen = None
    self.params = parameters.Params()
    self.physics_eng = physics.PhysicsSim()

    # Ball XY positions can be between -1.5 and 1.5
    ball0_os = spaces.Box(low=np.array([-self.params.TABLE_SIZE[0]/2., -self.params.TABLE_SIZE[1]/2.]),
                          high=np.array([self.params.TABLE_SIZE[0] / 2., self.params.TABLE_SIZE[1] / 2.]))

    ball1_os = spaces.Box(low=np.array([-self.params.TABLE_SIZE[0]/2., -self.params.TABLE_SIZE[1]/2.]),
                          high=np.array([self.params.TABLE_SIZE[0]/2., self.params.TABLE_SIZE[1]/2.]))

    # Arm joint can have positons:
    # Joint 0: [-Pi/2, Pi/2]
    # Joint 1: [-Pi, Pi]
    joints_angle = spaces.Box(low=np.array([-np.pi / 2, -np.pi]), high=np.array([np.pi / 2, np.pi]))
    joints_vel = spaces.Box(low=np.array([-50, -50]), high=np.array([50, 50]))

    self.observation_space = spaces.Tuple([ball0_os, ball1_os, joints_angle, joints_vel])

    # Actions are torques on joints and open/close of arm grip.
    # Joint torques can be between [-1, 1]
    self.action_space = spaces.Box(low=np.array([-1., -1.]), high=np.array([1., 1.]))

    self.seed(seed)
Пример #2
0
def test_create_table():
  physics_eng = physics.PhysicsSim()
  assert len(physics_eng.walls) == 4, 'Not all the walls have been created'
  for wall in physics_eng.walls:
    assert wall.active == True, 'Wall {} not active'.format(wall.userData['name'])
    assert wall.angle == 0.0, 'Wall {} angle not 0.0'.format(wall.userData['name'])
    assert wall.awake == True, 'Wall {} not awake'.format(wall.userData['name'])
    assert wall.inertia == 0.0, 'Wall {} inertia not 0.0. This means wall is Dynamic.'.format(wall.userData['name'])
  del physics_eng
Пример #3
0
    def __init__(self, seed=None, max_steps=500):
        """ Constructor
    :param seed: the random seed for the environment
    :param max_steps: the maximum number of steps the episode lasts
    :return:
    """
        self.screen = None
        self.params = parameters.Params()
        self.params.MAX_ENV_STEPS = max_steps
        self.physics_eng = physics.PhysicsSim()

        ## Ball XY positions can be between -1.5 and 1.5
        ## Arm joint can have positons:
        # Joint 0: [-Pi/2, Pi/2]
        # Joint 1: [-Pi, Pi]
        self.observation_space = spaces.Box(
            low=np.array([
                -self.params.TABLE_SIZE[0] / 2.,
                -self.params.TABLE_SIZE[1] / 2.,  # ball pose
                -np.pi / 2,
                -np.pi,  # joint angles
                -50,
                -50
            ]),  # joint vels
            high=np.array([
                self.params.TABLE_SIZE[0] / 2.,
                self.params.TABLE_SIZE[1] / 2.,  # ball pose
                np.pi / 2,
                np.pi,  # joint angles
                50,
                50
            ]),
            dtype=np.float32)  # joint vels

        ## Joint commands can be between [-1, 1]
        self.action_space = spaces.Box(low=np.array([-1., -1.]),
                                       high=np.array([1., 1.]),
                                       dtype=np.float32)

        self.goals = np.array(
            [hole['pose'] for hole in self.physics_eng.holes])
        self.goalRadius = [hole['radius'] for hole in self.physics_eng.holes]
        self.rew_area = None

        self.seed(seed)
Пример #4
0
    def __init__(self, seed=None, max_steps=500):
        """ Constructor
    :param seed: the random seed for the environment
    :param max_steps: the maximum number of steps the episode lasts
    :return:
    """
        self.screen = None
        self.params = parameters.Params()
        self.physics_eng = physics.PhysicsSim()
        self.params.MAX_ENV_STEPS = max_steps

        ## Ball XY positions can be between -1.5 and 1.5
        ball0_os = spaces.Box(low=np.array(
            [-self.params.TABLE_SIZE[0] / 2.,
             -self.params.TABLE_SIZE[1] / 2.]),
                              high=np.array([
                                  self.params.TABLE_SIZE[0] / 2.,
                                  self.params.TABLE_SIZE[1] / 2.
                              ]))

        ball1_os = spaces.Box(low=np.array(
            [-self.params.TABLE_SIZE[0] / 2.,
             -self.params.TABLE_SIZE[1] / 2.]),
                              high=np.array([
                                  self.params.TABLE_SIZE[0] / 2.,
                                  self.params.TABLE_SIZE[1] / 2.
                              ]))

        ## Arm joint can have positons:
        # Joint 0: [-Pi/2, Pi/2]
        # Joint 1: [-Pi, Pi]
        joints_angle = spaces.Box(low=np.array([-np.pi / 2, -np.pi]),
                                  high=np.array([np.pi / 2, np.pi]))
        joints_vel = spaces.Box(low=np.array([-50, -50]),
                                high=np.array([50, 50]))

        self.observation_space = spaces.Tuple(
            [ball0_os, ball1_os, joints_angle, joints_vel])

        ## Joint commands can be between [-1, 1]
        self.action_space = spaces.Box(low=np.array([-1., -1.]),
                                       high=np.array([1., 1.]))

        self.seed(seed)
Пример #5
0
def test_create_ball():
  physics_eng = physics.PhysicsSim(balls_pose=[[1,2]])
  assert len(physics_eng.balls) == 1, 'Not enough balls'
  assert physics_eng.balls[0].position + physics_eng.wt_transform == b2.b2Vec2([1, 2]), 'Wrong ball pose'