Grasshopper as a controller using MQTT

Hello

I designed a large-scale kinetic sculpture “Reflexion” - a wall of 91 programmable mirrors. All movements are defined in grasshopper script, compiled as .txt file (describing servo positions in time). By now, I only had this “hard coded” possibility. But me and my friend @makermatty developed MQTT plugin, so I can stream live data to my sculpture and move it directly from Grasshopper. What’s more, I can use external controller (positioner, accelerometer…) and access data from Grasshopper, use it to manipulate geometry and send data directly to mirrors. But we got noticable latency (in comparsion with direct connection between controller and mirrors). So…

I doubt that many people use it for this purpose, but still. I would like to ask someone more experienced than me about speed issues. I don’t understand Rhino/Grasshopper processes enough to optimize it to minimize latency.

Subscribe / Publish components are fast. I noticed that whenever I use timer, all the GH definition run slower (also in other definitions). Is there something that I can do differently, use different approach?

The question is simple - does it make sense to buy better computer, so Grasshopper get / set data faster? Or is it better to solve the problem on software side? Does someone have experiences with “live streaming” from Grasshopper and knows, how to deal with speed / latency issues?

Sharing the full script doesn’t make sense, because our MQTT plugin requires some dll dependency and is not ready for release yet :slight_smile: So at leaset a scheme:

How many bytes are sent per mqtt message? What is the response time for each message? Are you using arduino, esp32 order something else to control the mirrors?

One “frame” size is 1094 Bytes and we need 20 frames per second to get smooth movement. So it’s 21.88 kB per second. Broker is hosted on RaspberryPi and connected to the computer by ethernet. Extenral “interactive” controller is either a mobile phone or custom made device with ESP32. The communicatin between RaspberryPi and servos uses PCA9685 as the driver.

My opinion is that the script itself is not effective and fast enough. For example, if it takes 50ms to calculate 91 normal vectors and positions of all 182 servos, we already hit 20FPS.
I have an idea to use multithreading for the movement calculations. But not sure how to “pack” all the script and send it to all CPU cores at once. I only know how to do it for one component or one C# method…

Any idea appreciated :heart: