autorope / donkeycar

Open source hardware and software platform to build a small scale self driving car.
http://www.donkeycar.com
MIT License
3.05k stars 1.28k forks source link

I2c package needs to be update to work on bookworm #1177

Closed Ezward closed 1 month ago

Ezward commented 1 month ago

Users have indicated that PCA9685 is not working on RaspberryPi OS Bookworm. This is likely because we are using a very old an deprecated library that was not updated to handle the change in how gpio is addressed in RaspberryPi OS.

The old dependency is Adafruit_PCA9685, which is marked as deprecated and suggests using Adafruit_CircuitPython_PCA9685.

Adafruit_CircuitPython_PCA9685 has two pieces we need, the PCA9685 class which initialized the PCA9685 bus, address and frequency, and the PWMChannel class, which controls a specific servo channel on the board.

We need to update the code in two places to use the new classes. The first is in the pin specifiers code, pins.py. The pins.py:PCA9685 class should now import the Adafruit_CircuitPython_PCA9685:PCA9685 class to initialize the board. Then for each pin that is created, it will instantiate a [Adafruit_CircuitPython_PCA9685:PWMChannel]((https://github.com/adafruit/Adafruit_CircuitPython_PCA9685/blob/874545d908077baed0be8055cbbc63280a00c034/adafruit_pca9685.py#L51C7-L51C17) to control the pin.

The other place to update is the legacy donkeycar/parts/actuator.py:PCA9685 actuator class. Here we can eliminate duplication by instantiating a pwm pin using the pin providers PwmPinPCA9685 function, calling it with the pca9685 factory method to get the shared driver. If we do that then all the PCA9685 code is in one place.

Ezward commented 1 month ago

Removing the old driver and install the new one only changes that one package; all the other related packages are not affected. That is good news.

(env) ed@raspberrypi5:~/projects/donkeycar $ pip uninstall Adafruit_PCA9685
Found existing installation: Adafruit-PCA9685 1.0.1
Uninstalling Adafruit-PCA9685-1.0.1:
  Would remove:
    /home/ed/projects/donkeycar/env/lib/python3.11/site-packages/Adafruit_PCA9685-1.0.1.dist-info/*
    /home/ed/projects/donkeycar/env/lib/python3.11/site-packages/Adafruit_PCA9685/*
Proceed (Y/n)? Y
  Successfully uninstalled Adafruit-PCA9685-1.0.1
(env) ed@raspberrypi5:~/projects/donkeycar $ pip3 install adafruit-circuitpython-pca9685
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting adafruit-circuitpython-pca9685
  Downloading https://www.piwheels.org/simple/adafruit-circuitpython-pca9685/adafruit_circuitpython_pca9685-3.4.15-py3-none-any.whl (6.0 kB)
Requirement already satisfied: Adafruit-Blinka in ./env/lib/python3.11/site-packages (from adafruit-circuitpython-pca9685) (8.39.1)
Requirement already satisfied: adafruit-circuitpython-register in ./env/lib/python3.11/site-packages (from adafruit-circuitpython-pca9685) (1.9.18)
Requirement already satisfied: adafruit-circuitpython-busdevice in ./env/lib/python3.11/site-packages (from adafruit-circuitpython-pca9685) (5.2.9)
Requirement already satisfied: Adafruit-PlatformDetect>=3.62.0 in ./env/lib/python3.11/site-packages (from Adafruit-Blinka->adafruit-circuitpython-pca9685) (3.62.0)
Requirement already satisfied: Adafruit-PureIO>=1.1.7 in ./env/lib/python3.11/site-packages (from Adafruit-Blinka->adafruit-circuitpython-pca9685) (1.1.11)
Requirement already satisfied: pyftdi>=0.40.0 in ./env/lib/python3.11/site-packages (from Adafruit-Blinka->adafruit-circuitpython-pca9685) (0.55.4)
Requirement already satisfied: adafruit-circuitpython-typing in ./env/lib/python3.11/site-packages (from Adafruit-Blinka->adafruit-circuitpython-pca9685) (1.10.3)
Requirement already satisfied: RPi.GPIO in /usr/lib/python3/dist-packages (from Adafruit-Blinka->adafruit-circuitpython-pca9685) (0.7.1a4)
Requirement already satisfied: rpi-ws281x>=4.0.0 in ./env/lib/python3.11/site-packages (from Adafruit-Blinka->adafruit-circuitpython-pca9685) (5.0.0)
Requirement already satisfied: sysv-ipc>=1.1.0 in ./env/lib/python3.11/site-packages (from Adafruit-Blinka->adafruit-circuitpython-pca9685) (1.1.0)
Requirement already satisfied: typing-extensions~=4.0 in ./env/lib/python3.11/site-packages (from adafruit-circuitpython-register->adafruit-circuitpython-pca9685) (4.11.0)
Requirement already satisfied: adafruit-circuitpython-requests in ./env/lib/python3.11/site-packages (from adafruit-circuitpython-typing->Adafruit-Blinka->adafruit-circuitpython-pca9685) (3.2.8)
Requirement already satisfied: pyusb!=1.2.0,>=1.0.0 in ./env/lib/python3.11/site-packages (from pyftdi>=0.40.0->Adafruit-Blinka->adafruit-circuitpython-pca9685) (1.2.1)
Requirement already satisfied: pyserial>=3.0 in /usr/lib/python3/dist-packages (from pyftdi>=0.40.0->Adafruit-Blinka->adafruit-circuitpython-pca9685) (3.5)
Requirement already satisfied: Adafruit-Circuitpython-ConnectionManager in ./env/lib/python3.11/site-packages (from adafruit-circuitpython-requests->adafruit-circuitpython-typing->Adafruit-Blinka->adafruit-circuitpython-pca9685) (2.0.0)
Installing collected packages: adafruit-circuitpython-pca9685
Successfully installed adafruit-circuitpython-pca9685-3.4.15
Ezward commented 1 month ago

Branch: https://github.com/autorope/donkeycar/tree/1177-update-i2c-driver-for-bookwork

Ezward commented 1 month ago

I've tested main (donkey 5.1dev1) and it works fine on a RaspberryPi 5 with RaspberryPi OS bookworm. So I am closing this issue because we do not need it right now. I'm closing the associated PR https://github.com/autorope/donkeycar/pull/1178 as well. That code has some bug i the throttle output, but is mostly complete, so I'll keep the branch around in case we decide we want to do this work in the future.