LoginSignup
9
10

Raspberry PIを使ったラジコン&ドンキーカー(今回はタミヤリモコンカー)自動運転をする。

9月13日(うるう年は9月12日)はプログラマの日
https://qiita.com/kaizen_nagoya/items/5201b2968ff440320dae

に予定している内容を整理しています。

松浦光洋さんの資料

DonkeyCar の製作(TAMIYA GF-01)
https://qiita.com/mituhiromatuura/items/6b84b4d89abf328b96a7

以下各節で参照

今回用意したもの

Raspberry PI3

タミヤリモコンカー
https://www.amazon.co.jp/dp/B00R0QAF8E/

サインスマート 広角 魚眼レンズ カメラモジュール Camera Module Raspberry Pi用
https://www.amazon.co.jp/gp/product/B00N1YJKFS/

I2C接続16チャンネル サーボ&PWM駆動キット
http://akizukidenshi.com/catalog/g/gK-10350/

エレコム ワイヤレス ゲームパッド 小型軽量 12ボタン 連射 高耐久ボタン(日本メーカー製)採用 300万回耐久試験クリア ブラック JC-U3912TBK
https://amzn.to/2BDC2qx

作業

リモコンカーを動かす

受け入れ試験の一環として、リモコンカーを付属のリモコンに乾電池を入れ、リモコンカーの電池を付属の充電池で充電して動かす。

I2Cキットのはんだ付け

はんだ付けが必要なのは、1列6本のピンと3列12本のピンの合計18箇所。

テスタでの確認

GND同士が導通があるかどうか。
GND以外のピン同士がショートしていないか。

配線

I2Cキット、リモコンカー、Raspberry PIの間を配線する。

I2CキットとRaspberry PI間の配線は、凹同士のケーブル4本でピンを接続する。
I2Cキットとリモコンカーはリモコンカー側のケーブルを使う。

Raspbian SDカード

DonkeyCar 用 ラズパイ boot SD の作り方
https://qiita.com/mituhiromatuura/items/d0268d8ec3577cf3e7d7

RASPBIANに導入するソフト

$ sudo apt-get update
$ sudo apt-get install git

DonkeyCar セットアップ
https://qiita.com/mituhiromatuura/items/86a4dde22f469119f9d3

筆者(松浦光洋)のgithubからファイル一式を入手
$ git clone https://github.com/mituhiromatuura/donkey
$ pip install -e donkey[pi]
$ donkey createcar --template manage_車体名(gf-01,tt-02,picar,pimouse,zumo) ~/mycar
~/mycarは任意のフォルダ名
設定ファイルを車体用の物に差し替える
$ cp donkey/donkeycar/templates/config_車体名.py ~/mycar/config.py
$ cd ~/mycar
$ python manage.py drive

PC(mac)側に導入するソフト

上記URL参照

作業記録

Raspbian

pi@raspberrypi:~ $ sudo apt-get update
取得:1 http://archive.raspberrypi.org/debian stretch InRelease [25.3 kB]       
取得:2 http://mirrordirector.raspbian.org/raspbian stretch InRelease [15.0 kB] 
取得:3 http://archive.raspberrypi.org/debian stretch/main armhf Packages [175 kB]
取得:4 http://mirrordirector.raspbian.org/raspbian stretch/main armhf Packages [11.7 MB]
取得:5 http://archive.raspberrypi.org/debian stretch/ui armhf Packages [34.3 kB]
取得:6 http://mirrordirector.raspbian.org/raspbian stretch/contrib armhf Packages [56.9 kB]
12.0 MB を 1分 1秒 で取得しました (196 kB/s)                                   
エラー: タイムアウトしました
パッケージリストを読み込んでいます... 完了

pi@raspberrypi:~ $ sudo apt-get install git
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています                
状態情報を読み取っています... 完了
提案パッケージ:
  git-daemon-run | git-daemon-sysvinit git-doc git-el git-email git-gui gitk
  gitweb git-arch git-cvs git-mediawiki git-svn
