Running Picar-x libraries from a vitual environment

I am trying to use the picar-x for an autonomous driving project. The plan is to use a convolutional neural network which receives video images from the front camera and the neural network then decides whether to go straight, turn left or turn right. This was already successful with a Raspberry 4 and a Tensorflow-light model. Model inference however was rather slow and the picar had difficulties to follow the track. I am now trying to use a Raspberry Pi 5 with the Hailo AI-Hat, which should speed up the neural network inference. The Hailo AI Hat, however, only runs in its own virtual environment. This is a problem, because I would need to use the Picar-x libraries and the Hailo AI-Hat libraries in one python script.
My question is therefore: can I install the Picar-x libraries (Picar-x, Robot-hat, VIlib, etc) in a virtual environment? The setup.sh scripts seem to work outside of any virtual environment.
Thank you in advance!

Does creating the venv for the hat with --system-site-packages inherit the requisite picar packages? So you can leave picar outside venv as-is

Out of interest, I implemented a similar AI route planner to what you describe for my pidog, Fortunately pidog moves very slowly so my rpi4 is able to keep up!

​

Hi Spf650,
thanks for your question/suggestion. Incidentally, I tried to run the sunfounder Picar-x examples from within the AI Hat virtual environment yesterday and it worked. Apparently I do not have to install both Picar-x and AI Hat libraries in the same environment. The plan is now to install Tensorflow in the AI Hat virtual environment and then I should have all necessary components together :slight_smile:

Edit: I noticed that in order to access system-wide libraries I had to had to change my virtual environment settings. Using virtualenv I edited the ~/venv/pyvenv.cfg config file to set “include-system-site-packages = true”. (Default is “include-system-site-packages = false”, and then python does not see the system-wide libraries.)

1 Like

I’ve found that running through ROS can help performance in that I can easier distribute the various nodes across the 4 cores. Of course, there’s the ROS overhead itself to add, so swings and roundabouts. I use ROS2 humble under bookworm.