=== Instruction 1 ===
Is Correct: False
Syntax Pass: False
Code Function: The code defines a function to run a simulation task involving object manipulation. It begins by setting up the environment and resetting the task to its initial state. It optionally initializes video recording for the simulation. The function retrieves the positions of specific objects, namely two tomatoes and a plate. 

The task consists of a series of steps: first, it opens a drawer, then picks up the first tomato and places it on the plate, followed by picking up the second tomato and placing it on the plate as well. After each action, it checks if the task is completed and prints appropriate messages. Finally, it ensures that the environment is properly shut down after the task execution. The function is executed when the script is run as the main program.
Similarity: {'ok': False, 'reason': 'LLM JSON parsing failed.'}
Differences: 1. **Purpose**: 
   - **TASK**: Describes a specific sequence of actions to be performed (open a drawer, put tomatoes on a plate).
   - **CODE_FUNC**: Describes a function that implements a simulation of the task, including setup, execution, and shutdown.

2. **Structure**: 
   - **TASK**: Presented in a PDDL format, defining a domain and problem with types, predicates, and actions.
   - **CODE_FUNC**: Described in a narrative format, outlining the steps of a function without formal structure.

3. **Detail Level**: 
   - **TASK**: Provides detailed definitions of actions, preconditions, and effects in a formalized manner.
   - **CODE_FUNC**: Provides a high-level overview of the task execution without detailing the underlying logic or conditions.

4. **Execution Context**: 
   - **TASK**: Represents a theoretical model for planning and reasoning about actions in a domain.
   - **CODE_FUNC**: Represents an executable function that runs a simulation in a programming environment.

5. **Components**: 
   - **TASK**: Includes types, predicates, and actions specific to a robotic manipulation domain.
   - **CODE_FUNC**: Focuses on the procedural steps of the task, including object retrieval and action execution.

6. **Output**: 
   - **TASK**: Does not specify output; focuses on the logical structure of actions.
   - **CODE_FUNC**: Mentions printing messages to indicate task completion and status.

7. **Initialization**: 
   - **TASK**: Initialization is implicit in the PDDL problem definition.
   - **CODE_FUNC**: Explicitly mentions resetting the task and optionally initializing video recording.

8. **Environment Management**: 
   - **TASK**: Does not address environment management or shutdown procedures.
   - **CODE_FUNC**: Includes steps to ensure proper shutdown of the environment after task execution.

9. **Action Sequence**: 
   - **TASK**: Specifies actions in a logical order as part of a planning problem.
   - **CODE_FUNC**: Describes the action sequence in a procedural manner, focusing on execution rather than planning.

10. **Language**: 
    - **TASK**: Uses PDDL, a formal language for describing planning problems.
    - **CODE_FUNC**: Uses natural language to describe the function and its operations.

In summary, the semantic differences between TASK and CODE_FUNC are significant, as they serve different purposes and are structured differently.

Refined Code Generated:
-------------------
import numpy as np
from pyrep.objects.shape import Shape
from pyrep.objects.proximity_sensor import ProximitySensor

from env import setup_environment, shutdown_environment
from skill_code import pick, place, pull
from video import init_video_writers, recording_step, recording_get_observation
from object_positions import get_object_positions