以下のパッケージはアップグレードされます:
  git
アップグレード: 1 個、新規インストール: 0 個、削除: 0 個、保留: 263 個。
3,388 kB のアーカイブを取得する必要があります。
この操作後に追加で 28.7 kB のディスク容量が消費されます。
取得:1 http://ftp.jaist.ac.jp/pub/Linux/raspbian-archive/raspbian stretch/main armhf git armhf 1:2.11.0-3+deb9u3 [3,388 kB]
3,388 kB を 2秒 で取得しました (1,213 kB/s)
changelog を読んでいます... 完了
(データベースを読み込んでいます ... 現在 123605 個のファイルとディレクトリがインストールされています。)
.../git_1%3a2.11.0-3+deb9u3_armhf.deb を展開する準備をしています ...
git (1:2.11.0-3+deb9u3) で (1:2.11.0-3+deb9u2 に) 上書き展開しています ...
git (1:2.11.0-3+deb9u3) を設定しています ...

pi@raspberrypi:~ $ git clone https://github.com/mituhiromatuura/donkey
Cloning into 'donkey'...
remote: Counting objects: 6140, done.
remote: Compressing objects: 100% (8/8), done.
remote: Total 6140 (delta 1), reused 3 (delta 1), pack-reused 6131
Receiving objects: 100% (6140/6140), 30.59 MiB | 1.69 MiB/s, done.
Resolving deltas: 100% (3568/3568), done.
pi@raspberrypi:~ $ pip install -e donkey[pi]
Obtaining file:///home/pi/donkey
Collecting docopt (from donkeycar==2.5.1)
  Downloading https://www.piwheels.hostedpi.com/simple/docopt/docopt-0.6.2-py2.py3-none-any.whl
Collecting eventlet (from donkeycar==2.5.1)
  Downloading https://files.pythonhosted.org/packages/86/7e/96e1412f96eeb2f2eca9342dcc4d5bc9305880a448b603b0a8e54439b71c/eventlet-0.24.1-py2.py3-none-any.whl (219kB)
    100% |████████████████████████████████| 225kB 835kB/s 
Collecting flask (from donkeycar==2.5.1)
  Downloading https://files.pythonhosted.org/packages/7f/e7/08578774ed4536d3242b14dacb4696386634607af824ea997202cd0edb4b/Flask-1.0.2-py2.py3-none-any.whl (91kB)
    100% |████████████████████████████████| 92kB 1.4MB/s 
Collecting h5py (from donkeycar==2.5.1)
  Downloading https://files.pythonhosted.org/packages/74/5d/6f11a5fffc3d8884bb8d6c06abbee0b3d7c8c81bde9819979208ba823a47/h5py-2.8.0.tar.gz (274kB)
    100% |████████████████████████████████| 276kB 465kB/s 

なぜか、個々で10分止まっている。
別のコマンドプロンプトを起動し、

