Skip to content

Commit

Permalink
ft[examples]: observation checking and info for panda mujoco example.
Browse files Browse the repository at this point in the history
  • Loading branch information
maxspahn committed Dec 21, 2023
1 parent 3f8de60 commit 99df7a8
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions examples/panda_mujoco.py
Original file line number Diff line number Diff line change
@@ -1,44 +1,46 @@
import numpy as np
import sys
import gymnasium as gym
from urdfenvs.urdf_common.generic_mujoco_env import GenericMujocoEnv
from urdfenvs.urdf_common.generic_mujoco_robot import GenericMujocoRobot
from urdfenvs.generic_mujoco.generic_mujoco_env import GenericMujocoEnv
from urdfenvs.generic_mujoco.generic_mujoco_robot import GenericMujocoRobot
from urdfenvs.robots.generic_urdf import GenericUrdfReacher
from urdfenvs.urdf_common.urdf_env import UrdfEnv
from urdfenvs.scene_examples.obstacles import sphereObst1, sphereObst2, wall_obstacles, cylinder_obstacle


def run_panda(n_steps: int = 1000, render: bool = True, physics_engine: str = 'bullet'):
def run_panda(n_steps: int = 1000, render: bool = True, physics_engine: str = "bullet"):
obstacles = [sphereObst1, sphereObst2, cylinder_obstacle] + wall_obstacles
if physics_engine == 'mujoco':
if physics_engine == "mujoco":

robots = [
GenericMujocoRobot(xml_file='panda_scene.xml'),
GenericMujocoRobot(xml_file="panda_scene.xml", mode="vel"),
]
env = GenericMujocoEnv(robots, obstacles, render=True)
if physics_engine == 'bullet':
env = GenericMujocoEnv(robots, obstacles, render=render)
if physics_engine == "bullet":
robots = [
GenericUrdfReacher(urdf="panda.urdf", mode="vel"),
]
env= UrdfEnv(
dt=0.01, robots=robots,
render=True,
render=render,
observation_checking=False,
)
for obstacle in obstacles:
env.add_obstacle(obstacle)
env.set_spaces()


#observation, info = env.reset(seed=42)
pos0=np.array([0,0,0,-1.57079,0,1.57079,-0.7853,0.04,0.04])
env.reset(pos=pos0)
ob, info = env.reset()

action_mag = np.array([0.3, -0.2, 0.3, -0.15, 0.2, -0.01, 0.35, 0.01])
action_mag = np.array([0.8, -0.2, 0.3, -0.15, 0.2, -0.01, 0.35, 0.01])
t = 0.0
for _ in range(n_steps):
t += env.dt
action = action_mag * np.cos(t)
observation, *_ = env.step(action)
ob, _, terminated, _, info = env.step(action)
if terminated:
print(info)
break
env.close()

if __name__ == "__main__":
Expand Down

0 comments on commit 99df7a8

Please sign in to comment.