def run_skeleton_task():
    '''Generic skeleton for running any task in your simulation.'''
    print("===== Starting Skeleton Task =====")
    
    # === Environment Setup ===
    env, task = setup_environment()
    try:
        # Reset the task to its initial state
        _, obs = task.reset()

        # (Optional) Initialize video writers for capturing your simulation
        init_video_writers(obs)

        # Wrap the task steps for recording (if needed)
        original_step = task.step
        task.step = recording_step(original_step)
        original_get_obs = task.get_observation
        task.get_observation = recording_get_observation(original_get_obs)

        # === Retrieve Object Positions ===
        positions = get_object_positions()

        # Define the positions of the objects
        tomato1_pos = positions['item1']
        tomato2_pos = positions['item2']
        plate_pos = positions['plate']

        # === Execute the Plan ===
        # Step 1: Open the bottom drawer
        print("[Task] Opening the bottom drawer.")
        obs, reward, done = pull(env, task, pull_distance=0.1, pull_axis='x')
        if done:
            print("[Task] Task ended after opening the drawer!")
            return

        # Step 2: Pick the first tomato
        print("[Task] Picking tomato1.")
        obs, reward, done = pick(env, task, target_pos=tomato1_pos, approach_distance=0.15)
        if done:
            print("[Task] Task ended after picking tomato1!")
            return

        # Step 3: Place the first tomato on the plate
        print("[Task] Placing tomato1 on the plate.")
        obs, reward, done = place(env, task, target_pos=plate_pos, approach_distance=0.15)
        if done:
            print("[Task] Task ended after placing tomato1!")
            return

        # Step 4: Pick the second tomato
        print("[Task] Picking tomato2.")
        obs, reward, done = pick(env, task, target_pos=tomato2_pos, approach_distance=0.15)
        if done:
            print("[Task] Task ended after picking tomato2!")
            return

        # Step 5: Place the second tomato on the plate
        print("[Task] Placing tomato2 on the plate.")
        obs, reward, done = place(env, task, target_pos=plate_pos, approach_distance=0.15)
        if done:
            print("[Task] Task completed successfully! Reward:", reward)
        else:
            print("[Task] Task not completed yet (done=False).")

    finally:
        # Always ensure the environment is properly shutdown
        shutdown_environment(env)

    print("===== End of Skeleton Task =====")
-------------------

=== Instruction 2 ===
Is Correct: False
Syntax Pass: False
Code Function: The code defines a function to run a simulation task involving object manipulation. It begins by setting up the environment and resetting the task to its initial state. It optionally initializes video recording for the simulation. The function retrieves the positions of various objects, including a plate and two tomatoes. 

The task consists of three main steps: first, it attempts to pull open a bottom drawer; second, it places the first tomato onto the plate; and third, it places the second tomato onto the plate. After each action, it checks if the action was successful and prints the corresponding message. Finally, the environment is shut down to ensure proper cleanup after the task is completed.
Similarity: {'ok': False, 'reason': 'LLM JSON parsing failed.'}
Differences: 1. **Purpose**: 
   - **TASK**: Describes a specific instruction for a robot to perform a sequence of actions involving object manipulation.
   - **CODE_FUNC**: Describes a function that implements a simulation of the task, including setup, execution, and cleanup.

2. **Level of Abstraction**:
   - **TASK**: High-level instruction focused on what needs to be done.
   - **CODE_FUNC**: Low-level implementation detailing how the task is executed programmatically.

3. **Components**:
   - **TASK**: Contains a single instruction and a PDDL domain definition.
   - **CODE_FUNC**: Contains multiple steps, including environment setup, action execution, success checks, and cleanup.

4. **Execution Context**:
   - **TASK**: Does not specify how the actions are executed or the context in which they occur.
   - **CODE_FUNC**: Specifies a simulation context, including initialization and shutdown procedures.

5. **Feedback Mechanism**:
   - **TASK**: Does not include any feedback or success checks for actions.
   - **CODE_FUNC**: Includes checks after each action to determine if it was successful and prints messages accordingly.

6. **Action Sequence**:
   - **TASK**: Specifies a sequence of actions (pulling a drawer and dropping tomatoes).
   - **CODE_FUNC**: Details a specific order of actions (pulling a drawer, placing tomatoes) and includes the context of each action.

7. **Initialization**:
   - **TASK**: Assumes an initial state without detailing how it is set up.
   - **CODE_FUNC**: Explicitly initializes the environment and resets the task state.

8. **Recording**:
   - **TASK**: Does not mention any form of recording or monitoring.
   - **CODE_FUNC**: Optionally initializes video recording for the simulation.

9. **Cleanup**:
   - **TASK**: Does not address cleanup after task completion.
   - **CODE_FUNC**: Includes a shutdown procedure to ensure proper cleanup after the task.

10. **Object Retrieval**:
    - **TASK**: Does not specify how objects are retrieved or their positions.
    - **CODE_FUNC**: Retrieves positions of objects as part of the simulation setup.

