def get_unique_model_name(world: scenario.World, model_name: str) -> str: """ Get a unique model name given a world configuration. This function find the first available model name starting from the argument and appending a integer postfix until the resulting name is unique in the world. Tentatives example: `cartpole`, `cartpole1`, `cartpole2`, ... Args: world: An initialized world. model_name: The first model name attempt. Raises: ValueError: If the world is not valid. Returns: The unique model name calculated from the original name. """ if world.id() == 0: raise ValueError("The world is not valid") postfix = 0 model_name_tentative = f"{model_name}" while model_name_tentative in world.model_names(): postfix += 1 model_name_tentative = f"{model_name}{postfix}" return model_name_tentative
def insert_cube_in_operating_area( world: scenario_gazebo.World) -> scenario_gazebo.Model: # Insert objects from Fuel uri = lambda org, name: f"https://fuel.ignitionrobotics.org/{org}/models/{name}" # Download the cube SDF file cube_sdf = scenario_gazebo.get_model_file_from_fuel(uri=uri( org="openrobotics", name="wood cube 5cm"), use_cache=False) # Sample a random position random_position = np.random.uniform(low=[0.2, -0.3, 1.01], high=[0.4, 0.3, 1.01]) # Get a unique name model_name = gym_ignition.utils.scenario.get_unique_model_name( world=world, model_name="cube") # Insert the model assert world.insert_model( cube_sdf, scenario_core.Pose(random_position, [1., 0, 0, 0]), model_name) # Return the model return world.get_model(model_name=model_name)
def get_cube(gazebo: scenario.GazeboSimulator, world: scenario.World) -> core.Model: quaternion = to_wxyz(Rotation.from_euler("x", 45, degrees=True).as_quat()) initial_pose = core.Pose([0, 0, 0.5], quaternion.tolist()) cube_urdf = utils.get_cube_urdf() assert world.insert_model(cube_urdf, initial_pose) assert "cube_robot" in world.model_names() cube = world.get_model("cube_robot") assert cube.to_gazebo().reset_base_world_linear_velocity([0.1, -0.2, -0.3]) assert cube.to_gazebo().reset_base_world_angular_velocity([-0.1, 2.0, 0.3]) assert gazebo.run(paused=True) return cube
def insert_table(world: scenario_gazebo.World) -> scenario_gazebo.Model: # Insert objects from Fuel uri = lambda org, name: f"https://fuel.ignitionrobotics.org/{org}/models/{name}" # Download the cube SDF file bucket_sdf = scenario_gazebo.get_model_file_from_fuel( uri=uri(org="OpenRobotics", name="Table"), use_cache=False ) # Assign a custom name to the model model_name = "table" # Insert the model assert world.insert_model(bucket_sdf, scenario_core.Pose_identity(), model_name) # Return the model return world.get_model(model_name=model_name)
def get_random_panda(gazebo: scenario.GazeboSimulator, world: scenario.World) -> core.Model: panda_urdf = gym_ignition_models.get_model_file("panda") assert world.insert_model(panda_urdf) assert "panda" in world.model_names() panda = world.get_model("panda") joint_space = get_joint_positions_space(model=panda) joint_space.seed(10) q = joint_space.sample() dq = joint_space.np_random.uniform(low=-1.0, high=1.0, size=q.shape) assert panda.to_gazebo().reset_joint_positions(q.tolist()) assert panda.to_gazebo().reset_joint_velocities(dq.tolist()) assert gazebo.run(paused=True) return panda
def insert_bucket(world: scenario_gazebo.World) -> scenario_gazebo.Model: # Insert objects from Fuel uri = lambda org, name: f"https://fuel.ignitionrobotics.org/{org}/models/{name}" # Download the cube SDF file bucket_sdf = scenario_gazebo.get_model_file_from_fuel(uri=uri( org="GoogleResearch", name="Threshold_Basket_Natural_Finish_Fabric_Liner_Small"), use_cache=False) # Assign a custom name to the model model_name = "bucket" # Insert the model assert world.insert_model( bucket_sdf, scenario_core.Pose([0.68, 0, 1.02], [1., 0, 0, 1]), model_name) # Return the model return world.get_model(model_name=model_name)