LoginSignup
7
11

Ubuntuでも箱庭で機械学習するやつを動かそう

Last updated at Posted at 2023-04-20

こちらの記事の焼き直しですが,Ubuntu(Linux)での環境構築を整備したので,ついでに記事にしときます.

環境構築

UnityHubとBlenderをインストールします.

UnityHub

sudo sh -c 'echo "deb https://hub.unity3d.com/linux/repos/deb stable main" > /etc/apt/sources.list.d/unityhub.list'
wget -qO - https://hub.unity3d.com/linux/keys/public | sudo apt-key add -
sudo apt update
sudo apt-get install unityhub

blender

Blenderのページからhttps://www.blender.org/ Blenderをダウンロードしてきます.保存先は適当なフォルダで大丈夫です.以下x.x.xは適宜バージョンに読み替えてください.

tar xfv blender-x.x.x-linux-x64.tar.xz
sudo mv blender-x.x.x-linux-x64 /opt/
cp /opt/blender-x.x.x-linux-x64/blender.desktop 
sudo ln -s /opt/blender-x.x.x-linux-x64/blender /usr/local/bin/blender
~/.local/share/applications/
nano ~/.local/share/applications/blender.desktop
blender.desktop
Exec=/opt/blender-x-x-x-linux-x64/blender %f
Icon=/opt/blender-x.x.x-linux-x64/blender

setup

terminal A (hakoniwa-base)

git clone -b ai --recursive https://github.com/toppers/hakoniwa-base.git
cd hakoniwa-base
bash native/template/runtime/ai/linux/install.bash

terminal B (ros2sim)

git clone -b unity-asset --recursive https://github.com/toppers/hakoniwa-ros2sim.git
cd hakoniwa-ros2sim
bash docker/run.bash
---(on docker)---
bash hako-install.bash cpp

引き続きこれらのターミナルで作業するので閉じずに残しておきましょう.

Simulation

unity

UnityHubの画面からOpenボタンを押し,フォルダ選択からプロジェクトのフォルダの hakoniwa-ros2sim/unity/tb3 を選択します.初回はUnity Editor 2021.3.7f1のインストールを問われるので,そのまま従いインストールしましょう.

次にUnity Editor下部のProjectビューから,Assets/Scenes/Transportを選び「Shm_Configurator.unity」を開きます.その後メニューから「Window/Hakoniwa/Generate」を選択すると設定ファイルが生成されます.

terminal B

先ほどのTerminal Bで再度hakoniwa-install.bash cppを実行すると先ほど生成された設定ファイルを使っていろいろとええ感じに設定してくれます.

---(on docker)---
bash hako-install.bash cpp

terminal A

続いてterminal Aに戻り,箱庭のコア機能と制御プログラムを起動します.

bash native/template/runtime/ai/linux/run.bash

unity

制御プログラムが動いた状態でシミュレーションを開始します.順番を間違うと落ちるので注意です.
まずSceneをSimulation用のものに切り替えます.Projectのウィンドウから,Assets / Scenes / Transport / Simulation.unityを選択して開いてください.
続けて実行ボタン(▷)を押します.画面が実行モードに切り替わり[開始]ボタンとシミュレーション時間が表示されます.
[開始]ボタンを押すとシミュレーションが始まります.初期のうちは学習が進んでおらず,少し動いてはリセットを繰り返しますが,イテレーションが進むと徐々に賢くなってきます.

プログラムの編集

制御プログラムは hakonwa-base/workspace/dev/ai/ai_qtable.pyがエントリになっています.
そこまで長いプログラムでもないので,ぜひ改造して遊んでみてください!

7
11
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
7
11