DexterInd / GoPiGo3

The GoPiGo3 is a Raspberry Pi Robot!
https://gopigo.io
Other
101 stars 85 forks source link

Run GoPiGo3 w/ RHEL/CentOS/Fedora IoT? #320

Open goetzrieger opened 2 years ago

goetzrieger commented 2 years ago

Hi there:

Is it feasible or does anybody has experience running the GoPiGo3 with a non-Debian Linux distro like in $SUBJECT?

Background: We have a small fleet of GoPiGo3's (around 15) we used to run event workshops for our (Red Hat, that is) developer line of products. Until, well, Covid came along. So it's been 2.5 years and we would like to revive this, but would like to brush up our game:

All of this requires one of the above distros running and probably a raspi 4 and something like a Google Coral TPU stick.

Before I start digging into the setup scripts and hitting roadblocks any help would be appreciated!

CleoQc commented 2 years ago

Hello there and welcome back! The GoPiGo3 can be run with minimal installation on other distros as long as you do some setup manually.

Of the top of my head, you need to make sure SPI and I2C are active. Lately the GoPiGo3 uses pigpiod which may not be available on other distros so you would need some changes in gopigo3.py

The import : https://github.com/DexterInd/GoPiGo3/blob/master/Software/Python/gopigo3.py#L30

And these setup lines https://github.com/DexterInd/GoPiGo3/blob/master/Software/Python/gopigo3.py#L231-L235

And this install script: https://github.com/DexterInd/GoPiGo3/blob/7652f5b8c1815b7e51d5bc568f347e6fd0d1efa4/Install/install.sh#L47-L51

You won't need any of the tools that are tailored to beginners and that saves a lot of hassle.

Instead of running the install script, you can go ahead and run

python3 setup.py install

I think it will work...

CleoQc commented 2 years ago

@slowrunner has been able to install it on Ubuntu, he may have some words of wisdom.

jharris1993 commented 2 years ago

Slowrunner, (also known as "cyclicalobsessive" on the forum), has done a considerable body of work on this exact subject - getting Dexter Industries GoPiGo software to work on other platforms. Please check his work on the Dexter forums at https://forum.dexterindustries.com

One possible kicker: Most everything we've done is using software based off of Debian/Ubuntu distributions and, (as far as I know), it has never been attempted on a non-Debian derived distribution. (It has been successfully installed on ROS/ROS-2 and I don't know if those are Debian based or not.)

Please go to the forums, post your question there too, and if you try this with any non-Debian based release, let us know what worked and what didn't.

One other thing: If you're going to be running a lot of code and want blazing fast access times - I have contributed to the literature on the forum about running the GoPiGo using Seagate external SSD's. I have also contributed articles on how to multi-boot the robot using either PINN or dip-switches attached to GPIO pins. These may also be worth a look.

Thanks!

slowrunner commented 2 years ago

@goetzrieger These are my steps to install the basic GoPiGo3 API and supporting configuration on Ubuntu 20.0.4:

==== BEGIN GOPIGO3 SPECIFIC STEPS

===== Create a Pi user with a /home/pi default directory, /bin/bash login shell ===

$ sudo useradd -m pi
$ sudo passwd pi

$ sudo usermod -a -G ubuntu,adm,dialout,cdrom,floppy,sudo,audio,dip,video,plugdev,netdev,lxd pi
$ sudo groupadd gpio
$ sudo groupadd i2c
$ sudo groupadd spi
$ sudo usermod -a -G gpio,i2c,spi pi
$ sudo usermod -a -G gpio,i2c,spi ubuntu
$ sudo usermod -a -G pi ubuntu

Check with:
$ groups pi
$ groups ubuntu

=== CONFIGURE PASSWORD-LESS SUDO

sudo nano /etc/sudoers

make sudo group look like:
# Allow members of group sudo to execute any command
%sudo   ALL=(ALL:ALL) NOPASSWD: ALL

