Home > Using RLAI with Raspberry Pi
- Introduction
- Operating System
- Install RLAI
- IDE: PyCharm Community Edition
- VNC (Remote Desktop)
- References
Introduction
The Raspberry Pi is an appealing platform for mobile computation in general and for RLAI in particular. The latest model as of October 2021 has a 64-bit quad-core CPU with 8 GB of RAM. Add-on hardware provides a wide range of sensing and actuation capabilities, and the entire ecosystem is quite affordable.
Operating System
At present, the official Raspberry Pi OS is a 32-bit version of Debian running on the 64-bit ARM CPU. Thus, the OS presents a 32-bit CPU to all software in the OS. It is possible to install most RLAI dependencies, either directly from the package repositories of by building them from source. A specific few, particularly JAX, are neither available in the repositories nor straightforward to build from source for the ARM CPU. There is an open issue for this here, and it indicates that support for 32-bit Raspberry Pi is not likely to appear soon. I experimented with Ubuntu Desktop 21.04 64-bit, which installs and runs without issues on the Raspberry Pi 4 Model B; however, the desktop interface is sluggish, and since this is not an LTS version it is not possible to use the Deadsnakes repository to install Python 3.7 and 3.8 (the Ubuntu default is Python 3.9). The Raspberry Pi Imager does not provide any other Ubuntu Desktop versions. Ultimately, I settled on Ubuntu Server 20.04 64-bit, which is a much slimmer OS that also installs and runs without issues. It defaults to Python 3.8 and works fine with lighter desktop environments like XFCE. The installation is more complicated than for Ubuntu Desktop, but it is entirely feasible. Detailed instructions are provided below.
Image the Raspberry Pi SD Card
- Install and start the Raspberry Pi Imager.
- Select Ubuntu Server 20.04 64-bit within the Raspberry Pi Imager, then write the OS to the SD card.
- Insert the SD card into the Raspberry Pi and boot.
Configure Wireless Internet
sudo nano /etc/wpa_supplicant.conf
(edit as follows, replacing values as indicated):country=US ctrl_interface=DIR=/var/run/wpa_supplicant update_config=1 network={ ssid="Your Wi-Fi SSID" scan_ssid=1 psk="Your Wi-Fi Password" key_mgmt=WPA-PSK }
- Enable wireless interface:
sudo wpa_supplicant -Dnl80211 -B iwlan0 -c/etc/wpa_supplicant.conf
- Obtain wireless address:
sudo dhclient -v
The above should be sufficient to get your Raspberry Pi connected to Wi-Fi. Note that subsequent installation of the
XFCE Desktop Environment (below) will cause the wireless networking settings to be managed by NetworkManager, which
stores connection information in /etc/NetworkManager/system-connections
.
Upgrade OS
sudo apt update
sudo apt upgrade
sudo systemctl reboot
Install Required Packages and XFCE Desktop Environment
sudo apt install gfortran python3-dev libblas-dev liblapack-dev build-essential swig python-pygame git virtualenv qt5-default xvfb ffmpeg
sudo apt install xubuntu-desktop
sudo systemctl reboot
Install RLAI
Configure Virtual Environment
git clone https://github.com/MatthewGerber/rlai.git
cd rlai
virtualenv -p python3.8 venv
. venv/bin/activate
pip install -U pip setuptools wheel
Box2D
git clone https://github.com/pybox2d/pybox2d
cd pybox2d
python setup.py build
python setup.py install
PyQt5
pip install PyQt-builder
wget https://files.pythonhosted.org/packages/8e/a4/d5e4bf99dd50134c88b95e926d7b81aad2473b47fde5e3e4eac2c69a8942/PyQt5-5.15.4.tar.gz
tar -xvzf PyQt5-5.15.4.tar.gz
cd PyQt5-5.15.4
sip-install
JAX
wget https://files.pythonhosted.org/packages/0f/85/0499931fe8e9dc05f4dd5ef989be2db4653d429adf08b9371fc259402af0/jax-0.2.21.tar.gz
tar -xvzf jax-0.2.21.tar.gz
cd jax-0.2.21
pip install numpy==1.21.2 six wheel
cd jax
python build/build.py
pip install dist/*.whl
pip install .
Install and Test RLAI
pip install -e .[dev]
pytest ./test
(or, if running without a display:HEADLESS=True pytest ./test
)
IDE: PyCharm Community Edition
VNC (Remote Desktop)
Using the above configuration, I found the following VNC setup works best, providing automatic screen scaling and reliable operation.
- Install VNC server:
sudo apt install tigervnc-standalone-server
- Start VNC server:
LD_PRELOAD=/lib/aarch64-linux-gnu/libgcc_s.so.1 vncserver :1 -localhost no
- Start SSH tunnel from client, where
XXXX
is the user name andYYYY
is the IP address:ssh -L 59000:localhost:5901 -C -l XXXX YYYY
- Use the TigerVNC client to connect to
localhost:59000
.
References
- https://linuxhint.com/install-ubuntu-desktop-20-04-lts-on-raspberry-pi-4
- https://jax.readthedocs.io/en/latest/developer.html