LoginSignup
0
0

【PiCar-X】ラズパイの事前準備

Posted at

はじめに

そもそも、RaspberryPi(以下、ラズパイ)を搭載した自律走行型のラジコンは、もう数年前に検証させていただいたし、今更再開する理由はないと思います。
ですが、以前は業務の一環、今回は完全な趣味の世界です。

カメラ付きのラジコンが欲しいなと思ったのが発端です。
ラジコンを探しているときに、以前検証した「DonkeyCar」を思い出しました。

どうせラジコンを買うなら、苦労必至なのは明白ですが、チャレンジしてみたくなり、ラズパイを使ったラジコンを探すことにしました。

なにを買う?

Amazonで検索するといろいろなモデルがあります。
お財布事情と、所有しているRaspberryPi 3Bを使用できることを条件に、以下にします。

image.png

頭と体を慣らすために

ラズパイにはもう5年近く触れていません。
本体を購入する前に、まだ私にもできるのか、リハビリを兼ねて、ドキュメントを読みつつ、ラズパイの準備を選考して開始してみることにします。

OSなどの基本的な準備

使用するラズパイは、数年前に購入したRaspberry Pi 3B。

以下のドキュメントを参考に、ラズパイ側の準備を進めます。

以前に比べ、OSのインストールも楽になりました。
インストール時の設定でWiFiもSSHも有効にできます。
手順に従い、OSをインストール。
その後、VNCも有効にし、母艦のMacからRealVNC Viewerで接続確認。
ここまでは全く危なげなく問題なく完了。

正直、ちょっと拍子抜けするぐらい簡単です。

PiCar-Xは二種類の操作方法がある

PiCar-XはPythonで操作する方法と、Brocklyというビジュアルプログラミングアプリで操作する方法があります。
ドキュメントを確認しましたが、それぞれ別の起動OSを用意する必要があるようです。
今回はまず章立てに従って、Python用の起動OSを用意します。

Pythonで動かす

必須ソフトウェアのインストール

ここからさらにドキュメントに従い、
必要なソフトウェアをインストールしていきます。

「robot-hat」のインストール

ドキュメントだけはわかりませんが、実行ログから以下のインストールを行っていることがわかりました。

Installed /usr/local/lib/python3.9/dist-packages/robot_hat-2.2.11-py3.9.egg
Processing dependencies for robot-hat==2.2.11
Finished processing dependencies for robot-hat==2.2.11
Install dependencies with apt-get:
 - update apt-get... Done
 - install raspi-config... Done
 - install i2c-tools... Done
 - install espeak... Done
 - install libsdl2-dev... Done
 - install libsdl2-mixer-dev... Done
 - install portaudio19-dev... Done
 - install pico2wave... Done
Install dependencies with pip3:
 - update pip3... Done
 - install smbus2... Done
 - install gpiozero... Done
 - install pyaudio... Done
 - install spidev... Done
 - install pyserial... Done
 - install pillow... Done
 - install 'pygame>=2.1.2'... Done
Setup interfaces
 - turn on I2C... Done
 - turn on SPI... Done
Finished

「vilib」のインストール

手順に沿ってvilibのインストールに進みます。

Start installing vilib 0.2.1 for user class
Python version: 3.9.2
Raspbian version: 11 (32bit)

mediapipe is only supported on 64bit system.
apt install dependency:
 - dpkg configure... Done
 - update apt-get... Done
 - install python3-libcamera... Done
 - install python3-picamera2... Done
 - install python3-pyqt5... Done
 - install python3-opengl... Done
 - install python3-opencv... Done
 - install opencv-data... Done
 - install ffmpeg... Done
 - install libgtk-3-0... Done
 - install libxcb-shm0... Done
 - install libcdio-paranoia-dev... Done
 - install libsdl2-2.0-0... Done
 - install libxv1... Done
 - install libtheora0... Done
 - install libva-drm2... Done
 - install libva-x11-2... Done
 - install libvdpau1... Done
 - install libharfbuzz0b... Done
 - install libbluray2... Done
 - install libatlas-base-dev... Done
 - install libhdf5-103... Done
 - install libzbar0... Done
 - install libopenblas-dev... Done
pip3 install dependency:
 pip3 install with --break-system-packages
 - update pip3... Done
 - install tflite-runtime... Done
 - install Flask... Done
 - install imutils... Done
 - install pyzbar... Done
 - install pyzbar[scripts]... Done
 - install readchar... Done
 - install protobuf>=3.20.0... Done
  mediapipe is not supported on this platform... Skip
Create workspace
 - create dir... Done
 - copy workspace... Done
Install vilib python package
 - run setup file... Done
 - cleanup... Done
Finished

「picar-x」のインストール

手順に沿って「picar-x」のインストールに進みます。