11. **Success Messaging**:
    - **TASK**: Lacks any messaging or logging of actions.
    - **CODE_FUNC**: Prints messages after each action to indicate success or failure.

12. **Action Details**:
    - **TASK**: Provides a general description of actions without implementation details.
    - **CODE_FUNC**: Implements specific actions with checks and responses.

13. **Error Handling**:
    - **TASK**: Does not include any error handling or contingencies.
    - **CODE_FUNC**: Implies success checks which can be used for error handling.

14. **Object Types**:
    - **TASK**: Mentions tomatoes and a plate but does not define their types or roles.
    - **CODE_FUNC**: Defines the roles and types of objects involved in the simulation.

15. **Simulation vs. Real-world Execution**:
    - **TASK**: Focuses on a theoretical task execution.
    - **CODE_FUNC**: Focuses on simulating the task execution in a controlled environment.

16. **PDDL Usage**:
    - **TASK**: Utilizes PDDL for defining actions and states.
    - **CODE_FUNC**: Does not reference PDDL but instead describes procedural code.

17. **Action Specificity**:
    - **TASK**: Generalizes actions (e.g., "pull open any drawer").
    - **CODE_FUNC**: Specifies actions in detail (e.g., "attempts to pull open a bottom drawer").

18. **State Management**:
    - **TASK**: Does not manage or describe state transitions.
    - **CODE_FUNC**: Manages state transitions and checks throughout the simulation.

19. **Object Interaction**:
    - **TASK**: Describes interaction with objects in a general sense.
    - **CODE_FUNC**: Details specific interactions with objects, including the order and method of manipulation.

20. **Finality**:
    - **TASK**: Does not indicate a final state or completion.
    - **CODE_FUNC**: Indicates completion of the task and proper shutdown of the environment.

In summary, the semantic differences between TASK and CODE_FUNC are significant, as TASK provides a high-level instruction while CODE_FUNC details the implementation of that instruction in a simulation context.

Refined Code Generated:
-------------------
import numpy as np
from pyrep.objects.shape import Shape
from pyrep.objects.proximity_sensor import ProximitySensor

from env import setup_environment, shutdown_environment
from skill_code import *
from video import init_video_writers, recording_step, recording_get_observation
from object_positions import get_object_positions

def run_skeleton_task():
    '''Generic skeleton for running any task in your simulation.'''
    print("===== Starting Skeleton Task =====")
    
    # === Environment Setup ===
    env, task = setup_environment()
    try:
        # Reset the task to its initial state
        _, obs = task.reset()

        # (Optional) Initialize video writers for capturing your simulation
        init_video_writers(obs)

        # Wrap the task steps for recording (if needed)
        original_step = task.step
        task.step = recording_step(original_step)
        original_get_obs = task.get_observation
        task.get_observation = recording_get_observation(original_get_obs)

        # === Retrieve Object Positions ===
        positions = get_object_positions()

        # Define object positions
        plate_pos = positions['plate']
        bottom_drawer_pos = positions['bottom_anchor_pos']  # Assuming this is the position of the bottom drawer

        # === Execute the Plan ===
        # Step 1: Pull open any drawer that is not locked
        print("[Task] Pulling open the bottom drawer.")
        obs, _, done = pull(env, task, pull_distance=0.1, pull_axis='y', max_steps=100, threshold=0.01, timeout=10.0)
        if done:
            print("[Task] Drawer opened successfully!")
        else:
            print("[Task] Failed to open the drawer.")

        # Step 2: Place the first tomato onto the plate
        print("[Task] Placing tomato1 on the plate.")
        obs, _, done = place(env, task, target_pos=plate_pos, approach_distance=0.15, max_steps=100, threshold=0.01, approach_axis='z', timeout=10.0)
        if done:
            print("[Task] tomato1 placed successfully!")
        else:
            print("[Task] Failed to place tomato1.")

        # Step 3: Place the second tomato onto the plate
        print("[Task] Placing tomato2 on the plate.")
        obs, _, done = place(env, task, target_pos=plate_pos, approach_distance=0.15, max_steps=100, threshold=0.01, approach_axis='z', timeout=10.0)
        if done:
            print("[Task] tomato2 placed successfully!")
        else:
            print("[Task] Failed to place tomato2.")

    finally:
        # Always ensure the environment is properly shutdown
        shutdown_environment(env)

    print("===== End of Skeleton Task =====")