pi@raspberrypi:~ $ ps -ax
  PID TTY      STAT   TIME COMMAND
    1 ?        Ss     0:02 /sbin/init splash
    2 ?        S      0:00 [kthreadd]
    3 ?        S      0:00 [ksoftirqd/0]
    5 ?        S<     0:00 [kworker/0:0H]
    6 ?        S      0:00 [kworker/u8:0]
    7 ?        S      0:00 [rcu_sched]
    8 ?        S      0:00 [rcu_bh]
    9 ?        S      0:00 [migration/0]
   10 ?        S<     0:00 [lru-add-drain]
   11 ?        S      0:00 [cpuhp/0]
   12 ?        S      0:00 [cpuhp/1]
   13 ?        S      0:00 [migration/1]
   14 ?        S      0:00 [ksoftirqd/1]
   16 ?        S<     0:00 [kworker/1:0H]
   17 ?        S      0:00 [cpuhp/2]
   18 ?        S      0:00 [migration/2]
   19 ?        S      0:00 [ksoftirqd/2]
   21 ?        S<     0:00 [kworker/2:0H]
   22 ?        S      0:00 [cpuhp/3]
   23 ?        S      0:00 [migration/3]
   24 ?        S      0:00 [ksoftirqd/3]
   26 ?        S<     0:00 [kworker/3:0H]
   27 ?        S      0:00 [kdevtmpfs]
   28 ?        S<     0:00 [netns]
   29 ?        S      0:00 [khungtaskd]
   30 ?        S      0:00 [oom_reaper]
   31 ?        S<     0:00 [writeback]
   32 ?        S      0:00 [kcompactd0]
   33 ?        S<     0:00 [crypto]
   34 ?        S<     0:00 [bioset]
   35 ?        S<     0:00 [kblockd]
   36 ?        S<     0:00 [watchdogd]
   38 ?        S<     0:00 [rpciod]
   39 ?        S<     0:00 [xprtiod]
   40 ?        S      0:00 [kswapd0]
   41 ?        S<     0:00 [vmstat]
   42 ?        S<     0:00 [nfsiod]
   52 ?        S<     0:00 [kthrotld]
   53 ?        S<     0:00 [bioset]
   54 ?        S<     0:00 [bioset]
   55 ?        S<     0:00 [bioset]
   56 ?        S<     0:00 [bioset]
   57 ?        S<     0:00 [bioset]
   58 ?        S<     0:00 [bioset]
   59 ?        S<     0:00 [bioset]
   60 ?        S<     0:00 [bioset]
   61 ?        S<     0:00 [bioset]
   62 ?        S<     0:00 [bioset]
   63 ?        S<     0:00 [bioset]
   64 ?        S<     0:00 [bioset]
   65 ?        S<     0:00 [bioset]
   66 ?        S<     0:00 [bioset]
   67 ?        S<     0:00 [bioset]
   68 ?        S<     0:00 [bioset]
   69 ?        S<     0:00 [bioset]
   70 ?        S<     0:00 [bioset]
   71 ?        S<     0:00 [bioset]
   72 ?        S<     0:00 [bioset]
   73 ?        S<     0:00 [bioset]
   74 ?        S<     0:00 [bioset]
   75 ?        S<     0:00 [bioset]
   76 ?        S<     0:00 [bioset]
   77 ?        S<     0:00 [iscsi_eh]
   78 ?        S<     0:00 [dwc_otg]
   80 ?        S<     0:00 [DWC Notificatio]
   81 ?        S<     0:00 [VCHIQ-0]
   82 ?        S<     0:00 [VCHIQr-0]
   83 ?        S<     0:00 [VCHIQs-0]
   84 ?        S      0:00 [VCHIQka-0]
   85 ?        S<     0:00 [SMIO]
   86 ?        S      0:00 [kworker/2:2]
   87 ?        S      0:00 [irq/92-mmc1]
   88 ?        S      0:00 [kworker/2:3]
   90 ?        S<     0:00 [bioset]
   91 ?        S      0:01 [mmcqd/0]
   93 ?        S      0:00 [jbd2/mmcblk0p2-]
   94 ?        S<     0:00 [ext4-rsv-conver]
   95 ?        S<     0:00 [ipv6_addrconf]
  111 ?        S<     0:00 [kworker/3:1H]
  113 ?        S      0:00 [kworker/u8:1]
  123 ?        S      0:00 [kworker/0:2]
  125 ?        Ss     0:00 /lib/systemd/systemd-journald
  145 ?        S      0:00 [kworker/3:2]
  152 ?        Ss     0:00 /lib/systemd/systemd-udevd
  158 ?        S      0:00 [kworker/1:2]
  243 ?        S<     0:00 [cfg80211]
  292 ?        Ssl    0:00 /lib/systemd/systemd-timesyncd
  314 ?        Ssl    0:00 /usr/sbin/rsyslogd -n
  315 ?        Ss     0:00 /lib/systemd/systemd-logind
  318 ?        Ss     0:00 /usr/sbin/thd --triggers /etc/triggerhappy/triggers.d/ --socket /run/thd.socket --user nobody --deviceglob /dev/input/event*
  319 ?        Ss     0:00 /usr/sbin/cron -f
  325 ?        Ss     0:00 /usr/bin/dbus-daemon --system --address=systemd: --nofork --nopidfile --systemd-activation
  352 ?        Ss     0:00 /sbin/dhcpcd -q -b
  367 ?        Ss     0:00 avahi-daemon: running [raspberrypi.local]
  377 ?        S      0:00 [kworker/1:3]
  381 ?        S      0:00 avahi-daemon: chroot helper
  406 ?        Ssl    0:00 /usr/sbin/lightdm
  407 ?        S<     0:00 [kworker/2:1H]
  416 tty1     Ss     0:00 /bin/login -f
  427 tty7     Ssl+   0:29 /usr/lib/xorg/Xorg :0 -seat seat0 -auth /var/run/lightdm/root/:0 -nolisten tcp vt7 -novtswitch
  432 ?        S<     0:00 [kworker/u9:0]
  434 ?        S<     0:00 [hci0]
  435 ?        S<     0:00 [hci0]
  436 ?        S      0:00 /usr/bin/hciattach /dev/serial1 bcm43xx 921600 noflow - b8:27:eb:a5:f6:a7
  437 ?        S<     0:00 [kworker/u9:1]
  442 ?        Ss     0:00 /usr/lib/bluetooth/bluetoothd
  443 ?        Ssl    0:00 /usr/bin/bluealsa
  460 ?        S<     0:00 [krfcommd]
  471 ?        Ss     0:00 /lib/systemd/systemd --user
  475 ?        S      0:00 (sd-pam)
  482 tty1     S+     0:00 -bash
  487 ?        S<     0:00 [kworker/1:1H]
  512 ?        Sl     0:00 lightdm --session-child 14 17
  521 ?        Ssl    0:00 /usr/bin/lxsession -s LXDE-pi -e LXDE
  530 ?        Ss     0:00 /usr/bin/dbus-daemon --session --address=systemd: --nofork --nopidfile --systemd-activation
  569 ?        Ss     0:00 /usr/bin/ssh-agent x-session-manager
  575 ?        Ssl    0:00 /usr/lib/gvfs/gvfsd
  580 ?        Sl     0:00 /usr/lib/gvfs/gvfsd-fuse /run/user/1000/gvfs -f -o big_writes
  596 ?        S      0:02 openbox --config-file /home/pi/.config/openbox/lxde-pi-rc.xml
  599 ?        Sl     0:00 lxpolkit
  601 ?        Sl     0:05 lxpanel --profile LXDE-pi
  603 ?        Sl     0:02 pcmanfm --desktop --profile LXDE-pi
  609 ?        Ss     0:00 /usr/bin/ssh-agent -s
  622 ?        Ssl    0:00 /usr/lib/policykit-1/polkitd --no-debug
  641 ?        Ssl    0:00 /usr/lib/menu-cache/menu-cached /run/user/1000/menu-cached-:0
  645 ?        Ssl    0:00 /usr/lib/gvfs/gvfs-udisks2-volume-monitor
  648 ?        Ssl    0:00 /usr/lib/udisks2/udisksd --no-debug
  655 ?        Ssl    0:00 /usr/lib/gvfs/gvfs-gphoto2-volume-monitor
  664 ?        Ssl    0:00 /usr/lib/gvfs/gvfs-mtp-volume-monitor
  668 ?        Ssl    0:00 /usr/lib/gvfs/gvfs-afc-volume-monitor
  673 ?        Ssl    0:00 /usr/lib/gvfs/gvfs-goa-volume-monitor
  710 ?        Sl     0:00 /usr/lib/gvfs/gvfsd-trash --spawner :1.4 /org/gtk/gvfs/exec_spaw/0
  719 ?        Rl     0:05 lxterminal
  722 ?        S      0:00 gnome-pty-helper
  723 pts/0    Ss+    0:00 bash
  731 pts/1    Ss     0:00 bash
  737 ?        Sl     2:10 /usr/lib/chromium-browser/chromium-browser --disable-quic --enable-fast-unload --enable-tcp-fast-open --disable-gpu-compositing --ppapi-flash-version=27.0.0.187 --enable-pinch --ppapi-flash-path=
  756 ?        S      0:00 /usr/lib/chromium-browser/chromium-browser --type=zygote --ppapi-flash-path=/usr/lib/chromium-browser/libpepflashplayer.so --ppapi-flash-version=27.0.0.187
  761 ?        S      0:00 /usr/lib/chromium-browser/chromium-browser --type=zygote --ppapi-flash-path=/usr/lib/chromium-browser/libpepflashplayer.so --ppapi-flash-version=27.0.0.187
  763 ?        S<     0:00 [kworker/0:1H]
 1010 ?        Sl     0:24 /usr/lib/chromium-browser/chromium-browser --type=renderer --disable-gpu-compositing --enable-pinch --field-trial-handle=1453185977128754946,6710767791505337750,131072 --service-pipe-token=28C67E
 1144 ?        Sl     0:01 /usr/lib/chromium-browser/chromium-browser --type=gpu-process --field-trial-handle=1453185977128754946,6710767791505337750,131072 --supports-dual-gpus=false --gpu-driver-bug-workarounds=7,8,10,24
 1164 ?        Sl     4:39 /usr/lib/chromium-browser/chromium-browser --type=renderer --disable-gpu-compositing --enable-pinch --field-trial-handle=1453185977128754946,6710767791505337750,131072 --service-pipe-token=66E2F0
 1654 ?        S      0:00 [kworker/0:1]
 1888 ?        Ssl    0:00 /usr/lib/packagekit/packagekitd
 2053 pts/2    Ss     0:00 bash
 2059 ?        S      0:00 [kworker/3:0]
 2069 ?        S      0:00 [kworker/u8:2]
 2073 ?        S      0:00 [kworker/0:0]
 2074 pts/1    S+     0:11 /usr/bin/python /usr/bin/pip install -e donkey[pi]
 2083 pts/1    S+     2:50 /usr/bin/python -c import setuptools, tokenize;__file__='/tmp/pip-build-bD8YGy/h5py/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compil
 2086 ?        S      0:00 [kworker/2:1]
 2177 ?        S      0:00 [kworker/0:3]
 2427 pts/1    S+     0:00 arm-linux-gnueabihf-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -Wdate-time -D_FORTIFY_SOURCE=2 -g -fdebug-prefix-map=/build/python2.7-kKRR4y/python2.7-2.7
 2428 pts/1    R+     0:08 /usr/lib/gcc/arm-linux-gnueabihf/6/cc1 -quiet -I /usr/include/python2.7 -imultilib . -imultiarch arm-linux-gnueabihf -D_REENTRANT -D NDEBUG -D _FORTIFY_SOURCE=2 /tmp/easy_install-FKRCyS/Cython-0.
 2429 pts/2    R+     0:00 ps -ax

