|
| 1 | +import time |
| 2 | + |
| 3 | +from robosuite.robots import MobileRobot |
| 4 | +from robosuite.utils.input_utils import * |
| 5 | + |
| 6 | +MAX_FR = 25 # max frame rate for running simluation |
| 7 | + |
| 8 | +if __name__ == "__main__": |
| 9 | + |
| 10 | + # Create dict to hold options that will be passed to env creation call |
| 11 | + options = {} |
| 12 | + |
| 13 | + # print welcome info |
| 14 | + print("Welcome to robosuite v{}!".format(suite.__version__)) |
| 15 | + print(suite.__logo__) |
| 16 | + |
| 17 | + # Choose environment and add it to options |
| 18 | + options["env_name"] = choose_environment() |
| 19 | + |
| 20 | + # If a multi-arm environment has been chosen, choose configuration and appropriate robot(s) |
| 21 | + if "TwoArm" in options["env_name"]: |
| 22 | + # Choose env config and add it to options |
| 23 | + options["env_configuration"] = choose_multi_arm_config() |
| 24 | + |
| 25 | + # If chosen configuration was bimanual, the corresponding robot must be Baxter. Else, have user choose robots |
| 26 | + if options["env_configuration"] == "single-robot": |
| 27 | + options["robots"] = choose_robots(exclude_bimanual=False, use_humanoids=True, exclude_single_arm=True) |
| 28 | + else: |
| 29 | + options["robots"] = [] |
| 30 | + |
| 31 | + # Have user choose two robots |
| 32 | + for i in range(2): |
| 33 | + print("Please choose Robot {}...\n".format(i)) |
| 34 | + options["robots"].append(choose_robots(exclude_bimanual=False, use_humanoids=True)) |
| 35 | + # If a humanoid environment has been chosen, choose humanoid robots |
| 36 | + elif "Humanoid" in options["env_name"]: |
| 37 | + options["robots"] = choose_robots(use_humanoids=True) |
| 38 | + else: |
| 39 | + options["robots"] = choose_robots(exclude_bimanual=False, use_humanoids=True) |
| 40 | + |
| 41 | + # initialize the task |
| 42 | + env = suite.make( |
| 43 | + **options, |
| 44 | + has_renderer=True, |
| 45 | + has_offscreen_renderer=False, |
| 46 | + ignore_done=True, |
| 47 | + use_camera_obs=False, |
| 48 | + control_freq=20, |
| 49 | + renderer="mujoco", |
| 50 | + ) |
| 51 | + env.reset() |
| 52 | + |
| 53 | + camera_name = ["agentview", "birdview"] |
| 54 | + env.viewer.set_camera(camera_name=camera_name) |
| 55 | + for robot in env.robots: |
| 56 | + if isinstance(robot, MobileRobot): |
| 57 | + robot.enable_parts(legs=False, base=False) |
| 58 | + |
| 59 | + # do visualization |
| 60 | + for i in range(10000): |
| 61 | + start = time.time() |
| 62 | + action = np.random.randn(*env.action_spec[0].shape) |
| 63 | + obs, reward, done, _ = env.step(action) |
| 64 | + env.render() |
| 65 | + |
| 66 | + # limit frame rate if necessary |
| 67 | + elapsed = time.time() - start |
| 68 | + diff = 1 / MAX_FR - elapsed |
| 69 | + if diff > 0: |
| 70 | + time.sleep(diff) |
0 commit comments