Using the hideous RoboClaw Python "library" in a project, I can't seem to get past the fact that they threw a bunch of functions and global variables that deal with interfacing with physical hardware into a file. Unfortunately, I am stuck using this library because when the vendor releases a new firmware for their board, they also update this file on their website; porting it to something useful would be a continuous effort.
The issue arises when I attempt to import it multiple times, once for each board that I have attached to USB. Something (conceptually) like this would be ideal:
import roboclaw
class Board:
def __init__(self):
self.rc = roboclaw
Since the Python interpreter seems to maintain the same module reference in memory with every import, I can't seem to get it to create instances that exist in separate namespaces, essentially spitting out all kinds of I/O conflict errors when all boards incorrectly become assigned to the same /dev/ttyACM
device file. The closest that I seem to be able to get is this answer provided by Noctis Skytower, but it still isn't creating a separate namespaces for each Board
instance.
Additionally, I have tried setting up dynamic imports using imp
(like this) and importlib
(like this) though both of these fail to import because they can't find the roboclaw.py
file that sits in the same directory.
At a bit of a loss for the direction that I should be going on this, as I've never had to deal with this before.