running install
running bdist_egg
running egg_info
creating picarx.egg-info
writing picarx.egg-info/PKG-INFO
writing dependency_links to picarx.egg-info/dependency_links.txt
writing entry points to picarx.egg-info/entry_points.txt
writing requirements to picarx.egg-info/requires.txt
writing top-level names to picarx.egg-info/top_level.txt
writing manifest file 'picarx.egg-info/SOURCES.txt'
reading manifest file 'picarx.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
writing manifest file 'picarx.egg-info/SOURCES.txt'
installing library code to build/bdist.linux-armv7l/egg
running install_lib
running build_py
creating build
creating build/lib
creating build/lib/picarx
copying picarx/__init__.py -> build/lib/picarx
copying picarx/version.py -> build/lib/picarx
copying picarx/picarx.py -> build/lib/picarx
creating build/bdist.linux-armv7l
creating build/bdist.linux-armv7l/egg
creating build/bdist.linux-armv7l/egg/picarx
copying build/lib/picarx/__init__.py -> build/bdist.linux-armv7l/egg/picarx
copying build/lib/picarx/version.py -> build/bdist.linux-armv7l/egg/picarx
copying build/lib/picarx/picarx.py -> build/bdist.linux-armv7l/egg/picarx
byte-compiling build/bdist.linux-armv7l/egg/picarx/__init__.py to __init__.cpython-39.pyc
byte-compiling build/bdist.linux-armv7l/egg/picarx/version.py to version.cpython-39.pyc
byte-compiling build/bdist.linux-armv7l/egg/picarx/picarx.py to picarx.cpython-39.pyc
creating build/bdist.linux-armv7l/egg/EGG-INFO
copying picarx.egg-info/PKG-INFO -> build/bdist.linux-armv7l/egg/EGG-INFO
copying picarx.egg-info/SOURCES.txt -> build/bdist.linux-armv7l/egg/EGG-INFO
copying picarx.egg-info/dependency_links.txt -> build/bdist.linux-armv7l/egg/EGG-INFO
copying picarx.egg-info/entry_points.txt -> build/bdist.linux-armv7l/egg/EGG-INFO
copying picarx.egg-info/not-zip-safe -> build/bdist.linux-armv7l/egg/EGG-INFO
copying picarx.egg-info/requires.txt -> build/bdist.linux-armv7l/egg/EGG-INFO
copying picarx.egg-info/top_level.txt -> build/bdist.linux-armv7l/egg/EGG-INFO
creating dist
creating 'dist/picarx-2.0.3-py3.9.egg' and adding 'build/bdist.linux-armv7l/egg' to it
removing 'build/bdist.linux-armv7l/egg' (and everything under it)
Processing picarx-2.0.3-py3.9.egg
creating /usr/local/lib/python3.9/dist-packages/picarx-2.0.3-py3.9.egg
Extracting picarx-2.0.3-py3.9.egg to /usr/local/lib/python3.9/dist-packages
Adding picarx 2.0.3 to easy-install.pth file

Installed /usr/local/lib/python3.9/dist-packages/picarx-2.0.3-py3.9.egg
Processing dependencies for picarx==2.0.3
Searching for readchar==4.0.6
Best match: readchar 4.0.6
Adding readchar 4.0.6 to easy-install.pth file

Using /usr/local/lib/python3.9/dist-packages
Searching for setuptools==52.0.0
Best match: setuptools 52.0.0
Adding setuptools 52.0.0 to easy-install.pth file

Using /usr/lib/python3/dist-packages
Finished processing dependencies for picarx==2.0.3

音を出すための準備

最後に、i2sアンプに必要なコンポーネントをインストールする必要があるようです。

Support for your operating system is experimental. Please visit
forums.adafruit.com if you experience issues with this product.


This script will install everything needed to use
i2s amplifier

--- Warning ---

Always be careful when running scripts and commands
copied from the internet. Ensure they are from a
trusted source.

If you want to see what this script does before
running it, you should run:
    \curl -sS github.com/adafruit/Raspberry-Pi-Installer-Scripts/i2samp

Do you wish to continue? [y/N] y

Checking hardware requirements...

Adding Device Tree Entry to /boot/config.txt
dtoverlay=hifiberry-dac
dtoverlay=i2s-mmap

Commenting out Blacklist entry in
/etc/modprobe.d/raspi-blacklist.conf
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
alsa-utils is already the newest version (1.2.4-1+rpt1).
The following package was automatically installed and is no longer required:
  libfuse2
Use 'sudo apt autoremove' to remove it.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

Installing aplay systemd unit

You can optionally activate '/dev/zero' playback in
the background at boot. This will remove all
popping/clicking but does use some processor time.

Activate '/dev/zero' playback in background? [RECOMMENDED] [y/N] y

Created symlink /etc/systemd/system/multi-user.target.wants/aplay.service 眇? /etc/systemd/system/aplay.service.

Configuring sound output
card_num=
Created symlink /etc/systemd/system/multi-user.target.wants/auto_sound_card.service 眇? /etc/systemd/system/auto_sound_card.service.

We can now test your i2s amplifier
Set your speakers if possible!
Do you wish to test your system now? [y/N] y
Testing...

speaker-test 1.2.4

Playback device is default
Stream parameters are 48000Hz, S16_LE, 2 channels
WAV file(s)
Rate set to 48000Hz (requested 48000Hz)
Buffer size range from 480 to 32768
Period size range from 480 to 32768
Using max buffer size 32768
Periods = 4
was set period_size = 8192
was set buffer_size = 32768
 0 - Front Left
 1 - Front Right
Time per period = 2.407937
 0 - Front Left
 1 - Front Right
Time per period = 3.068430
 0 - Front Left
 1 - Front Right
Time per period = 2.901289
 0 - Front Left
 1 - Front Right
Time per period = 3.069732
 0 - Front Left
 1 - Front Right
Time per period = 3.072104

All done!

Enjoy your new i2s amplifier!

Some changes made to your system require
your computer to reboot to take effect.

Would you like to reboot now? [y/N]

本来の手順では、PiCar-Xのキットをラズパイに組んでから行うのでしょうが、まだラズパイしかない状態なので、この処理で実際に音は出ません。
が、きっと設定は大丈夫だろう、と自己判断し、手順通り再起動で事前準備を終わりとします。

手順の最後にこの一文があることも、「これで良し」と判断した理由の一つ。
image.png

ちなみに、i2c接続のDAコンバータ(TeraDak ES9023)がありますし、それにスピーカーなどを接続すれば音は出るかも知れませんが、手元に手頃なスピーカーがないので今回はパスです。
20240430_070244773_iOS.jpg

つぎは

続いて、Brocklyの環境を構築します。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0