if __name__ == "__main__":
    run_skeleton_task()
-------------------

=== Instruction 3 ===
Is Correct: False
Syntax Pass: False
Code Function: The code defines a function to run a simulation task involving object manipulation. It begins by setting up the environment and resetting the task to its initial state. Video recording is initialized to capture the simulation process. The function retrieves the positions of various objects in the environment.

The task consists of several key steps: first, it opens a drawer; second, it picks up a tomato labeled "tomato1" and places it on a plate; third, it picks up another tomato labeled "tomato2" and places it on the same plate. After each action, the code checks if the action was successful and prints the corresponding message.

Finally, the environment is shut down to ensure proper cleanup after the task is completed. The function is executed when the script is run as the main program.
Similarity: {'ok': False, 'reason': 'LLM JSON parsing failed.'}
Differences: 1. **Nature of Content**: 
   - TASK is a detailed instruction set for a specific action sequence involving object manipulation.
   - CODE_FUNC describes a function that implements a simulation of the task, including setup, execution, and cleanup.

2. **Level of Abstraction**:
   - TASK provides a high-level description of what needs to be done without implementation details.
   - CODE_FUNC includes specific programming constructs and logic to perform the task.

3. **Execution Context**:
   - TASK is a conceptual directive that can be interpreted and executed by a robot or an agent.
   - CODE_FUNC is a concrete implementation that runs in a programming environment.

4. **Components**:
   - TASK focuses on actions (selecting, opening, picking, and placing) without specifying how these actions are executed.
   - CODE_FUNC includes additional components such as environment setup, video recording, and success checks after each action.

5. **Output Handling**:
   - TASK does not mention any output or feedback mechanism.
   - CODE_FUNC includes print statements to provide feedback on the success of actions.

6. **Initialization and Cleanup**:
   - TASK does not address initialization or cleanup processes.
   - CODE_FUNC explicitly mentions resetting the environment and shutting it down after task completion.

7. **Object Specificity**:
   - TASK refers to "all the tomatoes" generically.
   - CODE_FUNC specifies actions for "tomato1" and "tomato2" individually.

8. **Error Handling**:
   - TASK does not include any error handling or success verification.
   - CODE_FUNC checks if each action was successful and prints messages accordingly.

9. **Execution Trigger**:
   - TASK is a standalone instruction that can be executed at any time.
   - CODE_FUNC is executed within a specific programming context (when the script is run as the main program).

10. **Focus on Simulation**:
    - TASK is focused on the physical actions to be performed.
    - CODE_FUNC emphasizes the simulation aspect, including video recording and environment management.

In summary, the semantic differences between TASK and CODE_FUNC are significant, as TASK is an abstract instruction set while CODE_FUNC is a concrete implementation of that task in a programming context.

Refined Code Generated:
-------------------
import numpy as np
from pyrep.objects.shape import Shape
from pyrep.objects.proximity_sensor import ProximitySensor

from env import setup_environment, shutdown_environment

from skill_code import *  
from video import init_video_writers, recording_step, recording_get_observation
from object_positions import get_object_positions

