Skip to content

Commit

Permalink
ft[robotmodels]: Modifies examples and tests to work with robot models.
Browse files Browse the repository at this point in the history
  • Loading branch information
maxspahn committed Feb 16, 2024
1 parent 3520d84 commit 46daf4b
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 11 deletions.
1 change: 1 addition & 0 deletions examples/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
__pycache__
panda
2 changes: 1 addition & 1 deletion examples/dual_arm.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

def run_dual_arm(n_steps=5000, render=False, goal=True, obstacles=True):
robots = [
GenericUrdfReacher(urdf="dual_arm.urdf", mode="vel"),
GenericUrdfReacher(urdf="dualArm.urdf", mode="vel"),
]
env = gym.make(
"urdf-env-v0",
Expand Down
2 changes: 1 addition & 1 deletion examples/mobile_reacher.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

def run_mobile_reacher(n_steps=1000, render=False, goal=True, obstacles=True):
robots = [
GenericUrdfReacher(urdf="mobilePandaWithGripper.urdf", mode="vel"),
GenericUrdfReacher(urdf="mobilePanda_with_gripper.urdf", mode="vel"),
]
env = gym.make(
"urdf-env-v0",
Expand Down
13 changes: 11 additions & 2 deletions examples/panda_mujoco.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import numpy as np
import os
import sys
import shutil
import numpy as np
import gymnasium as gym
from robotmodels.utils.robotmodel import RobotModel, LocalRobotModel
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
Expand All @@ -10,10 +13,16 @@

def run_panda(n_steps: int = 1000, render: bool = True, physics_engine: str = "bullet"):
obstacles = [sphereObst1, sphereObst2, cylinder_obstacle] + wall_obstacles
shutil.rmtree('panda')
robot_model_original = RobotModel('panda', 'panda_scene')
robot_model_original.copy_model(os.path.join(os.getcwd(), 'panda'))
robot_model = LocalRobotModel('panda', 'panda_scene')

xml_file = robot_model.get_xml_path()
if physics_engine == "mujoco":

robots = [
GenericMujocoRobot(xml_file="panda_scene.xml", mode="vel"),
GenericMujocoRobot(xml_file=xml_file, mode="vel"),
]
env = GenericMujocoEnv(robots, obstacles, render=render)
if physics_engine == "bullet":
Expand Down
7 changes: 5 additions & 2 deletions examples/panda_reacher.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import gymnasium as gym
import numpy as np
from robotmodels.utils.robotmodel import RobotModel
from urdfenvs.robots.generic_urdf import GenericUrdfReacher
from urdfenvs.scene_examples.goal import dynamicGoal
from urdfenvs.scene_examples.obstacles import dynamicSphereObst2
from urdfenvs.urdf_common.urdf_env import UrdfEnv

def run_panda(n_steps=1000, render=False, goal=True, obstacles=True):
robot_model = RobotModel('panda', model_name='panda_with_gripper')
urdf_file = robot_model.get_urdf_path()
robots = [
GenericUrdfReacher(urdf="panda_with_gripper.urdf", mode="vel"),
GenericUrdfReacher(urdf=urdf_file, mode="vel"),
]
env: UrdfEnv = gym.make(
"urdf-env-v0",
Expand All @@ -19,7 +22,7 @@ def run_panda(n_steps=1000, render=False, goal=True, obstacles=True):
env.add_obstacle(dynamicSphereObst2)
env.set_spaces()
action = np.ones(env.n()) * 0.1
ob = env.reset()
ob = env.reset(pos=robot_model.home_cfg())
env.add_collision_link(
robot_index=0,
link_index=5,
Expand Down
2 changes: 1 addition & 1 deletion examples/tiago.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def run_tiago(n_steps=1000, render=False, goal=True, obstacles=True):

robots = [
GenericDiffDriveRobot(
urdf="tiago_dual.urdf",
urdf="tiago.urdf",
mode="vel",
actuated_wheels=["wheel_right_joint", "wheel_left_joint"],
castor_wheels=[
Expand Down
4 changes: 2 additions & 2 deletions tests/test_acc_envs.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def nLinkRobotEnv():

@pytest.fixture
def dualArmEnv():
robot = GenericUrdfReacher(urdf="dual_arm.urdf", mode="acc")
robot = GenericUrdfReacher(urdf="dualArm.urdf", mode="acc")
init_pos = np.zeros(robot.n())
init_vel = np.zeros(robot.n())
return (robot, init_pos, init_vel)
Expand Down Expand Up @@ -72,7 +72,7 @@ def tiagoReacherEnv():
init_pos[3] = 0.1
init_vel = np.zeros(23)
robot = GenericDiffDriveRobot(
urdf="tiago_dual.urdf",
urdf="tiago.urdf",
mode="acc",
actuated_wheels=["wheel_right_joint", "wheel_left_joint"],
castor_wheels=[
Expand Down
4 changes: 2 additions & 2 deletions tests/test_vel_envs.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def tiagoReacherEnv():
init_pos[3] = 0.1
init_vel = np.zeros(23)
robot = GenericDiffDriveRobot(
urdf="tiago_dual.urdf",
urdf="tiago.urdf",
mode="vel",
actuated_wheels=["wheel_right_joint", "wheel_left_joint"],
castor_wheels=[
Expand Down Expand Up @@ -112,7 +112,7 @@ def priusEnv():
@pytest.fixture
def dualArmEnv():
from urdfenvs.robots.generic_urdf import GenericUrdfReacher
robot = GenericUrdfReacher(urdf="dual_arm.urdf", mode="vel")
robot = GenericUrdfReacher(urdf="dualArm.urdf", mode="vel")
init_pos = np.zeros(robot.n())
init_vel = np.zeros(robot.n())
return (robot, init_pos, init_vel)
Expand Down

0 comments on commit 46daf4b

Please sign in to comment.