MQTT for Isaac Sim: PhysX error

Hi,

I’m trying to implement MQTT in my project but I’m running into a PhysX error (see image below, this also happens for getWakeCounter()).

MicrosoftTeams-image

So the general idea is that I want to change the speed of the angular drive of a cylinder. I am working via the docker container deployment, so I installed the Mosquitto broker outside of the docker container (in the Azure server) like so: Installing the Mosquitto MQTT Server to the Raspberry Pi - Pi My Life Up. From the same location I communicate to the receiver like so: mosquitto_pub -h <public_azure_ip_address> -t "/velocity" -m "200".
The receiver is an extension I created in Isaac Sim. Hereby a piece of code that generally shows what I’ve done:

import omni.ext
import omni.usd as usd
import threading
import paho.mqtt.client as mqtt


class MyExtension(omni.ext.IExt):
    def __init__(self):
        self.host_ip = "<public_azure_ip_address>"
        self.port = 1883
        self.topic_subscribe = "/velocity"
        self.client = mqtt.Client()
        self.client.on_connect = self.on_connect
        self.client.on_message = self.on_message
        self.client.connect(self.host_ip, self.port, 60)
        self.client.loop_start()


    def on_startup(self, ext_id):
        print("[omni.conveyor.modules] MyExtension startup")


    def on_shutdown(self):
        print("[omni.conveyor.modules] MyExtension shutdown")
        self.client.loop_stop()


    def on_connect(self, client, userdata, flags, rc):
        print("Connected with result code " + str(rc)).
        self.client.subscribe(self.topic_subscribe)


    def on_message(self, client, userdata, msg): 
        print("Set speed:" + str(msg.payload))
        speed = int(msg.payload)
        stage = usd.get_context().get_stage()
        joint = stage.GetPrimAtPath('Cylinder/joint')
        joint.GetAttribute('drive:angular:physics:targetVelocity').Set(speed)

I also tried placing self.client.loop_start() in the on_startup function but that didn’t work either.
Note that the same way of changing speed works when I would simply make a button for it, so my hypothesis is that it has something to do with that the MQTT thread interrupts something in the main Isaac thread (or the other thread? I noticed that Isaac already uses 2 threads by default) that the program doesn’t like as it interrupts something that happens internally.

The confusing thing is that sometimes it does work for a little while, but then it breaks, but I cannot find a pattern in why it suddenly breaks.

Does someone know how to fix/tackle this problem?

Hi

An approach for a solution may be to program inside a method subscribed to physics events. This post, which describes a similar problem, may be helpful:

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.