=== CONFIGURE PI DEFAULT SHELL TO BASH

$ sudo chsh -s /bin/bash pi

=== ALLOW non-root SPI and GPIO  (Temporarily - will make permanent later)

$ sudo chgrp spi /dev/spidev0.0
$ sudo chgrp spi /dev/spidev0.1

$ sudo chmod 660 /dev/spidev0.0
$ sudo chmod 660 /dev/spidev0.1

$ sudo chgrp gpio /sys/class/gpio/export
$ sudo chgrp gpio /sys/class/gpio/unexport

$ sudo chmod 770 /sys/class/gpio/export
$ sudo chmod 770 /sys/class/gpio/unexport

=== [SKIP] === Enable spi, i2c without raspi-config

6/3/21: system-boot/sysconfig.txt now has these configured

enable_uart=1
dtparam=audio=on
dtparam=i2c_arm=on
dtparam=spi=on

==== GOPIGO3 LIBRARIES 
$ logout
$ ssh pi@x.x.x.x
$ sudo git clone -b install_on_ubuntu http://www.github.com/DexterInd/GoPiGo3.git /home/pi/Dexter/GoPiGo3

$ sudo curl -kL dexterindustries.com/update_tools | bash -s -- --system-wide --use-python3-exe-too --install-deb-debs --install-python-package
[sudo] password for pi:  (enter login pswd for pi)

$ sudo apt-get install --no-install-recommends python3-pip python3-numpy python3-curtsies

=== DI_SENSORS LIBRARY

$ sudo git clone https://github.com/DexterInd/DI_Sensors.git /home/pi/Dexter/DI_Sensors

==== [Already installed] RPi.GPIO

sudo apt install python3-rpi.gpio  

==== PIGPIO ===
$ sudo apt-get install unzip
$ wget https://github.com/joan2937/pigpio/archive/master.zip
$ unzip master.zip
$ cd pigpio-master
$ make
$ sudo make install
$ cd ..
$ rm master.zip

=== pigpiod

wget https://raw.githubusercontent.com/joan2937/pigpio/master/util/pigpiod.service

