コード例 #1
0
def test_physicality():
    """
    Test coordinate system [vertical is 0]
        1) gravity acts in proper direction based on origin
        2) torque actions behave as expected in that frame
    """
    # Apply a bunch of non-torque actions, ensure that monotonically accelerate

    LEFT_FORCE = 0
    NO_FORCE = 1
    RIGHT_FORCE = 2

    domain = InfCartPoleSwingUp()
    domain.force_noise_max = 0  # no stochasticity in applied FORCE

    # Positive angle (right)
    s = np.array([10.0 * np.pi / 180.0, 0.0])  # pendulum slightly right
    domain.state = s.copy()

    for i in np.arange(5):  # do for 5 steps and ensure works
        domain.step(NO_FORCE)
        assert np.all(domain.state > s)  # angle and angular velocity increase
        s = domain.state.copy()

    # Negative angle (left)
    s = np.array([-10.0 * np.pi / 180.0, 0.0])  # pendulum slightly right
    domain.state = s.copy()

    for i in np.arange(5):  # do for 5 steps and ensure works
        domain.step(NO_FORCE)
        assert np.all(domain.state < s)  # angle and angular velocity increase
        s = domain.state.copy()
コード例 #2
0
def test_physicality():
    """
    Test coordinate system [vertical is 0]
        1) gravity acts in proper direction based on origin
        2) torque actions behave as expected in that frame
    """
    # Apply a bunch of non-torque actions, ensure that monotonically accelerate

    LEFT_FORCE = 0
    NO_FORCE = 1
    RIGHT_FORCE = 2

    domain = InfCartPoleSwingUp()
    domain.force_noise_max = 0 # no stochasticity in applied FORCE

    # Positive angle (right)
    s = np.array([10.0 * np.pi/180.0, 0.0]) # pendulum slightly right
    domain.state = s.copy()

    for i in np.arange(5): # do for 5 steps and ensure works
        domain.step(NO_FORCE)
        assert np.all(domain.state > s) # angle and angular velocity increase
        s = domain.state.copy()

    # Negative angle (left)
    s = np.array([-10.0 * np.pi/180.0, 0.0]) # pendulum slightly right
    domain.state = s.copy()

    for i in np.arange(5): # do for 5 steps and ensure works
        domain.step(NO_FORCE)
        assert np.all(domain.state < s) # angle and angular velocity increase
        s = domain.state.copy()
コード例 #3
0
def test_physicality_hanging():
    """
    Test that energy does not spontaneously enter system
    """
    # Apply a bunch of non-torque actions, ensure that monotonically accelerate

    LEFT_FORCE = 0
    NO_FORCE = 1
    RIGHT_FORCE = 2

    domain = InfCartPoleSwingUp()
    domain.force_noise_max = 0 # no stochasticity in applied FORCE

    # Positive angle (right)
    s = np.array([179.6 * np.pi/180.0, 0.0]) # pendulum hanging down
    domain.state = s

    for i in np.arange(5): # do for 5 steps and ensure works
        domain.step(NO_FORCE)
        assert np.abs(domain.state[0]) <=179.5 # angle does not increase
        assert np.abs(domain.state[1]) <= 0.1 # angular rate does not increase
        s = domain.state
コード例 #4
0
def test_physicality_hanging():
    """
    Test that energy does not spontaneously enter system
    """
    # Apply a bunch of non-torque actions, ensure that monotonically accelerate

    LEFT_FORCE = 0
    NO_FORCE = 1
    RIGHT_FORCE = 2

    domain = InfCartPoleSwingUp()
    domain.force_noise_max = 0  # no stochasticity in applied FORCE

    # Positive angle (right)
    s = np.array([179.6 * np.pi / 180.0, 0.0])  # pendulum hanging down
    domain.state = s

    for i in np.arange(5):  # do for 5 steps and ensure works
        domain.step(NO_FORCE)
        assert np.abs(domain.state[0]) <= 179.5  # angle does not increase
        assert np.abs(domain.state[1]) <= 0.1  # angular rate does not increase
        s = domain.state
コード例 #5
0
 def myfn(*args, **kwargs):
     return _make_experiment(InfCartPoleSwingUp(), *args, **kwargs)