commit 246fa163263f7363b5466eaf0215ba69463c33d3 Author: Vien Ngo Date: Fri Aug 28 15:48:34 2020 +0200 first commit: Mujoco Reacher 5 links diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..51ab974 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/test.iml b/.idea/test.iml new file mode 100644 index 0000000..02f1ba9 --- /dev/null +++ b/.idea/test.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..0bd2a7a --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/MUJOCO_LOG.TXT b/MUJOCO_LOG.TXT new file mode 100644 index 0000000..d398e34 --- /dev/null +++ b/MUJOCO_LOG.TXT @@ -0,0 +1,15 @@ +Fri Aug 28 14:41:56 2020 +ERROR: GLEW initalization error: Missing GL version + +Fri Aug 28 14:59:14 2020 +ERROR: GLEW initalization error: Missing GL version + +Fri Aug 28 15:03:43 2020 +ERROR: GLEW initalization error: Missing GL version + +Fri Aug 28 15:07:03 2020 +ERROR: GLEW initalization error: Missing GL version + +Fri Aug 28 15:15:01 2020 +ERROR: GLEW initalization error: Missing GL version + diff --git a/reacher.egg-info/PKG-INFO b/reacher.egg-info/PKG-INFO new file mode 100644 index 0000000..9ea9f7e --- /dev/null +++ b/reacher.egg-info/PKG-INFO @@ -0,0 +1,10 @@ +Metadata-Version: 1.0 +Name: reacher +Version: 0.0.1 +Summary: UNKNOWN +Home-page: UNKNOWN +Author: UNKNOWN +Author-email: UNKNOWN +License: UNKNOWN +Description: UNKNOWN +Platform: UNKNOWN diff --git a/reacher.egg-info/SOURCES.txt b/reacher.egg-info/SOURCES.txt new file mode 100644 index 0000000..147b0db --- /dev/null +++ b/reacher.egg-info/SOURCES.txt @@ -0,0 +1,6 @@ +setup.py +reacher.egg-info/PKG-INFO +reacher.egg-info/SOURCES.txt +reacher.egg-info/dependency_links.txt +reacher.egg-info/requires.txt +reacher.egg-info/top_level.txt \ No newline at end of file diff --git a/reacher.egg-info/dependency_links.txt b/reacher.egg-info/dependency_links.txt new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/reacher.egg-info/dependency_links.txt @@ -0,0 +1 @@ + diff --git a/reacher.egg-info/requires.txt b/reacher.egg-info/requires.txt new file mode 100644 index 0000000..1e6c2dd --- /dev/null +++ b/reacher.egg-info/requires.txt @@ -0,0 +1 @@ +gym diff --git a/reacher.egg-info/top_level.txt b/reacher.egg-info/top_level.txt new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/reacher.egg-info/top_level.txt @@ -0,0 +1 @@ + diff --git a/reacher/__init__.py b/reacher/__init__.py new file mode 100644 index 0000000..2044486 --- /dev/null +++ b/reacher/__init__.py @@ -0,0 +1,6 @@ +from gym.envs.registration import register + +register( + id='ReacherALREnv-v0', + entry_point='reacher.envs:ReacherALREnv', +) diff --git a/reacher/__pycache__/__init__.cpython-37.pyc b/reacher/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 0000000..7e115b8 Binary files /dev/null and b/reacher/__pycache__/__init__.cpython-37.pyc differ diff --git a/reacher/envs/__init__.py b/reacher/envs/__init__.py new file mode 100644 index 0000000..00340ff --- /dev/null +++ b/reacher/envs/__init__.py @@ -0,0 +1 @@ +from reacher.envs.reacher_env import ReacherALREnv diff --git a/reacher/envs/__pycache__/__init__.cpython-37.pyc b/reacher/envs/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 0000000..6409b90 Binary files /dev/null and b/reacher/envs/__pycache__/__init__.cpython-37.pyc differ diff --git a/reacher/envs/__pycache__/reacher_env.cpython-37.pyc b/reacher/envs/__pycache__/reacher_env.cpython-37.pyc new file mode 100644 index 0000000..ccdf815 Binary files /dev/null and b/reacher/envs/__pycache__/reacher_env.cpython-37.pyc differ diff --git a/reacher/envs/reacher_5links.xml b/reacher/envs/reacher_5links.xml new file mode 100644 index 0000000..07be257 --- /dev/null +++ b/reacher/envs/reacher_5links.xml @@ -0,0 +1,54 @@ + + + + + + + \ No newline at end of file diff --git a/reacher/envs/reacher_env.py b/reacher/envs/reacher_env.py new file mode 100644 index 0000000..2647413 --- /dev/null +++ b/reacher/envs/reacher_env.py @@ -0,0 +1,44 @@ +import numpy as np +from gym import utils +from gym.envs.mujoco import mujoco_env + +class ReacherALREnv(mujoco_env.MujocoEnv, utils.EzPickle): + def __init__(self): + utils.EzPickle.__init__(self) + mujoco_env.MujocoEnv.__init__(self, '/home/vien/git/reacher_test/reacher/envs/reacher_5links.xml', 2) + + def step(self, a): + vec = self.get_body_com("fingertip")-self.get_body_com("target") + reward_dist = - np.linalg.norm(vec) + reward_ctrl = - np.square(a).sum() + reward = reward_dist + reward_ctrl + self.do_simulation(a, self.frame_skip) + ob = self._get_obs() + done = False + return ob, reward, done, dict(reward_dist=reward_dist, reward_ctrl=reward_ctrl) + + def viewer_setup(self): + self.viewer.cam.trackbodyid = 0 + + def reset_model(self): + qpos = self.np_random.uniform(low=-0.1, high=0.1, size=self.model.nq) + self.init_qpos + while True: + self.goal = self.np_random.uniform(low=-.2, high=.2, size=2) + if np.linalg.norm(self.goal) < 0.2: + break + qpos[-2:] = self.goal + qvel = self.init_qvel + self.np_random.uniform(low=-.005, high=.005, size=self.model.nv) + qvel[-2:] = 0 + self.set_state(qpos, qvel) + + return self._get_obs() + + def _get_obs(self): + theta = self.sim.data.qpos.flat[:5] + return np.concatenate([ + np.cos(theta), + np.sin(theta), + self.sim.data.qpos.flat[5:], # this is goal position + self.sim.data.qvel.flat[:5], # this is angular velocity + self.get_body_com("fingertip") - self.get_body_com("target") + ]) diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..d8affaa --- /dev/null +++ b/setup.py @@ -0,0 +1,6 @@ +from setuptools import setup + +setup(name='reacher', + version='0.0.1', + install_requires=['gym'] # And any other dependencies foo needs +) \ No newline at end of file diff --git a/test.py b/test.py new file mode 100644 index 0000000..4cb210b --- /dev/null +++ b/test.py @@ -0,0 +1,13 @@ +import gym + + +if __name__ == "__main__": + env = gym.make('reacher:ReacherALREnv-v0') + #env = gym.make('Hopper-v2') + env.reset() + + for i in range(10000): + action = env.action_space.sample() + obs = env.step(action) + print("step",i) + env.render()