def run_skeleton_task():
    '''Generic skeleton for running any task in your simulation.'''
    print("===== Starting Skeleton Task =====")
    
    env, task = setup_environment()
    try:
        descriptions, obs = task.reset()

        init_video_writers(obs)

        original_step = task.step
        task.step = recording_step(original_step)
        original_get_obs = task.get_observation
        task.get_observation = recording_get_observation(original_get_obs)

        positions = get_object_positions()

        plate_pos = positions['plate']
        bottom_anchor_pos = positions['bottom_anchor_pos']
        middle_anchor_pos = positions['middle_anchor_pos']
        top_anchor_pos = positions['top_anchor_pos']

        print("[Task] Opening the drawer...")
        obs, reward, done = pull(env, task, pull_distance=0.1, pull_axis='y', max_steps=100, threshold=0.01, timeout=10.0)
        if done:
            print("[Task] Drawer opened successfully!")
        else:
            print("[Task] Failed to open the drawer.")

        print("[Task] Picking up tomato1...")
        obs, reward, done = pick(env, task, target_pos=positions['item1'], approach_distance=0.15, max_steps=100, threshold=0.01, approach_axis='z', timeout=10.0)
        if done:
            print("[Task] Tomato1 picked successfully!")
        else:
            print("[Task] Failed to pick tomato1.")

        print("[Task] Placing tomato1 on the plate...")
        obs, reward, done = place(env, task, target_pos=plate_pos, approach_distance=0.15, max_steps=100, threshold=0.01, approach_axis='z', timeout=10.0)
        if done:
            print("[Task] Tomato1 placed successfully!")
        else:
            print("[Task] Failed to place tomato1.")

        print("[Task] Picking up tomato2...")
        obs, reward, done = pick(env, task, target_pos=positions['item2'], approach_distance=0.15, max_steps=100, threshold=0.01, approach_axis='z', timeout=10.0)
        if done:
            print("[Task] Tomato2 picked successfully!")
        else:
            print("[Task] Failed to pick tomato2.")

        print("[Task] Placing tomato2 on the plate...")
        obs, reward, done = place(env, task, target_pos=plate_pos, approach_distance=0.15, max_steps=100, threshold=0.01, approach_axis='z', timeout=10.0)
        if done:
            print("[Task] Tomato2 placed successfully!")
        else:
            print("[Task] Failed to place tomato2.")

    finally:
        shutdown_environment(env)

    print("===== End of Skeleton Task =====")

if __name__ == "__main__":
    run_skeleton_task()
-------------------

=== Instruction 4 ===
Is Correct: False
Syntax Pass: False
Code Function: The code defines a function to run a simulation task involving object manipulation in a virtual environment. It begins by setting up the environment and resetting the task to its initial state. Video recording is optionally initialized to capture the simulation. The function retrieves the positions of specific objects, including two tomatoes and a plate.

The task consists of a series of steps: first, it pulls a drawer to unlock a cabinet, then picks the first tomato and places it on the plate, followed by picking the second tomato and placing it on the plate as well. After each action, the function checks if the task is completed and prints appropriate messages. Finally, it ensures that the environment is properly shut down after the task execution. The overall behavior is to simulate a sequence of actions involving picking and placing objects in a controlled environment.
Similarity: {'ok': False, 'reason': 'LLM JSON parsing failed.'}
Differences: 1. **Purpose**: 
   - TASK describes a specific sequence of actions to be performed in a real-world scenario, while CODE_FUNC outlines a function that simulates these actions in a virtual environment.

2. **Environment Setup**: 
   - TASK does not specify how the environment is set up, whereas CODE_FUNC explicitly mentions setting up the environment and resetting the task to its initial state.

3. **Video Recording**: 
   - TASK does not mention video recording, while CODE_FUNC includes an optional step to initialize video recording to capture the simulation.

4. **Object Retrieval**: 
   - TASK does not detail how the positions of objects are retrieved, while CODE_FUNC specifies that it retrieves the positions of the tomatoes and the plate.

5. **Action Sequence**: 
   - TASK outlines the actions in a more abstract manner (unlocking, transferring tomatoes), while CODE_FUNC provides a detailed sequence of actions (pulling a drawer, picking, and placing tomatoes).

6. **Completion Check**: 
   - TASK does not include any mechanism for checking if the task is completed, whereas CODE_FUNC includes checks after each action to determine task completion.

7. **Output Messages**: 
   - TASK does not specify any output or feedback mechanism, while CODE_FUNC mentions printing appropriate messages after actions.

8. **Environment Shutdown**: 
   - TASK does not address what happens after the actions are completed, while CODE_FUNC ensures that the environment is properly shut down after task execution.

