fix new minitaur envs for newer Gym (_step -> step etc),
add extra sleep to sync Minitaur walk with RTC clock
This commit is contained in:
@@ -17,6 +17,7 @@ import minitaur_logging
|
|||||||
import minitaur_logging_pb2
|
import minitaur_logging_pb2
|
||||||
import minitaur_rainbow_dash
|
import minitaur_rainbow_dash
|
||||||
import motor
|
import motor
|
||||||
|
from pkg_resources import parse_version
|
||||||
|
|
||||||
NUM_MOTORS = 8
|
NUM_MOTORS = 8
|
||||||
MOTOR_ANGLE_OBSERVATION_INDEX = 0
|
MOTOR_ANGLE_OBSERVATION_INDEX = 0
|
||||||
@@ -563,6 +564,13 @@ class MinitaurGymEnv(gym.Env):
|
|||||||
"""
|
"""
|
||||||
return len(self._get_observation())
|
return len(self._get_observation())
|
||||||
|
|
||||||
|
if parse_version(gym.__version__)>=parse_version('0.9.6'):
|
||||||
|
close = _close
|
||||||
|
render = _render
|
||||||
|
reset = _reset
|
||||||
|
seed = _seed
|
||||||
|
step = _step
|
||||||
|
|
||||||
def set_time_step(self, control_step, simulation_step=0.001):
|
def set_time_step(self, control_step, simulation_step=0.001):
|
||||||
"""Sets the time step of the environment.
|
"""Sets the time step of the environment.
|
||||||
|
|
||||||
@@ -604,3 +612,5 @@ class MinitaurGymEnv(gym.Env):
|
|||||||
@property
|
@property
|
||||||
def env_step_counter(self):
|
def env_step_counter(self):
|
||||||
return self._env_step_counter
|
return self._env_step_counter
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import argparse
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
import tensorflow as tf
|
import tensorflow as tf
|
||||||
import minitaur_gym_env
|
import minitaur_gym_env
|
||||||
|
import time
|
||||||
|
|
||||||
|
|
||||||
#FLAGS = flags.FLAGS
|
#FLAGS = flags.FLAGS
|
||||||
@@ -53,6 +54,7 @@ def ResetPoseExample(log_path=None):
|
|||||||
action = [math.pi / 2] * 8
|
action = [math.pi / 2] * 8
|
||||||
for _ in range(steps):
|
for _ in range(steps):
|
||||||
_, _, done, _ = environment.step(action)
|
_, _, done, _ = environment.step(action)
|
||||||
|
time.sleep(1./100.)
|
||||||
if done:
|
if done:
|
||||||
break
|
break
|
||||||
|
|
||||||
@@ -96,6 +98,7 @@ def MotorOverheatExample(log_path=None):
|
|||||||
observation, _, _, _ = environment.step(action)
|
observation, _, _, _ = environment.step(action)
|
||||||
current_row.extend(observation.tolist())
|
current_row.extend(observation.tolist())
|
||||||
actions_and_observations.append(current_row)
|
actions_and_observations.append(current_row)
|
||||||
|
time.sleep(1./100.)
|
||||||
|
|
||||||
if FLAGS.output_filename is not None:
|
if FLAGS.output_filename is not None:
|
||||||
WriteToCSV(FLAGS.output_filename, actions_and_observations)
|
WriteToCSV(FLAGS.output_filename, actions_and_observations)
|
||||||
@@ -142,6 +145,7 @@ def SineStandExample(log_path=None):
|
|||||||
observation, _, _, _ = environment.step(action)
|
observation, _, _, _ = environment.step(action)
|
||||||
current_row.extend(observation.tolist())
|
current_row.extend(observation.tolist())
|
||||||
actions_and_observations.append(current_row)
|
actions_and_observations.append(current_row)
|
||||||
|
time.sleep(1./100.)
|
||||||
|
|
||||||
if FLAGS.output_filename is not None:
|
if FLAGS.output_filename is not None:
|
||||||
WriteToCSV(FLAGS.output_filename, actions_and_observations)
|
WriteToCSV(FLAGS.output_filename, actions_and_observations)
|
||||||
@@ -189,6 +193,8 @@ def SinePolicyExample(log_path=None):
|
|||||||
a4 = math.sin(t * speed + math.pi) * amplitude2
|
a4 = math.sin(t * speed + math.pi) * amplitude2
|
||||||
action = [a1, a2, a2, a1, a3, a4, a4, a3]
|
action = [a1, a2, a2, a1, a3, a4, a4, a3]
|
||||||
_, reward, done, _ = environment.step(action)
|
_, reward, done, _ = environment.step(action)
|
||||||
|
time.sleep(1./100.)
|
||||||
|
|
||||||
sum_reward += reward
|
sum_reward += reward
|
||||||
if done:
|
if done:
|
||||||
tf.logging.info("Return is {}".format(sum_reward))
|
tf.logging.info("Return is {}".format(sum_reward))
|
||||||
|
|||||||
Reference in New Issue
Block a user