Skip to content

Commit

Permalink
Merge pull request #196 from maxspahn/ft-gymnasium-migration
Browse files Browse the repository at this point in the history
Ft gymnasium migration
  • Loading branch information
maxspahn authored Jun 19, 2023
2 parents dc6401d + b3ad4ae commit bf45db8
Show file tree
Hide file tree
Showing 44 changed files with 173 additions and 123 deletions.
4 changes: 2 additions & 2 deletions examples/albert.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import warnings
import gym
import gymnasium as gym
import numpy as np
from urdfenvs.robots.generic_urdf.generic_diff_drive_robot import GenericDiffDriveRobot
from urdfenvs.urdf_common.urdf_env import UrdfEnv
Expand Down Expand Up @@ -32,7 +32,7 @@ def run_albert(n_steps=1000, render=False, goal=True, obstacles=True):
print(f"Initial observation : {ob}")
history = []
for _ in range(n_steps):
ob, _, _, _ = env.step(action)
ob, *_ = env.step(action)
history.append(ob)
env.close()
return history
Expand Down
4 changes: 2 additions & 2 deletions examples/boxer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import gym
import gymnasium as gym
from urdfenvs.scene_examples.obstacles import wall_obstacles
import numpy as np

Expand Down Expand Up @@ -30,7 +30,7 @@ def run_boxer(n_steps=1000, render=False, goal=True, obstacles=True):
print("Starting episode")
history = []
for _ in range(n_steps):
ob, _, _, _ = env.step(action)
ob, *_ = env.step(action)
print(ob['robot_0']['joint_state']['velocity'][0:2])
history.append(ob)
env.close()
Expand Down
4 changes: 2 additions & 2 deletions examples/dual_arm.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import gym
import gymnasium as gym
import numpy as np
from urdfenvs.robots.generic_urdf import GenericUrdfReacher

Expand All @@ -16,7 +16,7 @@ def run_dual_arm(n_steps=5000, render=False, goal=True, obstacles=True):
print(f"Initial observation : {ob}")
history = []
for _ in range(n_steps):
ob, _, _, _ = env.step(action)
ob, *_ = env.step(action)
history.append(ob)
env.close()
return history
Expand Down
4 changes: 2 additions & 2 deletions examples/generic_holonomic.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import gym
import gymnasium as gym
from urdfenvs.robots.generic_urdf import GenericUrdfReacher
import numpy as np
import os
Expand Down Expand Up @@ -35,7 +35,7 @@ def run_generic_holonomic(n_steps=1000, render=False, goal=True, obstacles=True)
print("Starting episode")
history = []
for _ in range(n_steps):
ob, _, _, _ = env.step(action)
ob, *_ = env.step(action)
history.append(ob)
env.close()
return history
Expand Down
4 changes: 2 additions & 2 deletions examples/heijn.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import gym
import gymnasium as gym
import numpy as np
from urdfenvs.scene_examples.obstacles import *
from urdfenvs.scene_examples.goal import *
Expand Down Expand Up @@ -28,7 +28,7 @@ def run_point_robot(n_steps=1000, render=False, goal=True, obstacles=True):
env.add_goal(splineGoal)
history = []
for _ in range(n_steps):
ob, _, _, _ = env.step(action)
ob, *_ = env.step(action)
history.append(ob)
env.close()
return history
Expand Down
4 changes: 2 additions & 2 deletions examples/iris.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import gym
import gymnasium as gym
import numpy as np
from urdfenvs.robots.iris import IrisDrone

Expand All @@ -22,7 +22,7 @@ def run_iris(n_steps=3000, render=False, goal=True, obstacles=True):
action += np.array([0, 1, 0, 1]) * 1
if i > 248 and i < 298:
action += np.array([0, 1, 0, 1]) * -1
ob, _, _, _ = env.step(action)
ob, *_ = env.step(action)
history.append(ob)
env.close()
return history
Expand Down
4 changes: 2 additions & 2 deletions examples/jackal.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import gym
import gymnasium as gym
import numpy as np

from urdfenvs.scene_examples.obstacles import wall_obstacles
Expand Down Expand Up @@ -33,7 +33,7 @@ def run_jackal(n_steps=1000, render=False, goal=True, obstacles=True):
print("Starting episode")
history = []
for _ in range(n_steps):
ob, _, _, _ = env.step(action)
ob, *_ = env.step(action)
history.append(ob)
env.close()
return history
Expand Down
2 changes: 1 addition & 1 deletion examples/keyboard_input.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import gym
import gymnasium as gym
from urdfenvs.robots.tiago import TiagoRobot

from multiprocessing import Process, Pipe
Expand Down
4 changes: 2 additions & 2 deletions examples/mobile_reacher.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import gym
import gymnasium as gym
from urdfenvs.robots.generic_urdf import GenericUrdfReacher
import numpy as np

Expand All @@ -25,7 +25,7 @@ def run_mobile_reacher(n_steps=1000, render=False, goal=True, obstacles=True):
else:
action[-1] = 0.01
action[-2] = 0.01
ob, _, _, _ = env.step(action)
ob, *_ = env.step(action)
history.append(ob)
env.close()
return history
Expand Down
4 changes: 2 additions & 2 deletions examples/multi_robot.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import gym
import gymnasium as gym
import numpy as np
from urdfenvs.robots.generic_urdf import GenericUrdfReacher
from urdfenvs.robots.generic_urdf import GenericDiffDriveRobot
Expand Down Expand Up @@ -78,7 +78,7 @@ def run_multi_robot(n_steps=1000, render=False, obstacles=False, goal=False):
print("Starting episode")
history = []
for _ in range(n_steps):
ob, _, _, _ = env.step(action)
ob, *_ = env.step(action)
history.append(ob)
env.close()
return history
Expand Down
4 changes: 2 additions & 2 deletions examples/n_link_urdf_reacher.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import gym
import gymnasium as gym
from urdfenvs.robots.generic_urdf import GenericUrdfReacher
import numpy as np

Expand All @@ -17,7 +17,7 @@ def run_n_link_reacher(n_steps=1000, render=False, goal=True, obstacles=True):
print(f"Initial observation : {ob}")
history = []
for _ in range(n_steps):
ob, _, _, _ = env.step(action)
ob, *_ = env.step(action)
history.append(ob)
env.close()
return history
Expand Down
4 changes: 2 additions & 2 deletions examples/panda_reacher.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import gym
import gymnasium as gym
import numpy as np
from urdfenvs.robots.generic_urdf import GenericUrdfReacher
from urdfenvs.scene_examples.goal import dynamicGoal
Expand Down Expand Up @@ -46,7 +46,7 @@ def run_panda(n_steps=1000, render=False, goal=True, obstacles=True):
action[7] = 0.02
action[8] = 0.02
collision_links_position: dict = env.collision_links_poses(position_only=True)
ob, _, _, _ = env.step(action)
ob, *_ = env.step(action)
history.append(ob)
env.close()
return history
Expand Down
4 changes: 2 additions & 2 deletions examples/point_robot.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import gym
import gymnasium as gym
from urdfenvs.robots.generic_urdf import GenericUrdfReacher
import numpy as np

