7
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

DonkeyCarをUnity上で走らせる

Posted at

はじめに

DonkeyCarを作っても広い場所で走らせれないし、場所があっても行くのが面倒なので
Unity上に好きなコースを作って走らせれるようにしました。
備忘録として残します。

環境構築方法を決める

基本的な考え方は、UnityとDonkeyCar(python)間の通信としてROS2を採用します。
幾つかパターンを考えましたが、Ubuntu上でUnityを動かすことで落ち着きました。
(UbuntuでUnityが普通に動くの知らなかったです。)

1:WindowsでUnity WLS2でUbuntuしてDonkeyCar USB△ GPU△
2:WindowsでUnity VirtualBoxでUbuntuしてDonkeyCar USB○ GPU☓
3:UbuntuでUnity UbuntuでDonkeyCar USB○ GPU○

結局3が一番かんたんでした。

Ubuntu環境の準備

今回は、Ubuntu 22.04 で行いました。
https://jp.ubuntu.com/download

Unityのインストール

以下を参考にしてUnityをインストール
https://unity3d.com/jp/get-unity/download

AppImage 実行できない場合の対処方法

https://gamingsym.in/jp/ubuntu-22-04%E3%81%A7appimage%E3%82%92%E5%AE%9F%E8%A1%8C%E3%81%A7%E3%81%8D%E3%81%BE%E3%81%9B%E3%82%93%E3%81%8B%EF%BC%9F-%E3%81%93%E3%82%8C%E3%82%92%E4%BF%AE%E6%AD%A3%E3%81%99%E3%82%8B%E6%96%B9/
https://qiita.com/YuukiToriyama/items/d4840dc31bdae65e8294
https://terminalroot.com/how-to-install-unity-engine-on-ubuntu-via-appimage/

エラーが出る「No usable version of libssl was found」

以下を参考にして対応
https://forum.unity.com/threads/workaround-for-libssl-issue-on-ubuntu-22-04.1271405/

 [1]install
 以下のURLからlibssl1.0.0_1.0.2n-1ubuntu5.8_amd64.debをダウンロード
 http://security.ubuntu.com/ubuntu/pool/main/o/openssl1.0/
 [2]install
 sudo apt install libssl-dev

DonkeyCarのインストール

以下を参考にしてDonkeycarをインストール
https://docs.donkeycar.com/guide/host_pc/setup_ubuntu/
後のことを考えてPythonは、3.10.0がいい(3.7.0でやるとrclpyが使えませんでした。)
ubuntu.ymlのpythonのバージョンを変えておく 3.7→3.10

ROS2のインストール

以下を参考にしてROS2をインストールする
https://qiita.com/porizou1/items/5dd915402e2990e4d95f

Unity-Robotics-Hubの導入

https://github.com/Unity-Technologies/Unity-Robotics-Hub
ダウンロードしたらどこかに置いておく

ROS-TCP-Connectorの導入

Package Managerのgit URLに以下を追加
https://github.com/Unity-Technologies/ROS-TCP-Connector.git?path=/com.unity.robotics.ros-tcp-connector

インストール後にすること
RoboticsSettingsでROS2を選択
RosMessageBrowserでUnity-Robotics-Hubにあるメッセージ型をビルド

ROS-TCP-Endpointの導入

以下をwsでクローンする
https://github.com/Unity-Technologies/ROS-TCP-Endpoint.git
git checkout ROS2v0.7.0 してからビルドする

ROS-Unity疎通確認

以下を参考にして「ROS–Unity Integration: Publisher」をトライする
https://github.com/Unity-Technologies/Unity-Robotics-Hub/blob/main/tutorials/ros_unity_integration/publisher.md
→エラー出てしまって出来なかったので、何でも良いのでパブリッシュしてみます。

以下のコマンドで実行します。
ros2 run ros_tcp_endpoint default_server_endpoint --ros-args -p ROS_IP:=127.0.0.1

Rviz2で画像を表示

圧縮画像を確認するために、image-transportパッケージの追加
sudo apt install ros-humble-image-transport-plugins

圧縮画像をRawデータに変換してあげる
ros2 run image_transport republish compressed --ros-args -r in/compressed:=image/compressed -r out:=image_raw

nvidia driverのinstall

https://codechacha.com/ja/install-nvidia-driver-ubuntu/
以下を参考にしてドライバをインストール
https://qiita.com/porizou1/items/74d8264d6381ee2941bd

TensorFlowをインストールする

→GPUは、使える設定で入れれませんでした。
PytorchがGPU使えてるのでそちらで乗り切ってます。
あとで対応します。

書き残し

・DonkeyCarのROS2用のスクリプト
 https://github.com/taigamaru/donkeycar/tree/feature/add-ros2-and-pytorch
 (この中からros2.py manage.pyぐらいを参考にする。)

・Unityのカメラ映像を送るスクリプト
 https://github.com/Field-Robotics-Japan/UnitySensorsROSAssets
 以下をカメラにアタッチすることで映像をパブリッシュします。
  RGBCamera.cs
  RGBCameraPublisher.cs

トラブルシュート

rclpyのimportでエラーが出る。

エラー:version `GLIBCXX_3.4.30' のエラーが出る

解決策
conda install -c conda-forge gcc=12.1.0

7
4
1

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
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?