Industrielle styresystemer - Wiki
Python has a very simple format for publishing and subscribing to data when it comes to MQTT. The first step was to install the needed libraries and the python version was to be updated to python 3 as the libraries only support this version. The library used was paho-mqtt. Since we had not worked with MQTT in python during the course, we watched an introduction to using this library, the link for this is; https://www.youtube.com/watch?v=c_DPKujOmGw. The publisher and subscriber is mostly similar with some differences. This will be outlined and detailed throughout this section.
The setup of MQTT is not explained in detail here as it is similar to the one done in blender. For more information visit MQTT via Blender with Python Module
This was achieved using the multiprocessing and queue library which basically queue's events. The code for multithreading was as follows;
This was done because the camera needed to be controlled from the stockfish file so they needed to be run together. This was the best way to get the two files running bug free.
To add threading in the object detection, the main loop was coded inside a threaded function and this was then joined with the stockfish process using the main code shown above. The object detection code is quite long so a short snippet is shown below. For full code, check the report for the GITHUB link
When this function is called in the stockfish file, the camera starts running. A snapshot function was added as well so that it can be called when the program requires the camera to take a snapshot however, this is not fully functioning yet, there is some problem with the multi-threading in object detection. We are trying to debug this for the presentation. The function is as follows:
This function is supposed to generate the movement string that is taken in by the stockfish engine to play against so currently this part is not working. This was called in the on message function as such;
Since we do not have a lot of experience with multi-threading, the debugging is taking longer than expected. However, other aspects of the MQTT connection itself is working well.
Results;
The figures above show that the stockfish connects to the MQTT connection and the camera is running so threading is working. It is waiting to receive the message and when it does, it prints out the message received.