Expand Down Expand Up @@ -32,7 +32,7 @@ def run_point_robot(n_steps=1000, render=False, goal=True, obstacles=True):
history = []
env.reconfigure_camera(2.0, 0.0, -90.01, (0, 0, 0))
for _ in range(n_steps):
ob, _, _, _ = env.step(action)
ob, *_ = env.step(action)
history.append(ob)
env.close()
return history
Expand Down
4 changes: 2 additions & 2 deletions examples/point_robot_3dlidar_sensor.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import gym
import gymnasium as gym
import numpy as np
from urdfenvs.scene_examples.obstacles import (
sphereObst1,
Expand Down Expand Up @@ -46,7 +46,7 @@ def run_point_robot_with_lidar(
print(f"Initial observation : {ob}")
history = []
for _ in range(n_steps):
ob, _, _, _ = env.step(action)
ob, *_ = env.step(action)
# Access the lidar observation
#_ = ob["robot_0"]["LidarSensor"]

Expand Down
4 changes: 2 additions & 2 deletions examples/point_robot_free_space_decomp.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import gym
import gymnasium as gym
import pprint
import numpy as np
from urdfenvs.scene_examples.obstacles import (
Expand Down Expand Up @@ -41,7 +41,7 @@ def run_point_robot_with_freespacedecomp(
print(f"Initial observation : {ob}")
history = []
for _ in range(n_steps):
ob, _, _, _ = env.step(action)
ob, *_ = env.step(action)
#print(ob['robot_0']['FreeSpaceDecompSensor'])
# Access the lidar observation
#_ = ob["robot_0"]["LidarSensor"]
Expand Down
2 changes: 1 addition & 1 deletion examples/point_robot_full_sensor.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import gym
import gymnasium as gym
from urdfenvs.urdf_common.urdf_env import UrdfEnv
from urdfenvs.robots.generic_urdf import GenericUrdfReacher
from urdfenvs.sensors.full_sensor import FullSensor
Expand Down
4 changes: 2 additions & 2 deletions examples/point_robot_lidar_sensor.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import gym
import gymnasium as gym
import numpy as np
from urdfenvs.scene_examples.obstacles import (
sphereObst1,
Expand Down Expand Up @@ -40,7 +40,7 @@ def run_point_robot_with_lidar(
print(f"Initial observation : {ob}")
history = []
for _ in range(n_steps):
ob, _, _, _ = env.step(action)
ob, *_ = env.step(action)
# Access the lidar observation
#_ = ob["robot_0"]["LidarSensor"]

Expand Down
4 changes: 2 additions & 2 deletions examples/point_robot_obstacle_sensor.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import gym
import gymnasium as gym
from urdfenvs.robots.generic_urdf import GenericUrdfReacher
from urdfenvs.sensors.obstacle_sensor import ObstacleSensor
from urdfenvs.scene_examples.obstacles import (
Expand Down Expand Up @@ -36,7 +36,7 @@ def run_point_robot_with_obstacle_sensor(n_steps=1000, render=False, obstacles=T
history = []
for _ in range(n_steps):
action = defaultAction
ob, reward, done, info = env.step(action)
ob, *_ = env.step(action)
# In observations, information about obstacles is stored in ob['obstacleSensor']
history.append(ob)
env.close()
Expand Down
2 changes: 1 addition & 1 deletion examples/point_robot_reward.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@


class InverseDistanceDenseReward(Reward):
def calculateReward(self, observation: dict) -> float:
def calculate_reward(self, observation: dict) -> float:
goal = observation['robot_0']['FullSensor']['goals'][1]['position']
position = observation['robot_0']['joint_state']['position']
return 1.0/np.linalg.norm(goal-position)
Expand Down
2 changes: 1 addition & 1 deletion examples/point_robot_sdf_sensor.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import gym
import gymnasium as gym
import numpy as np

from urdfenvs.urdf_common.urdf_env import UrdfEnv
Expand Down
4 changes: 2 additions & 2 deletions examples/prius.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import gym
import gymnasium as gym
from urdfenvs.robots.prius import Prius
import numpy as np

Expand All @@ -17,7 +17,7 @@ def run_prius(n_steps=1000, render=False, goal=True, obstacles=True):
print(f"Initial observation : {ob}")
history = []
for i in range(n_steps):
ob, _, _, _ = env.step(action)
ob, *_ = env.step(action)
if ob['robot_0']['joint_state']['steering'] > 0.2:
action[1] = 0
history.append(ob)
Expand Down
6 changes: 3 additions & 3 deletions examples/tiago.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import gym
import gymnasium as gym
from urdfenvs.robots.generic_urdf.generic_diff_drive_robot import GenericDiffDriveRobot
import numpy as np

Expand Down Expand Up @@ -48,7 +48,7 @@ def run_tiago(n_steps=1000, render=False, goal=True, obstacles=True):
action[14] = 0.0 # right arm shoulder
action[22] = 0.01 # finger joint
vel0 = np.zeros(env.n())
ob = env.reset()
ob, *_ = env.reset()
print("base: ", ob['robot_0']["joint_state"]["position"][0:3])
print("torso: ", ob['robot_0']["joint_state"]["position"][3])
print("head: ", ob['robot_0']["joint_state"]["position"][4:6])
Expand All @@ -57,7 +57,7 @@ def run_tiago(n_steps=1000, render=False, goal=True, obstacles=True):
print("Starting episode")
history = []
for _ in range(n_steps):
ob, _, _, _ = env.step(action)
ob, *_ = env.step(action)
history.append(ob)
env.close()
return history
Expand Down
Loading

0 comments on commit bf45db8

Please sign in to comment.