どうしよう。再度ps

pi@raspberrypi:~ $ ps -ax

(中略)

2074 pts/1    S+     0:11 /usr/bin/python /usr/bin/pip install -e donkey[pi]
 2083 pts/1    S+     2:50 /usr/bin/python -c import setuptools, tokenize;__file__='/tmp/pip-build-bD8YGy/h5py/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compil
 2086 ?        S      0:00 [kworker/2:1]
 2177 ?        S      0:00 [kworker/0:3]
 2427 pts/1    S+     0:00 arm-linux-gnueabihf-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -Wdate-time -D_FORTIFY_SOURCE=2 -g -fdebug-prefix-map=/build/python2.7-kKRR4y/python2.7-2.7
 /usr/lib/gcc/arm-linux-gnueabihf/6/cc1 -quiet -I /usr/include/python2.7 -imultilib . -imultiarch arm-linux-gnueabihf -D_REENTRANT -D NDEBUG -D _FORTIFY_SOURCE=2 /tmp/easy_install-FKRCyS/Cython-0.28.5/Cython/Tempita/_tempita.c -quiet -dumpbase _tempit
 2624 pts/2    R+     0:00 ps -ax

状態は変わっている。しばらく様子見。

別のSDにエラーを保存

$ python manage.py drive &> py.error
$ ls /dev/sd*
/dev/sda  /dev/sdc1
$ mkdir data
$ sudo mount /dev/sdc1 ./data
$ cp py.error ./data

