Error reported when the robotic arm follows the task

Hi everyone, I am using Isaac sim to simulate the following target of a robotic arm.

I want to use Script Editor to execute my code because it is more convenient for me to debug.
But I encountered some problems during use.

Because I don’t want to use the SimulationAPP, I execute my code in Script Ediotr. When I play in the UI, it keeps reporting errors.

Its error message is“Task name should be unique in the world”

I didn’t import the Class, but instead put the entire code into Script Editor for execution

I hope to receive some help, thank you very much.

My code:

from omni.isaac.manipulators import SingleManipulator
from omni.isaac.manipulators.grippers import ParallelGripper
from omni.isaac.core.utils.stage import add_reference_to_stage
import omni.isaac.core.tasks as tasks
from typing import Optional
import numpy as np
import asyncio




class FollowTarget(tasks.FollowTarget):
    def __init__(
        self,
        name: str = "denso_follow_target",
        target_prim_path: Optional[str] = None,
        target_name: Optional[str] = None,
        target_position: Optional[np.ndarray] = None,
        target_orientation: Optional[np.ndarray] = None,
        offset: Optional[np.ndarray] = None,
    ) -> None:
        tasks.FollowTarget.__init__(
            self,
            name=name,
            target_prim_path=target_prim_path,
            target_name=target_name,
            target_position=target_position,
            target_orientation=target_orientation,
            offset=offset,
        )
        return

    def set_robot(self) -> SingleManipulator:
        #TODO: change this to the robot usd file.
        asset_path = "C:/Users/Administrator/Desktop/testarm/xin/3/Cobotta_Pro_900_Assets/Cobotta_Pro_900_Assets/cobotta_pro_900.usd"
        add_reference_to_stage(usd_path=asset_path, prim_path="/World/cobotta")
        gripper = ParallelGripper(
            end_effector_prim_path="/World/cobotta/onrobot_rg6_base_link",
            joint_prim_names=["finger_joint", "right_outer_knuckle_joint"],
            joint_opened_positions=np.array([0, 0]),
            joint_closed_positions=np.array([0.628, -0.628]),
            action_deltas=np.array([-0.628, 0.628]))
        manipulator = SingleManipulator(prim_path="/World/cobotta",
                                        name="cobotta_robot",
                                        end_effector_prim_name="onrobot_rg6_base_link",
                                        gripper=gripper)
        joints_default_positions = np.zeros(12)
        joints_default_positions[7] = 0.628
        joints_default_positions[8] = 0.628
        manipulator.set_joints_default_state(positions=joints_default_positions)
        return manipulator

from omni.isaac.core import World

my_world = World(stage_units_in_meters=1.0)
my_task = FollowTarget(name="denso_follow_target", target_position=np.array([0.5, 0, 0.5]))
my_world.add_task(my_task)
my_world.reset()
task_params = my_world.get_task("denso_follow_target").get_params()
target_name = task_params["target_name"]["value"]
denso_name = task_params["robot_name"]["value"]
my_denso = my_world.scene.get_object(denso_name)
articulation_controller = my_denso.get_articulation_controller()
flag=True
while flag==True:
    my_world.step(render=True)
    if my_world.is_playing():
        if my_world.current_time_step_index == 0:
            my_world.reset()
        observations = my_world.get_observations()
        print(observations)

Hi @Julie_A - For script editor, you need to follow asynchronous programming workflow.

@rthaker Thank you very much for your reply. I am very, very looking forward to it.
I have made many attempts in the past few days, but they have never been successful. I can’t jump out of it

While simulation.app. is_running():

I tried to remove it and do it in the script editor, which was very frustrating.
Can you give me a case study? It can be avoided

While simulating app. is_running():

, can run follow_targed_example normally