<filename>test_particle.py
"""
Note: this has to be called from outside directory. 
TODO figure out Python package structure...
"""

import numpy as np
from math import sqrt
import gym
import particle_env.env

if __name__ == "__main__":
    env = gym.make('Particle-3-4-Sparse-v0')
    goal = np.array([3, 4]) # TODO find a way to build this into env? 

    print('Running PD controller towards goal {}'.format(goal))

    obs = env.reset()

    done = False
    while not done: 
        env.render()

        # PD controller 
        kp = 3
        kd = 1.5*sqrt(kp)
        force = (goal - obs[:2]) * kp + (-obs[2:]*kd)

        obs, reward, done, _ = env.step(force)

        if done:
            if reward==100:
                print('Goal achieved!')
            else:
                print('Episode ended')


<filename>test_particle.py
"""
Note: this has to be called from outside directory. 
TODO figure out Python package structure...
"""

import numpy as np
from math import sqrt
import gym
import particle_env.env

if __name__ == "__main__":
    env = gym.make('Particle-3-4-Sparse-v0')
    goal = np.array([3, 4]) # TODO find a way to build this into env? 

    print('Running PD controller towards goal {}'.format(goal))

    obs = env.reset()

    done = False
    while not done: 
        env.render()

        # PD controller 
        kp = 3
        kd = 1.5*sqrt(kp)
        force = (goal - obs[:2]) * kp + (-obs[2:]*kd)

        obs, reward, done, _ = env.step(force)

        if done:
            if reward==100:
                print('Goal achieved!')
            else:
                print('Episode ended')


Note: this has to be called from outside directory.  TODO figure out Python package structure... # TODO find a way to build this into env? # PD controller