Skip to content

Commit

Permalink
Merge pull request #44 from WPI-MMR/hotfix-goobta-get-obs
Browse files Browse the repository at this point in the history
[Hotfix] Expose get_obs() to realtime env API
  • Loading branch information
mahajanrevant authored Feb 2, 2021
2 parents 268264b + 8cc061c commit 85fe8d8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
2 changes: 0 additions & 2 deletions examples/solo8_vanilla/realtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
import gym_solo
from gym_solo.envs import solo8v2vanilla
from gym_solo.core import obs
from gym_solo.core import rewards
from gym_solo.core import termination as terms


if __name__ == '__main__':
Expand Down
16 changes: 8 additions & 8 deletions gym_solo/envs/solo8v2vanilla.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,9 @@ def reset(self, init_call: bool = False) -> solo_types.obs:
"""
self.client.removeBody(self.robot)
self.load_bodies()

joint_ordering = [self.client.getJointInfo(self.robot, j)[1].decode('UTF-8')
for j in range(self._joint_cnt)]
positions = [self.config.starting_joint_pos[j] for j in joint_ordering]

positions = [self.config.starting_joint_pos[j]
for j in self.joint_ordering]

# Let the robot lay down flat, as intended. Note that this is a hack
# around modifying the URDF, but that should really be handled in the
Expand Down Expand Up @@ -140,18 +139,19 @@ def load_bodies(self) -> Tuple[int, int]:
self.config.robot_start_orientation_euler),
flags=p.URDF_USE_INERTIA_FROM_FILE, useFixedBase=False)

joint_cnt = self.client.getNumJoints(robot_id)
for joint in range(joint_cnt):
self._joint_cnt = self.client.getNumJoints(robot_id)
for joint in range(self._joint_cnt):
self.client.changeDynamics(robot_id, joint,
linearDamping=self.config.linear_damping,
angularDamping=self.config.angular_damping,
restitution=self.config.restitution,
lateralFriction=self.config.lateral_friction)


self.robot = robot_id
self._joint_cnt = joint_cnt
self._zero_gains = np.zeros(self._joint_cnt)

self.joint_ordering = [self.client.getJointInfo(self.robot, j)[1].decode('UTF-8')
for j in range(self._joint_cnt)]
self._action_space = spaces.Box(-self.config.max_motor_rotation,
self.config.max_motor_rotation,
shape=(self._joint_cnt,))
11 changes: 10 additions & 1 deletion gym_solo/envs/solo8v2vanilla_realtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,13 @@ def reset(self, *args, **kwargs):
"""
super().reset(*args, **kwargs)
# Since stepSimulation() is a noop, need to use time to reset the bot
time.sleep(1)
time.sleep(1)

def get_obs(self):
"""Get the current observation of the environment.
Note this is different from the OpenAI gym `get_obs()` as this is
a realtime simulation, so `get_obs()` can have different results even
if `env.step()` isn't called.
"""
return self.obs_factory.get_obs()

0 comments on commit 85fe8d8

Please sign in to comment.