9. **Level of Detail**: 
   - TASK provides a high-level description of the task, while CODE_FUNC goes into detail about the implementation and execution of the task in a simulation.

10. **Context**: 
    - TASK is focused on a physical task in a real-world context, while CODE_FUNC is focused on a virtual simulation context.

Refined Code Generated:
-------------------
import numpy as np
from pyrep.objects.shape import Shape
from pyrep.objects.proximity_sensor import ProximitySensor

from env import setup_environment, shutdown_environment

from skill_code import *  
from video import init_video_writers, recording_step, recording_get_observation
from object_positions import get_object_positions

def run_skeleton_task():
    '''Generic skeleton for running any task in your simulation.'''
    print("===== Starting Skeleton Task =====")
    
    env, task = setup_environment()
    try:
        descriptions, obs = task.reset()

        init_video_writers(obs)

        original_step = task.step
        task.step = recording_step(original_step)
        original_get_obs = task.get_observation
        task.get_observation = recording_get_observation(original_get_obs)

        positions = get_object_positions()

        tomato1_pos = positions['item1']
        tomato2_pos = positions['item2']
        plate_pos = positions['plate']
        bottom_drawer_pos = positions['bottom_anchor_pos']

        print("[Task] Pulling the drawer to unlock the cabinet.")
        obs, reward, done = pull(env, task, pull_distance=0.1, pull_axis='y')
        if done:
            print("[Task] Task ended after pulling the drawer!")
            return

        print("[Task] Picking the first tomato.")
        obs, reward, done = pick(env, task, target_pos=tomato1_pos, approach_distance=0.15)
        if done:
            print("[Task] Task ended after picking the first tomato!")
            return

        print("[Task] Placing the first tomato on the plate.")
        obs, reward, done = place(env, task, target_pos=plate_pos, approach_distance=0.15)
        if done:
            print("[Task] Task ended after placing the first tomato!")
            return

        print("[Task] Picking the second tomato.")
        obs, reward, done = pick(env, task, target_pos=tomato2_pos, approach_distance=0.15)
        if done:
            print("[Task] Task ended after picking the second tomato!")
            return

        print("[Task] Placing the second tomato on the plate.")
        obs, reward, done = place(env, task, target_pos=plate_pos, approach_distance=0.15)
        if done:
            print("[Task] Task completed successfully! Reward:", reward)
        else:
            print("[Task] Task not completed yet (done=False).")

    finally:
        shutdown_environment(env)

    print("===== End of Skeleton Task =====")

if __name__ == "__main__":
    run_skeleton_task()
-------------------

=== Instruction 5 ===
Is Correct: False
Syntax Pass: False
Code Function: The code defines a function to run a simulation task involving object manipulation. It begins by setting up the environment and resetting the task to its initial state. It initializes video recording capabilities to capture the simulation. The function retrieves the positions of various objects, including a table, a plate, and two tomatoes.

The task consists of a series of steps: first, it pulls open a bottom drawer; next, it picks the first tomato from the table and places it onto the plate; then, it picks the second tomato from the table and places it onto the plate as well. After each action, the function checks if the task is completed and prints appropriate messages. Finally, it ensures that the environment is properly shut down after the task execution. The overall behavior is to simulate a sequence of actions involving picking and placing objects in a controlled environment.
Similarity: {'ok': False, 'reason': 'LLM JSON parsing failed.'}
Differences: 1. **Purpose**: 
   - **TASK**: Describes a specific sequence of actions to be performed in a physical environment.
   - **CODE_FUNC**: Describes a function that implements a simulation of the task, including setup, execution, and cleanup.

2. **Level of Abstraction**: 
   - **TASK**: High-level instructions focused on what actions to take.
   - **CODE_FUNC**: Low-level implementation details, including programming constructs and function calls.

3. **Environment Interaction**: 
   - **TASK**: Directly involves physical actions (e.g., sliding open a drawer, tossing tomatoes).
   - **CODE_FUNC**: Involves simulating these actions in a controlled environment, including setup and teardown processes.

