When I added an INA219 Voltage/Current sensor to GoPi5Go-Dave, I discovered the sensor needed multi-process I2C protection. I created an “EasyINA219” class that used the Dexter Industries I2C mutex.
Next up was to create a ROS “Battery node” that uses the EasyINA219 class to publish battery information periodically for other nodes that need to make decisions based on the remaining battery level or the charging/discharging status.
The ROS Battery node lives inside a Docker container but some of my non-ROS programs that live outside the Docker container also access the INA219 sensor (my docking test program, battery status script, and others.) I mapped the Raspberry PiOS I2C bus to the Ubuntu I2C bus inside the Docker container to allow the EasyINA219 class inside the container to communicate with the INA219 sensor hardware attached to the Raspberry Pi PiOS I2C bus.
About a month ago, I hit a snag as I was translating my docking test program into a ROS program, where testing the ROS battery node inside the container would mess up the docking test program outside the container, even though both were using the same “mutex protected” EasyINA219 class. I decided to take a break from working in ROS with no idea why my INA219 class was not working as designed.
Also about a month ago, @jimrh asked about using a mutex on his GoPiGo3 robot to protect SPI access. We worked out how the Dexter Industries mutex could be used for his applications.
Only today, a light popped on! The EasyINA219 class was accessing its mutex in the Raspberry PiOS /var/lock/ folder but the Docker container has a totally separate Ubuntu /var/lock/ folder! I need to map that folder so that the EasyINA219 class inside the container can see if any Raspberry PiOS processes have locked the I2C bus, and vice versa.
I need to test the mutex between the two environments, and if the mapping works I can restart my ROS battery node and continue porting my pure Python docking test program into a ROS 2 docking test node.
I think the mystery has been solved.