예제 #1
0
    def __init__(self, *args, **kwargs):
        super().__init__(self.model_path("cartpole.xml.mako"), *args, **kwargs)

        self.max_cart_pos = 3
        self.max_reward_cart_pos = 3
        self.cart = find_body(self.world, "cart")
        self.pole = find_body(self.world, "pole")

        # Always call Serializable constructor last
        Serializable.quick_init(self, locals())
예제 #2
0
 def __init__(self, *args, **kwargs):
     self.max_pole_angle = .2
     self.max_cart_pos = 2.4
     self.max_cart_speed = 4.
     self.max_pole_speed = 4.
     self.reset_range = 0.05
     super(CartpoleEnv, self).__init__(
         self.model_path("cartpole.xml.mako"), *args, **kwargs)
     self.cart = find_body(self.world, "cart")
     self.pole = find_body(self.world, "pole")
     Serializable.__init__(self, *args, **kwargs)
예제 #3
0
    def __init__(self, *args, **kwargs):
        self.max_pole_angle = .2
        self.max_cart_pos = 2.4
        self.max_cart_speed = 4.
        self.max_pole_speed = 4.
        self.reset_range = 0.05
        super().__init__(self.model_path("cartpole.xml.mako"), *args, **kwargs)
        self.cart = find_body(self.world, "cart")
        self.pole = find_body(self.world, "pole")

        # Always call Serializable constructor last
        Serializable.quick_init(self, locals())
예제 #4
0
 def __init__(self, *args, **kwargs):
     # make sure mdp-level step is 100ms long
     kwargs["frame_skip"] = kwargs.get("frame_skip", 2)
     if kwargs.get("template_args", {}).get("noise", False):
         self.link_len = (np.random.rand() - 0.5) + 1
     else:
         self.link_len = 1
     kwargs["template_args"] = kwargs.get("template_args", {})
     kwargs["template_args"]["link_len"] = self.link_len
     super(DoublePendulumEnv,
           self).__init__(self.model_path("double_pendulum.xml.mako"),
                          *args, **kwargs)
     self.link1 = find_body(self.world, "link1")
     self.link2 = find_body(self.world, "link2")
     Serializable.__init__(self, *args, **kwargs)
예제 #5
0
 def forward_dynamics(self, action):
     if len(action) != flat_dim(self.action_space) + 1:
         raise ValueError('incorrect action dimension: expected %d but got '
                          '%d' % (flat_dim(self.action_space), len(action)))
     lb, ub = self.action_bounds
     action = np.clip(action, lb, ub)
     for ctrl, act in zip(self.extra_data.controls, action):
         if ctrl.typ == "force":
             for name in ctrl.bodies:
                 body = find_body(self.world, name)
                 direction = np.array(ctrl.direction)
                 direction = direction / np.linalg.norm(direction)
                 world_force = body.GetWorldVector(direction * act)
                 world_point = body.GetWorldPoint(ctrl.anchor)
                 body.ApplyForce(world_force, world_point, wake=True)
         elif ctrl.typ == "torque":
             assert ctrl.joint
             joint = find_joint(self.world, ctrl.joint)
             joint.motorEnabled = True
             # forces the maximum allowed torque to be taken
             if act > 0:
                 joint.motorSpeed = 1e5
             else:
                 joint.motorSpeed = -1e5
             joint.maxMotorTorque = abs(act)
         else:
             raise NotImplementedError
     self.before_world_step(action)
     self.world.Step(self.extra_data.timeStep,
                     self.extra_data.velocityIterations,
                     self.extra_data.positionIterations)
예제 #6
0
 def __init__(self, *args, **kwargs):
     Serializable.__init__(self, *args, **kwargs)
     self.random_start = kwargs.pop("random_start", True)
     self.random_start_range = kwargs.pop("random_start_range", 1.)
     super(CarParkingEnv, self).__init__(self.model_path("car_parking.xml"),
                                         *args, **kwargs)
     self.goal = find_body(self.world, "goal")
     self.car = find_body(self.world, "car")
     self.wheels = [
         body for body in self.world.bodies if "wheel" in _get_name(body)
     ]
     self.front_wheels = [
         body for body in self.wheels if "front" in _get_name(body)
     ]
     self.max_deg = 30.
     self.goal_radius = 1.
     self.vel_thres = 1e-1
     self.start_radius = 5.
예제 #7
0
 def __init__(self, height_bonus=1., goal_cart_pos=0.6, *args, **kwargs):
     super(MountainCarEnv,
           self).__init__(self.model_path("mountain_car.xml.mako"), *args,
                          **kwargs)
     self.max_cart_pos = 2
     self.goal_cart_pos = goal_cart_pos
     self.height_bonus = height_bonus
     self.cart = find_body(self.world, "cart")
     Serializable.quick_init(self, locals())
예제 #8
0
    def __init__(self, height_bonus=1., goal_cart_pos=0.6, *args, **kwargs):
        super().__init__(self.model_path("mountain_car.xml.mako"), *args,
                         **kwargs)

        self.max_cart_pos = 2
        self.goal_cart_pos = goal_cart_pos
        self.height_bonus = height_bonus
        self.cart = find_body(self.world, "cart")

        # Always call Serializable constructor last
        Serializable.quick_init(self, locals())
예제 #9
0
    def __init__(self,
                 random_start=True,
                 random_start_range=1.0,
                 *args,
                 **kwargs):
        self.random_start = random_start
        self.random_start_range = random_start_range
        super().__init__(self.model_path("car_parking.xml"), *args, **kwargs)
        self.goal = find_body(self.world, "goal")
        self.car = find_body(self.world, "car")
        self.wheels = [
            body for body in self.world.bodies if "wheel" in _get_name(body)
        ]
        self.front_wheels = [
            body for body in self.wheels if "front" in _get_name(body)
        ]
        self.max_deg = 30.
        self.goal_radius = 1.
        self.vel_thres = 1e-1
        self.start_radius = 5.

        # Always call Serializable constructor last
        Serializable.quick_init(self, locals())