When considering possible methods for managing a multisensor system managed by a single microprocessor, there are a number of considerations to be made regarding the timing efficiency of the program. Surely the cleanest approach to this data management would be to implement the Robot Operating System (ROS); however, throughout testing the actual usage and implementation of ROS to the Raspberry Pi system proved to be challenging and buggy. Additionally, considering our system would only use a few sensors at most, the team was confident the system could be constructed manually in python.
The image below is an example of how we accomplished this for the purposes of our project. The image is an example of the creation of a single additional simultaneous thread that runs the function “trackpavementangle”. This function is setup to continuously collect images and return an error angle for the direction of the car. Once execution is cancelled this thread is closed along with the main thread. More can be read through our Github link in the Home tab.
Multithreading was necessary for our project because the camera sensor had a very high latency which would consistently block execution and cause data sampling issues for the other sensors on the car. Threading solves this by executing the camera code on a separate thread which is carried out by a different core of the Raspberry Pi meaning both the camera thread and the main thread could run simultaneously without impacting eachothers’ execution.