(Replacing with the non-forking version - don't know why)

$ sudo nano pigpiod.service

[Unit]
Description=Pigpio daemon
After=network.target syslog.target
StartLimitIntervalSec=60
StartLimitBurst=5
StartLimitAction=reboot

[Service]
Type=simple
ExecStartPre=/sbin/sysctl -w net.ipv4.tcp_keepalive_time=300
ExecStartPre=/sbin/sysctl -w net.ipv4.tcp_keepalive_intvl=60
ExecStartPre=/sbin/sysctl -w net.ipv4.tcp_keepalive_probes=5
# Don't fork pigpiod
ExecStart=/usr/local/bin/pigpiod -g
ExecStop=
Restart=always
RestartSec=10

[Install]
WantedBy=multi-user.target

$ sudo cp pigpiod.service /etc/systemd/system

$ sudo systemctl enable pigpiod.service
$ sudo systemctl start pigpiod.service
$ systemctl status pigpiod.service
● pigpiod.service - Pigpio daemon
     Loaded: loaded (/etc/systemd/system/pigpiod.service; enabled; vendor preset: enabled)
     Active: active (running) since Fri 2021-06-04 20:08:56 EDT; 9s ago
    Process: 8685 ExecStartPre=/sbin/sysctl -w net.ipv4.tcp_keepalive_time=300 (code=exited, status=0/SUCCESS)
    Process: 8686 ExecStartPre=/sbin/sysctl -w net.ipv4.tcp_keepalive_intvl=60 (code=exited, status=0/SUCCESS)
    Process: 8687 ExecStartPre=/sbin/sysctl -w net.ipv4.tcp_keepalive_probes=5 (code=exited, status=0/SUCCESS)
   Main PID: 8688 (pigpiod)
      Tasks: 4 (limit: 973)
     CGroup: /system.slice/pigpiod.service
             └─8688 /usr/local/bin/pigpiod -g

Jun 04 20:08:56 ROSPI systemd[1]: Starting Pigpio daemon...
Jun 04 20:08:56 ROSPI sysctl[8685]: net.ipv4.tcp_keepalive_time = 300
Jun 04 20:08:56 ROSPI sysctl[8686]: net.ipv4.tcp_keepalive_intvl = 60
Jun 04 20:08:56 ROSPI sysctl[8687]: net.ipv4.tcp_keepalive_probes = 5
Jun 04 20:08:56 ROSPI systemd[1]: Started Pigpio daemon.

=== R4R_Tools (for I2C_mutex)
$ sudo git clone https://github.com/DexterInd/RFR_Tools.git /home/pi/Dexter/lib/Dexter/RFR_Tools
$ sudo apt-get install libffi-dev
$ cd /home/pi/Dexter/lib/Dexter//RFR_Tools/miscellaneous/
$ sudo python3 setup.py install

Check that the mutex stuff will be available:

$ unzip -l /usr/local/lib/python3.8/dist-packages/Dexter_AutoDetection_and_I2C_Mutex-0.0.0-py3.8.egg
Archive:  /usr/local/lib/python3.8/dist-packages/Dexter_AutoDetection_and_I2C_Mutex-0.0.0-py3.8.egg
  Length      Date    Time    Name
---------  ---------- -----   ----
     3154  2021-05-31 15:48   I2C_mutex.py
     9445  2021-05-31 15:48   auto_detect_robot.py
     6211  2021-05-31 15:48   auto_detect_rpi.py
    23756  2021-05-31 15:48   di_i2c.py
     1700  2021-05-31 15:48   di_mutex.py
      303  2021-05-31 15:51   EGG-INFO/PKG-INFO
      372  2021-05-31 15:51   EGG-INFO/SOURCES.txt
        1  2021-05-31 15:51   EGG-INFO/dependency_links.txt
       46  2021-05-31 15:51   EGG-INFO/requires.txt
       60  2021-05-31 15:51   EGG-INFO/top_level.txt
        1  2021-05-31 15:51   EGG-INFO/zip-safe
     2812  2021-05-31 15:51   __pycache__/I2C_mutex.cpython-38.pyc
     6565  2021-05-31 15:51   __pycache__/auto_detect_robot.cpython-38.pyc
     4592  2021-05-31 15:51   __pycache__/auto_detect_rpi.cpython-38.pyc
    14282  2021-05-31 15:51   __pycache__/di_i2c.cpython-38.pyc
     1652  2021-05-31 15:51   __pycache__/di_mutex.cpython-38.pyc
---------                     -------
    74952                     16 files

==== wiringPi ====

cd /home/pi/Dexter/lib
git clone https://github.com/DexterInd/wiringPi/
cd wiringPi
sudo chmod +x ./build
sudo ./build

==== [SKIP] antenna wifi service
sudo mkdir -p /etc/systemd/system/antenna_wifi.service.d/

sudo cp /home/pi/di_update/Raspbian_For_Robots/upd_script/antenna_wifi_override.conf /etc/systemd/system/antenna_wifi.service.d/
sudo nano /etc/systemd/system/antenna_wifi.service.d 
  change Restart=always to =no
sudo systemctl daemon-reload
sudo systemctl restart antenna_wifi.service

systemctl status antenna_wifi    shows it ran once, exited and not restarted

- to disable it:
sudo systemctl disable antenna_wifi

==== GPG3_POWER SERVICE ===
  cd ~
  sudo cp /home/pi/Dexter/GoPiGo3/Install/gpg3_power.service /etc/systemd/system
  sudo chmod 644 /etc/systemd/system/gpg3_power.service
  sudo systemctl daemon-reload
  sudo systemctl enable gpg3_power.service
  sudo systemctl start gpg3_power.service

====  [SKIP]  AUTODETECT ROBOT ===
X mkdir /home/pi/Dexter/R4R
X cd /home/pi/Dexter/R4R
X wget https://raw.githubusercontent.com/DexterInd/Raspbian_For_Robots/master/buster_update/auto_detect_robot.service
X sudo cp /home/pi/Dexter/R4R/auto_detect_robot.service /etc/systemd/system/
X sudo systemctl daemon-reload
X sudo systemctl enable auto_detect_robot.service
X sudo systemctl start auto_detect_robot.service

==== SETUP GoPiGo3 and DI_Sensors Python3 eggs 
$ cd /home/pi/Dexter/GoPiGo3/Software/Python
$ sudo python3 setup.py install
$ cd /home/pi/Dexter/DI_Sensors/Python
$ sudo python3 setup.py install

==== Setup non-root access rules ====

$ sudo nano /etc/udev/rules.d/99-com.rules

SUBSYSTEM=="input", GROUP="input", MODE="0660"
SUBSYSTEM=="i2c-dev", GROUP="i2c", MODE="0660"
SUBSYSTEM=="spidev", GROUP="spi", MODE="0660"
SUBSYSTEM=="bcm2835-gpiomem", GROUP="gpio", MODE="0660"
SUBSYSTEM=="rpivid-*", GROUP="video", MODE="0660"

KERNEL=="vcsm-cma", GROUP="video", MODE="0660"
SUBSYSTEM=="dma_heap", GROUP="video", MODE="0660"

SUBSYSTEM=="gpio", GROUP="gpio", MODE="0660"
SUBSYSTEM=="gpio*", PROGRAM="/bin/sh -c '\
    chown -R root:gpio /sys/class/gpio && chmod -R 770 /sys/class/gpio;\
    chown -R root:gpio /sys/devices/virtual/gpio && chmod -R 770 /sys/devices/virtual/gpio;\
    chown -R root:gpio /sys$devpath && chmod -R 770 /sys$devpath\
'"

SUBSYSTEM=="pwm*", PROGRAM="/bin/sh -c '\
    chown -R root:gpio /sys/class/pwm && chmod -R 770 /sys/class/pwm;\
    chown -R root:gpio /sys/devices/platform/soc/*.pwm/pwm/pwmchip* && chmod -R 770 /sys/devices/platform/soc/*.pwm/pwm/pwmchip*\
'"

KERNEL=="ttyAMA0", PROGRAM="/bin/sh -c '\
    ALIASES=/proc/device-tree/aliases; \
    if cmp -s $$ALIASES/uart0 $$ALIASES/serial0; then \
        echo 0;\
    elif cmp -s $$ALIASES/uart0 $$ALIASES/serial1; then \
        echo 1; \
    else \
        exit 1; \
    fi\
'", SYMLINK+="serial%c"

KERNEL=="ttyAMA1", PROGRAM="/bin/sh -c '\
    ALIASES=/proc/device-tree/aliases; \
    if [ -e /dev/ttyAMA0 ]; then \
        exit 1; \
    elif cmp -s $$ALIASES/uart0 $$ALIASES/serial0; then \
        echo 0;\
    elif cmp -s $$ALIASES/uart0 $$ALIASES/serial1; then \
        echo 1; \
    else \
        exit 1; \
    fi\
'", SYMLINK+="serial%c"

KERNEL=="ttyS0", PROGRAM="/bin/sh -c '\
    ALIASES=/proc/device-tree/aliases; \
    if cmp -s $$ALIASES/uart1 $$ALIASES/serial0; then \
        echo 0; \
    elif cmp -s $$ALIASES/uart1 $$ALIASES/serial1; then \
        echo 1; \
    else \
        exit 1; \
    fi \
'", SYMLINK+="serial%c"

ACTION=="add", SUBSYSTEM=="vtconsole", KERNEL=="vtcon1", RUN+="/bin/sh -c '\
    if echo RPi-Sense FB | cmp -s /sys/class/graphics/fb0/name; then \
        echo 0 > /sys$devpath/bind; \
    fi; \
'"

=== ESPEAK-NG 
  - Not installing python3-espeak or speech-dispatcher-espeak-ng (installs pulseaudio)
$ sudo apt-get install -y espeak-ng
$ espeak-ng "Hello"
  - if want python interface to espeak-ng:
    $ pip3 install py-espeak-ng

==== FULL POWEROFF FOR CLEAN TEST
$ sudo shutdown -h now

Boot up in GoPiGo3

$ ssh pi@X.X.X.X

=== Test GoPiGo Functions
$ cd ~
$ python3 Dexter/GoPiGo3/Software/Python/Examples/Read_Info.py
$ python3 Dexter/GoPiGo3/Software/Python/Examples/LED.py
$ python3 Dexter/GoPiGo3/Software/Python/Examples/easy_Distance_Sensor.py
$ python3 Dexter/DI_Sensors/Python/Examples/IMUSensor.py

$ python3 Dexter/GoPiGo3/Software/Python/Examples/Servo.py
$ python3 Dexter/GoPiGo3/Software/Python/Examples/Motor_Turn.py
jharris1993 commented 2 years ago

One thing that is implicit in all of this is that there is a hard dependency on the "pi" user as the primary, (default), user. (i.e. When you create your initial username for the system, it should be "pi".)

This is a known "issue" based on the fact that the GoPiGo libraries were originally designed to be installed over a stock Raspbian install where the default username was "pi". This is known and there are plans to fix this - I don't know if or when.

The "pi" user should also be in the sudoers file and in the wheel group to make sure it can do whatever you need it to do.

References to raspi-config do not apply to non Raspbian based systems, AFAIK.

One other note: AFAIK, the current libraries are specific to the GoPiGo-3. I do not know to what extent, if at all, they're applicable to older versions of the GoPiGo. Perhaps @CleoQc can comment on this?

===============

Question: Are there other non-Debian based releases for the Raspberry Pi?

I know of Pidora, (and some RISC based stuff and maybe Arch), but things like Red Hat, Slackware, CentOS, etc - I don't know.

Which specific distributions are you talking about? (links please!) It might be interesting to try installs on a GoPiGo-3 and see what happens.

goetzrieger commented 2 years ago

Wow, good to see there is a really active community around! Even after this Covid-induced time of very little in-person events. But I‘m really eager going back running Robot Hackathons now. And @CleoQc, I very well remember how you helped out with faulty boards on short notice to rescue one of our event in 2019.

Okay. From what I understand there is an „old-style“ sysfs interface to GPIO that is deprecated since Kernel 4.8 or so and the new /dev/gpiochip* interface. Most modern distros are starting to use the new interface, notably Fedora-based ones. https://embeddedbits.org/new-linux-kernel-gpio-user-space-interface/

So on Fedora the old sysfs-style interface is not enabled in the kernel and pigpiod is not available.

Nicole mentioned above Gopigo3 Python libs are using pigpiod now which I understand is using the sysfs interface. Does that mean there is a lot of work in porting the gopigo3 libs/API to the new interface? The library is called libgpiod and has Python bindings, too.

I’m being a bit verbose because I‘m pretty new to this stuff and this would put a stop on my experiment already.

goetzrieger commented 2 years ago

@jharris1993 Fedora is kind of the upstream community project to our Red Hat Enterprise Linux. We are moving fast into the „Edge“ use cases so Fedora and in the newest version RHEL are able to run on ARM as found in lots of IoT devices. https://docs.fedoraproject.org/en-US/quick-docs/raspberry-pi/

My main target for our GopiGo’s is Fedora IoT which is running on Raspi quite well and is a great foundation for deploying containerized applications. https://getfedora.org/en/iot/

This would e.g. allow us to run the Gopigo libs in a container and maybe something like a Tensorflow-lite based image recognition application in another one on the robot.

But first I‘ve got to get the robot running with Fedora.