$ python manage.py drive
/usr/lib/python3/dist-packages/h5py/__init__.py:34: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
  from ._conv import register_converters as _register_converters
using donkey v2.5.1 ...
loading config file: /home/pi/mycar/config.py
config loaded
PiCamera loaded.. .warming camera
Starting Donkey Server...
Traceback (most recent call last):
  File "manage.py", line 190, in <module>
    drive(cfg, model_path = args['--model'], use_joystick=args['--js'], use_chaos=args['--chaos'])
  File "manage.py", line 103, in drive
    steering_controller = PCA9685(cfg.STEERING_CHANNEL)
  File "/home/pi/env/lib/python3.5/site-packages/donkeycar/parts/actuator.py", line 18, in __init__
    self.pwm = Adafruit_PCA9685.PCA9685()
  File "/home/pi/env/lib/python3.5/site-packages/Adafruit_PCA9685/PCA9685.py", line 75, in __init__
    self.set_all_pwm(0, 0)
  File "/home/pi/env/lib/python3.5/site-packages/Adafruit_PCA9685/PCA9685.py", line 111, in set_all_pwm
    self._device.write8(ALL_LED_ON_L, on & 0xFF)
  File "/home/pi/env/lib/python3.5/site-packages/Adafruit_GPIO/I2C.py", line 114, in write8
    self._bus.write_byte_data(self._address, register, value)
  File "/home/pi/env/lib/python3.5/site-packages/Adafruit_PureIO/smbus.py", line 256, in write_byte_data
    self._device.write(data)
