1414from rcs .envs .utils import default_sim_robot_cfg , default_sim_tilburg_hand_cfg
1515
1616import rcs
17+ import time
1718from rcs import sim
19+ from rcs .utils import SimpleFrameRate
1820
1921logger = logging .getLogger (__name__ )
2022logger .setLevel (logging .INFO )
@@ -33,7 +35,7 @@ def __init__(self, env: gym.Env, simulation: sim.Sim):
3335
3436
3537class RobotSimWrapper (gym .Wrapper ):
36- def __init__ (self , env , simulation : sim .Sim , sim_wrapper : Type [ SimWrapper ] | None = None ):
38+ def __init__ (self , env , simulation : sim .Sim , sim_wrapper : SimWrapper | None = None ):
3739 self .sim_wrapper = sim_wrapper
3840 if sim_wrapper is not None :
3941 env = sim_wrapper (env , simulation )
@@ -42,10 +44,20 @@ def __init__(self, env, simulation: sim.Sim, sim_wrapper: Type[SimWrapper] | Non
4244 assert isinstance (self .unwrapped .robot , sim .SimRobot ), "Robot must be a sim.SimRobot instance."
4345 self .sim_robot = cast (sim .SimRobot , self .unwrapped .robot )
4446 self .sim = simulation
47+ cfg = self .sim .get_config ()
48+ self .frame_rate = SimpleFrameRate (1 / cfg .frequency , "RobotSimWrapper" )
4549
4650 def step (self , action : dict [str , Any ]) -> tuple [dict [str , Any ], float , bool , bool , dict ]:
4751 _ , _ , _ , _ , info = super ().step (action )
48- self .sim .step_until_convergence ()
52+ cfg = self .sim .get_config ()
53+ if cfg .async_control :
54+ self .sim .step (round (1 / cfg .frequency / self .sim .model .opt .timestep ))
55+ if cfg .realtime :
56+ self .frame_rate .frame_rate = 1 / cfg .frequency
57+ self .frame_rate ()
58+
59+ else :
60+ self .sim .step_until_convergence ()
4961 state = self .sim_robot .get_state ()
5062 info ["collision" ] = state .collision
5163 info ["ik_success" ] = state .ik_success
@@ -348,7 +360,7 @@ def reset(
348360class RandomCubePos (SimWrapper ):
349361 """Wrapper to randomly place cube in the lab environments."""
350362
351- def __init__ (self , env : gym .Env , simulation : sim .Sim , include_rotation : bool = False ):
363+ def __init__ (self , env : gym .Env , simulation : sim .Sim , include_rotation : bool = True ):
352364 super ().__init__ (env , simulation )
353365 self .include_rotation = include_rotation
354366
@@ -361,7 +373,7 @@ def reset(
361373 iso_cube = np .array ([0.498 , 0.0 , 0.226 ])
362374 iso_cube_pose = rcs .common .Pose (translation = np .array (iso_cube ), rpy_vector = np .array ([0 , 0 , 0 ])) # type: ignore
363375 iso_cube = self .unwrapped .robot .to_pose_in_world_coordinates (iso_cube_pose ).translation ()
364- pos_z = 0.826
376+ pos_z = 0.0288 / 2
365377 pos_x = iso_cube [0 ] + np .random .random () * 0.2 - 0.1
366378 pos_y = iso_cube [1 ] + np .random .random () * 0.2 - 0.1
367379
0 commit comments