Skip to content

Open and Close Door ​

SUMMARY

Open and Close slide the door between the positions given when connecting, easing in and out of the travel. Each call blocks until the door arrives, and travels from wherever the door stands now, so opening a door that already stands open returns without moving it.

The Skill ​

python
machine.open()
machine.close()

The Code ​

python
"""
Opens and closes the door of a CNC machine in a running Isaac Sim stage.

Supports Isaac Sim only. The door slides between the two positions given
here, easing in and out of the travel, and each move blocks until the door
arrives.

Usage:
    python open_and_close_door.py --prim_path <PRIM_PATH>
    python open_and_close_door.py --prim_path <PRIM_PATH>
        --open_position 0.0 0.0 0.0 --closed_position -0.8 0.0 0.0

Note:
    Open Isaac Sim before running this. A stage that does not hold the
    door prim gets the bundled demo CNC machine added to it at
    /World/cnc_machine, keeping whatever is already in the stage; a machine
    of your own needs its door as its own prim, named with --prim_path.

    Both positions are relative to the door prim's parent: select the door
    prim, slide it fully open and fully closed in the stage, and read the
    position off Property > Transform each time. Where that transform is
    shown as a matrix, the first three values of the bottom row are its x,
    y and z.

    The door is slid by writing its transform, so keep its path clear -- it
    passes through whatever stands in the way.
"""

import argparse

from loguru import logger

from telekinesis.medulla.machines import isaacsim


def main(prim_path: str,
         open_position: list[float],
         closed_position: list[float]) -> None:
    """Opens the door of a CNC machine, then closes it again."""

    # ===================== Create Machine =======================================
    machine = isaacsim.CNCMachine(name="my_simulated_cnc_machine")
    machine.set_usd("https://assets.telekinesis.ai/usd/machines/cnc_machine.zip")

    try:
        # ===================== Connect Machine ==================================
        machine.connect(simulation_prim_path=prim_path,
                        open_position=open_position,
                        closed_position=closed_position)

        # ==================== Run Skill ============================================
        logger.info("Opening the door.")
        machine.open()
        logger.info(f"Door open at {machine.door_position} m.")

        logger.success("Closing the door.")
        machine.close()
        logger.success(f"Door closed at {machine.door_position} m.")

        logger.info("Opening the door.")
        machine.open()
        logger.info(f"Door open at {machine.door_position} m.")
    except (ConnectionError, RuntimeError) as e:
        logger.error(f"Error occurred: {e}")
    finally:
        machine.disconnect()


if __name__ == "__main__":
    p = argparse.ArgumentParser(
        description="Open and close a CNC machine's door in Isaac Sim")
    p.add_argument("--prim_path", type=str, default="/World/cnc_machine/E_body_1/door",
                   help='Isaac Sim CNC machine door prim path, e.g. '
                        '"/World/cnc_machine/E_body_1/door"')
    p.add_argument("--open_position", type=float, nargs=3,
                   default=[-0.68654, -0.05313, 1.208], metavar=("X", "Y", "Z"),
                   help="Door position in meters, relative to the door "
                        "prim's parent, at which it stands open")
    p.add_argument("--closed_position", type=float, nargs=3,
                   default=[-0.2193, -0.05313, 1.208], metavar=("X", "Y", "Z"),
                   help="Door position in meters, relative to the door "
                        "prim's parent, at which it stands closed")
    args = p.parse_args()

    main(prim_path=args.prim_path,
         open_position=args.open_position,
         closed_position=args.closed_position)

Running the Example ​

bash
python open_and_close_door.py --prim_path /World/cnc_machine/E_body_1/door

For all options:

bash
python open_and_close_door.py --help

Parameter Configuration ​

open and close take no parameters. Both target positions are set once, when connecting — see Connection and Disconnection.

Returns ​

MethodTypeDescription
openNoneReturns nothing.
closeNoneReturns nothing.

Raises ​

MethodExceptionCondition
openRuntimeErrorThe machine is not connected, or the door rejects the command.
closeRuntimeErrorThe machine is not connected, or the door rejects the command.

Where to Use the Skill ​

Open and Close Door require an active connection — see Connection and Disconnection.