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 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 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