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
        descriptions, 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 based on the retrieved positions
        top_anchor_pos = positions['top_anchor']
        top_joint_pos = positions['top_joint']
        top_side_pos = positions['top_side']
        bin_pos = positions['bin']

        # Step 1: Move to the top anchor position
        print("[Task] Moving to top anchor position:", top_anchor_pos)
        obs, reward, done = move(env, task, obs.robot_position, top_anchor_pos)
        if done:
            print("[Task] Task ended after moving to top anchor position!")
            return

        # Step 2: Rotate the gripper to the desired orientation
        print("[Task] Rotating gripper to desired orientation.")
        target_quat = [0, 0, 0, 1]  # Example quaternion for rotation
        obs, reward, done = rotate(env, task, target_quat)
        if done:
            print("[Task] Task ended after rotating gripper!")
            return

        # Step 3: Move to the top joint position
        print("[Task] Moving to top joint position:", top_joint_pos)
        obs, reward, done = move(env, task, obs.robot_position, top_joint_pos)
        if done:
            print("[Task] Task ended after moving to top joint position!")
            return

        # Step 4: Pick the object at the top joint position
        print("[Task] Picking object at top joint position.")
        obs, reward, done = pick(env, task, 'object_name', top_joint_pos)
        if done:
            print("[Task] Task ended after picking object!")
            return

        # Step 5: Move to the bin position
        print("[Task] Moving to bin position:", bin_pos)
        obs, reward, done = move(env, task, obs.robot_position, bin_pos)
        if done:
            print("[Task] Task ended after moving to bin position!")
            return

        # Step 6: Place the object in the bin
        print("[Task] Placing object in the bin.")
        obs, reward, done = place(env, task, 'object_name', bin_pos)
        if done:
            print("[Task] Task ended after placing object!")
            return

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

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


if __name__ == "__main__":
    run_skeleton_task()