Пример #1
0
    def build(cls, n_substeps: int = 10):
        """Construct a ShadowHandReachSimulation object.

        :param n_substeps: (int) sim.nsubsteps, num of substeps
        :return: a ShadowHandReachSimulation object with properly constructed sim.
        """
        xml = MujocoXML()
        xml.add_default_compiler_directive()

        xml.append(
            MujocoXML.parse(cls.FLOOR_XML).set_named_objects_attr(
                "floor", tag="body", pos=[1, 1, 0]))

        target = MujocoXML.parse(cls.TARGET_XML)

        colors = [
            [1.0, 0.0, 0.0, 1.0],
            [0.0, 1.0, 0.0, 1.0],
            [0.0, 0.0, 1.0, 1.0],
            [1.0, 1.0, 0.0, 1.0],
            [1.0, 0.0, 1.0, 1.0],
        ]

        for site, color in zip(FINGERTIP_SITE_NAMES, colors):
            target.set_named_objects_attr(
                f"target_{site}",
                pos=[0.5, 0.5, 0.0],
                type="sphere",
                rgba=color,
                size=0.005,
            )

        xml.append(target)

        xml.append(
            MujocoXML.parse(cls.HAND_XML).add_name_prefix(
                "robot0:").set_named_objects_attr(
                    "robot0:hand_mount",
                    tag="body",
                    pos=[1.0, 1.25, 0.15],
                    euler=[np.pi / 2, 0, np.pi],
                ).remove_objects_by_name("robot0:annotation:outer_bound")
            # Remove hand base free joint so that hand is immovable
            .remove_objects_by_name("robot0:hand_base"))

        xml.append(MujocoXML.parse(cls.LIGHT_XML))

        simulation = cls(xml.build(nsubsteps=n_substeps))

        # Move fingers out of the way.
        simulation.shadow_hand.set_position_control(
            simulation.shadow_hand.denormalize_position_control(
                simulation.shadow_hand.zero_control()))

        for _ in range(20):
            simulation.step()

        return simulation
Пример #2
0
    def build(
        cls,
        n_substeps: int = 10,
        simulation_params: CubeSimulationParameters = CubeSimulationParameters(),
    ):
        """
        Construct a CubeSimulationInterface object with perpendicular cube.
        """

        cube_xml_path, size_params = cls._get_model_xml_path_and_params(
            simulation_params.cube_appearance
        )

        xml = MujocoXML()
        xml.add_default_compiler_directive()

        cls._build_mujoco_cube_xml(xml, cube_xml_path)

        xml.append(
            MujocoXML.parse(cls.FLOOR_XML).set_named_objects_attr(
                "floor", tag="body", pos=[1, 1, 0]
            )
        )

        xml.append(
            MujocoXML.parse(cls.HAND_XML)
            .add_name_prefix("robot0:")
            .set_objects_attr(tag="size", **size_params)
            .set_named_objects_attr(
                "robot0:hand_mount",
                tag="body",
                pos=[1.0, 1.25, 0.15],
                euler=[np.pi / 2, 0, np.pi],
            )
            .remove_objects_by_name("robot0:annotation:outer_bound")
            # Remove hand base free joint so that hand is immovable
            .remove_objects_by_name("robot0:hand_base")
        )

        xml.append(MujocoXML.parse(cls.LIGHT_XML))

        simulation = cls(xml.build(nsubsteps=n_substeps))

        if simulation_params.hide_target:
            simulation.hide_target()

        return simulation
Пример #3
0
    def build(
        cls, n_substeps: int = 10, timestep: float = 0.008, name_prefix: str = "robot0:"
    ):
        """
        Construct MjSim object for this simulation

        :param name_prefix - to append to names of all objects in the MuJoCo model of the hand;
            by default no prefix is appended.
        """
        xml = MujocoXML()
        xml.add_default_compiler_directive()

        max_contacts_params = dict(njmax=2000, nconmax=200)

        xml.append(
            MujocoXML.parse(cls.FLOOR_XML).set_named_objects_attr(
                "floor", tag="body", pos=[1, 1, 0]
            )
        )

        xml.append(
            MujocoXML.parse(cls.HAND_XML)
            .add_name_prefix(name_prefix)
            .set_objects_attr(tag="size", **max_contacts_params)
            .set_objects_attr(tag="option", timestep=timestep)
            .set_named_objects_attr(
                f"{name_prefix}hand_mount",
                tag="body",
                pos=[1.0, 1.25, 0.15],
                euler=[np.pi / 2, 0, np.pi],
            )
            .remove_objects_by_name(f"{name_prefix}annotation:outer_bound")
            # Remove hand base free joint so that hand is immovable
            .remove_objects_by_name(f"{name_prefix}hand_base")
        )

        xml.append(MujocoXML.parse(cls.LIGHT_XML))

        return cls(sim=xml.build(nsubsteps=n_substeps), hand_prefix=name_prefix)