Error: Synchronous call to step
cannot be made from within Kit. Please use an async function with step_async
.
Receiving this error when i run my code with “rep.orchestrator.step()” but i still manage to save the data to the directory as required. But when i use “await omni.replicator.core.orchestrator.step_async()” the error goes away but the simulation dont play on each step and the replicator save the images at stand still simulation.
Any idea how to remove this error. Script is attache below:
async def _replicator_event_async(self):
color = [(1, 0, 0), (0, 1, 0), (0, 0, 1)]
def randomize_factory_lights():
lights = rep.create.light(
light_type="Sphere",
temperature=rep.distribution.normal(6500, 2000),
intensity=rep.distribution.normal(0, 150000),
position=rep.distribution.uniform((0.25, 0.25, 2.0),
(1, 1, 4.0)),
scale=rep.distribution.uniform(0.5, 0.8),
color=rep.distribution.choice(color),
count=3,
)
return lights.node
rep.randomizer.register(randomize_factory_lights)
camera_positions = [(-0.05, 0.02, 1.5),
(-0.06, 0.1, 1.5),
(-0.05, -0.07, 1.5),
(0.09, -0.15, 1.4)]
camera = rep.create.camera(focal_length=21, clipping_range=(0.01, 1000000), name="BinCam")
with rep.trigger.on_frame(num_frames=30):
rep.randomizer.randomize_factory_lights()
with camera:
rep.modify.pose(
position=rep.distribution.sequence(camera_positions),
look_at="/bin",
)
# Setup the writer
writer = rep.WriterRegistry.get("BasicWriter")
os.getcwd()
os.chdir('C:\\Users\\Student\\Lego')
self._output_dir = os.getcwd() + "/_output_abc"
print("Outputting synthetic data to: ", self._output_dir)
writer.initialize(output_dir=self._output_dir, rgb=True, instance_segmentation=True, colorize_instance_segmentation=True)
rp = rep.create.render_product("/Replicator/BinCam_Xform/BinCam", (512, 512))
await writer.attach_async([rp])
self._timeline.play()
rep.orchestrator.run()
rep.orchestrator.step()
# await omni.replicator.core.orchestrator.step_async()
rep.BackendDispatch.wait_until_done()
rep.orchestrator.stop()
self._timeline.pause()
return