4. **Action Sequence**: 
   - **TASK**: Specifies a linear sequence of actions (open drawer, toss tomatoes).
   - **CODE_FUNC**: Describes a more complex sequence that includes checking conditions and managing state (e.g., checking if the task is completed).

5. **State Management**: 
   - **TASK**: Does not explicitly mention state management or conditions.
   - **CODE_FUNC**: Includes state management (e.g., checking if the task is completed, resetting the environment).

6. **Output**: 
   - **TASK**: Does not specify any output or feedback mechanism.
   - **CODE_FUNC**: Includes print statements to provide feedback on the task execution.

7. **Initialization**: 
   - **TASK**: Assumes an initial state without detailing how it is set up.
   - **CODE_FUNC**: Explicitly initializes the environment and objects before executing the task.

8. **Recording**: 
   - **TASK**: Does not mention any recording or monitoring of the task.
   - **CODE_FUNC**: Includes video recording capabilities to capture the simulation.

9. **Completion Check**: 
   - **TASK**: Does not include any mechanism to check if the task is completed.
   - **CODE_FUNC**: Implements checks to determine if the task has been successfully completed.

10. **Cleanup**: 
    - **TASK**: Does not address any cleanup or finalization steps after task execution.
    - **CODE_FUNC**: Ensures proper shutdown of the environment after the task is executed.

Refined Code Generated:
-------------------
import numpy as np
from pyrep.objects.shape import Shape
from pyrep.objects.proximity_sensor import ProximitySensor

from env import setup_environment, shutdown_environment

from skill_code import *
from video import init_video_writers, recording_step, recording_get_observation
from object_positions import get_object_positions

def run_skeleton_task():
    '''Generic skeleton for running any task in your simulation.'''
    print("===== Starting Skeleton Task =====")
    
    # === Environment Setup ===
    env, task = setup_environment()
    try:
        # Reset the task to its initial state
        _, obs = task.reset()

        # (Optional) Initialize video writers for capturing your simulation
        init_video_writers(obs)

        # Wrap the task steps for recording (if needed)
        original_step = task.step
        task.step = recording_step(original_step)
        original_get_obs = task.get_observation
        task.get_observation = recording_get_observation(original_get_obs)

        # === Retrieve Object Positions ===
        positions = get_object_positions()

        # Define object positions
        plate_pos = positions['plate']
        tomato1_pos = positions['item1']
        tomato2_pos = positions['item2']
        
        # Step 1: Pull open the bottom drawer
        print("[Task] Pulling open the bottom drawer.")
        obs, reward, done = pull(env, task, pull_distance=0.1, pull_axis='y')
        if done:
            print("[Task] Task ended after pulling the drawer!")
            return

        # Step 2: Pick the first tomato from the table
        print("[Task] Picking tomato1 from the table.")
        obs, reward, done = pick(env, task, target_pos=tomato1_pos, approach_distance=0.15)
        if done:
            print("[Task] Task ended after picking tomato1!")
            return

        # Step 3: Place the first tomato onto the plate
        print("[Task] Placing tomato1 onto the plate.")
        obs, reward, done = place(env, task, target_pos=plate_pos, approach_distance=0.15)
        if done:
            print("[Task] Task ended after placing tomato1!")
            return

        # Step 4: Pick the second tomato from the table
        print("[Task] Picking tomato2 from the table.")
        obs, reward, done = pick(env, task, target_pos=tomato2_pos, approach_distance=0.15)
        if done:
            print("[Task] Task ended after picking tomato2!")
            return

        # Step 5: Place the second tomato onto the plate
        print("[Task] Placing tomato2 onto the plate.")
        obs, reward, done = place(env, task, target_pos=plate_pos, approach_distance=0.15)
        if done:
            print("[Task] Task completed successfully! Reward:", reward)
        else:
            print("[Task] Task not completed yet (done=False).")

    finally:
        # Always ensure the environment is properly shutdown
        shutdown_environment(env)

    print("===== End of Skeleton Task =====")

if __name__ == "__main__":
    run_skeleton_task()
-------------------