OSError: [Errno 121] Remote I/O error
Installing with get-pip.py
To install pip, securely download get-pip.py. [1]:

$ curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
As when running any script downloaded from the web, ensure that you have reviewed the code and are happy that it works as you expect. Then run the following:

$ python get-pip.py

参考資料

DonkeyCar の製作(TAMIYA TT-02)
https://qiita.com/mituhiromatuura/items/c7da046d9b912d8249fc

DonkeyCar の製作(SunFounder Smart Video Car kit)
https://qiita.com/mituhiromatuura/items/9698b09d654ea8245cef

DonkeyCar の製作(Pololu Zumo)
https://qiita.com/mituhiromatuura/items/bd978b07c2b947c9d1fa

DonkeyCar の製作(RT ラズパイマウスV2)
https://qiita.com/mituhiromatuura/items/81616b97d46b8d072c0d

文書履歴

ver 0.10 初稿 20180912 朝
ver 0.11 松浦光洋さんのURL追記 昼
ver 0.12 松原和音さんの資料 追記 夕
ver 0.13 sudo apt-get update; apt-get install git 追記 20180913 朝
ver 0.14 細部追記 20180914

<この記事は個人の過去の経験に基づく個人の感想です。現在所属する組織、業務とは関係がありません。>

最後までおよみいただきありがとうございました。

いいね 💚、フォローをお願いします。

Thank you very much for reading to the last sentence.

Please press the like icon 💚 and follow me for your happy life.

9
10
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
9
10