Update position of the robot after the simulation Stop/Start

Hi,

I’ve extensively searched for a solution to this problem and couldn’t find an answer, although I believe it should be relatively straightforward to accomplish.

I am using the moveit.py file (located in /isaac_sim-2023.1.0/standalone_examples/api/omni.isaac.ros2_bridge) from the MoveIt ROS 2 tutorial. My goal is to set the initial position of the robot joints before the simulation starts. I’ve come up with the following code, which works as expected:

simulation_context.initialize_physics()

# BEGINNING OF CUSTOM CODE

articulation = Articulation("/Franka")

# Set the initial position of the robot arm
joint_angles = np.zeros(6)
joint_angles[1] = -0.523599  # 30º in joint 2
articulation.set_joint_positions(joint_angles)

# END OF CUSTOM CODE

simulation_context.play()

while simulation_app.is_running():

    # Run with a fixed step size
    simulation_context.step(render=True)

    # Tick the Publish/Subscribe JointState, Publish TF, and Publish Clock nodes each frame
    og.Controller.set(og.Controller.attribute("/ActionGraph/OnImpulseEvent.state:enableImpulse"), True)

simulation_context.stop()
simulation_app.close()

However, after the simulation stops and is played back again, the initial position is not set. I assume that these lines of code are not executed after the restart.

I found that there is a callback on_timeline_event() which executes when the simulation is stopped, paused, or played but only works within extensions. Is there a simple way to achieve that using SimulationContext()?