平たく言うと、前回のつづきです。
今回は、実際に箱庭ドローンの MCP サーバーをインストールしてGemini CLIでドローンを飛ばしてみましょ!っていう記事です。
どういうメリットあるか
まー、これくらい?
- AIにドローンを操作させる体験ができる
→ Gemini CLI 経由して、自然言語でドローンを飛ばせる - WSL2 上で完結するので手元のPCで試せる
→ Ubuntu 24.04 環境なら追加のハード不要
準備するもの
こんだけです。不足するものは事前インストールをお願いします。
- ゲーミングPC (RTX3060クラス~)
- Windows 11
- WSL2/Ubuntu24.04.2 LTS(22は動きません)
- Gemini CLI
セットアップの流れ
基本的には、インストーラを用意していますので、細かな作業はいりません。
が、中で何やっているか気になると思いますので、書いておきます。
- pyenv + Python3.12.3 のインストール
- バージョンは固定してます(pythonのバージョン地獄いやなもので)
- Hakoniwa パッケージの導入
- APT レポジトリ追加、hakoniwa-core-full インストール
- 箱庭ドローン実行バイナリ(lnx.zip)
- 箱庭ドローンUnityアプリ(WebAvatar.zip)
- hakoniwa-pdu / 追加Pythonライブラリの導入
- pip install hakoniwa-pdu scipy aiohttp aiohttp_cors websockets
- Gemini CLI の設定 (settings.json)
- mcpServers に hakoniwa_drone を追加
最初の一歩
箱庭のリポジトリをクローンします。
場所は、WSL2/Ubuntuのホームディレクトリにhakoniwa
ディレクトリを作ります。
cd
mkdir hakoniwa
cd hakoniwa
あとは、クローン。
箱庭ドローンシミュレータ本体:
git clone --recursive https://github.com/toppers/hakoniwa-drone-core.git
箱庭Webサーバー:
git clone --recursive https://github.com/toppers/hakoniwa-webserver.git
インストール開始!
インストーラをコマンドでたたくだけです。5分くらいかかりますかね。
cd hakoniwa-drone-core
bash install-drone-ubuntu.bash
成功すると、こんなログがでます。
Gemini設定ファイルの編集
Geminiの設定ファイルは、~/.gemini/settings.json
にあります。
ここに、追加すべき設定内容をいかに格納していますので、追加してください。
cat config/launcher/gemini-mcpserver.json
"mcpServers": {
"hakoniwa_drone": {
"command": "/home/tmori/.pyenv/shims/python",
"args": [
"-m",
"hakoniwa_pdu.apps.mcp.server"
],
"env": {
"PDU_CONFIG_PATH": "/home/tmori/hakoniwa/hakoniwa-drone-core/config/pdudef/webavatar.json",
"SERVICE_CONFIG_PATH": "/home/tmori/hakoniwa/hakoniwa-drone-core/config/launcher/drone_service.json",
"HAKO_BINARY_PATH": "/usr/share/hakoniwa/offset"
}
}
}
マージ後:
cat ~/.gemini/settings.json
{
"selectedAuthType": "oauth-personal",
"hasSeenIdeIntegrationNudge": true,
"ideMode": true,
"mcpServers": {
"hakoniwa_drone": {
"command": "/home/tmori/.pyenv/shims/python",
"args": [
"-m",
"hakoniwa_pdu.apps.mcp.server"
],
"env": {
"PDU_CONFIG_PATH": "/home/tmori/qiita/hakoniwa-drone-core/config/pdudef/webavatar.json",
"SERVICE_CONFIG_PATH": "/home/tmori/qiita/hakoniwa-drone-core/config/launcher/drone_service.json",
"HAKO_BINARY_PATH": "/usr/share/hakoniwa/offset"
}
}
}
}
実行のながれ
前提として、hakoniwa-drone-core
ディレクトリで作業します。
そして、 オペレーションの流れは、以下の2つだけです。
- 端末Aで、RPCサーバーを起動する
- 端末Bで、Gemini CLIを起動する
端末Aで、RPCサーバーを起動する
RPCサーバーの起動:
bash launch.bash config/launcher/drone-api-ubuntu.launch.json
起動ログ:
/usr/share/hakoniwa/offset
2025-08-31 17:06:58,200 - root - INFO - Starting HakoDroneRpcServer...
2025-08-31 17:06:58,200 - root - INFO - HakoDroneRpcServer initialized
2025-08-31 17:06:58,201 - root - INFO - HakoRPCServer ready. assets:
2025-08-31 17:06:58,201 - root - INFO - - drone (cwd=/home/tmori/hakoniwa/hakoniwa-drone-core, cmd=lnx/linux-main_hako_drone_service, args=['config/drone/api', 'config/pdudef/webavatar.json'])
2025-08-31 17:06:58,201 - root - INFO - - environment (cwd=/home/tmori/hakoniwa/hakoniwa-drone-core/drone_api, cmd=python, args=['-m', 'hako_env_event', '../config/pdudef/webavatar.json', '20', 'assets/config'])
2025-08-31 17:06:58,201 - root - INFO - - webserver (cwd=/home/tmori/hakoniwa/hakoniwa-drone-core/../hakoniwa-webserver, cmd=python, args=['-m', 'server.main', '--asset_name', 'WebServer', '--config_path', '/home/tmori/hakoniwa/hakoniwa-drone-core/config/pdudef/webavatar.json', '--delta_time_usec', '20000'])
2025-08-31 17:06:58,201 - root - INFO - - Unity (cwd=/home/tmori/hakoniwa/hakoniwa-drone-core/WebAvatar, cmd=simulation.exe, args=[])
2025-08-31 17:06:58,201 - root - INFO - Service 'Service/SystemControl' with handler '_system_control_handler' added.
2025-08-31 17:06:58,201 - root - INFO - HakoDroneService initialized
Registering drone service: DroneService/DroneSetReady srv_type: DroneSetReady with handler _set_ready_handler
2025-08-31 17:06:58,201 - root - INFO - Service 'DroneService/DroneSetReady' with handler '_set_ready_handler' added.
Registering drone service: DroneService/DroneTakeOff srv_type: DroneTakeOff with handler _takeoff_handler
2025-08-31 17:06:58,202 - root - INFO - Service 'DroneService/DroneTakeOff' with handler '_takeoff_handler' added.
Registering drone service: DroneService/DroneGoTo srv_type: DroneGoTo with handler _go_to_handler
2025-08-31 17:06:58,202 - root - INFO - Service 'DroneService/DroneGoTo' with handler '_go_to_handler' added.
Registering drone service: DroneService/DroneGetState srv_type: DroneGetState with handler _get_state_handler
2025-08-31 17:06:58,202 - root - INFO - Service 'DroneService/DroneGetState' with handler '_get_state_handler' added.
Registering drone service: DroneService/DroneLand srv_type: DroneLand with handler _land_handler
2025-08-31 17:06:58,202 - root - INFO - Service 'DroneService/DroneLand' with handler '_land_handler' added.
Registering drone service: DroneService/CameraCaptureImage srv_type: CameraCaptureImage with handler _capture_image_handler
2025-08-31 17:06:58,202 - root - INFO - Service 'DroneService/CameraCaptureImage' with handler '_capture_image_handler' added.
Registering drone service: DroneService/CameraSetTilt srv_type: CameraSetTilt with handler _set_tilt_handler
2025-08-31 17:06:58,202 - root - INFO - Service 'DroneService/CameraSetTilt' with handler '_set_tilt_handler' added.
Registering drone service: DroneService/LiDARScan srv_type: LiDARScan with handler _scan_lidar_handler
2025-08-31 17:06:58,202 - root - INFO - Service 'DroneService/LiDARScan' with handler '_scan_lidar_handler' added.
Registering drone service: DroneService/MagnetGrab srv_type: MagnetGrab with handler _grab_magnet_handler
2025-08-31 17:06:58,202 - root - INFO - Service 'DroneService/MagnetGrab' with handler '_grab_magnet_handler' added.
2025-08-31 17:06:58,202 - hakoniwa_pdu.impl.websocket_base_communication_service - INFO - WebSocketBaseCommunicationService created with version: v2
[INFO] PduManager created with wire version: v2
[INFO] PduManager initialized
No changes made.
2025-08-31 17:06:58,230 - hakoniwa_pdu.rpc.remote.remote_pdu_service_server_manager - INFO - Service PDU definitions prepared.
2025-08-31 17:06:58,236 - websockets.server - INFO - server listening on 127.0.0.1:8080
2025-08-31 17:06:58,236 - hakoniwa_pdu.impl.websocket_server_communication_service - INFO - WebSocket server started at localhost:8080
[INFO] Service started successfully at ws://localhost:8080
2025-08-31 17:06:58,236 - root - INFO - RPC Server started at ws://localhost:8080 with 10 services.
端末Bで、Gemini CLIを起動する
Gemini CLIの起動:
gemini
RPCサーバー側で、以下のログがでます。
2025-08-31 17:08:21,108 - websockets.server - INFO - connection open
2025-08-31 17:08:21,111 - hakoniwa_pdu.rpc.remote.remote_pdu_service_server_manager - INFO - Register RPC client: DroneService/DroneSetReady, channel_id=-1
2025-08-31 17:08:21,164 - hakoniwa_pdu.rpc.remote.remote_pdu_service_server_manager - INFO - Register RPC client: DroneService/DroneTakeOff, channel_id=-1
2025-08-31 17:08:21,217 - hakoniwa_pdu.rpc.remote.remote_pdu_service_server_manager - INFO - Register RPC client: DroneService/DroneGoTo, channel_id=-1
2025-08-31 17:08:21,271 - hakoniwa_pdu.rpc.remote.remote_pdu_service_server_manager - INFO - Register RPC client: DroneService/DroneGetState, channel_id=-1
2025-08-31 17:08:21,324 - hakoniwa_pdu.rpc.remote.remote_pdu_service_server_manager - INFO - Register RPC client: DroneService/DroneLand, channel_id=-1
2025-08-31 17:08:21,378 - hakoniwa_pdu.rpc.remote.remote_pdu_service_server_manager - INFO - Register RPC client: DroneService/CameraCaptureImage, channel_id=-1
2025-08-31 17:08:21,431 - hakoniwa_pdu.rpc.remote.remote_pdu_service_server_manager - INFO - Register RPC client: DroneService/CameraSetTilt, channel_id=-1
2025-08-31 17:08:21,484 - hakoniwa_pdu.rpc.remote.remote_pdu_service_server_manager - INFO - Register RPC client: DroneService/LiDARScan, channel_id=-1
2025-08-31 17:08:21,538 - hakoniwa_pdu.rpc.remote.remote_pdu_service_server_manager - INFO - Register RPC client: DroneService/MagnetGrab, channel_id=-1
2025-08-31 17:08:21,591 - hakoniwa_pdu.rpc.remote.remote_pdu_service_server_manager - INFO - Register RPC client: Service/SystemControl, channel_id=-1
Geminiに箱庭ドローンシミュレータでできることを聞いてみる
質問:
could you list up hakoniwa drone functtions?
回答:
✦ Of course. Here are the functions available for controlling the Hakoniwa drone:
Simulator Control:
* hakoniwa_simulator_activate: Activate the Hakoniwa Drone.
* hakoniwa_simulator_start: Start the Hakoniwa Drone.
* hakoniwa_simulator_terminate: Terminate the Hakoniwa Drone.
Drone Control:
* drone_set_ready: Prepare the drone for a mission.
* drone_takeoff: Command the drone to take off to a specific height.
* drone_land: Command the drone to land.
* drone_get_state: Get the drone's current state (position, orientation, etc.).
* drone_go_to: Move the drone to a specified position.
Sensors:
* camera_capture_image: Capture an image from the drone's camera.
* camera_set_tilt: Set the tilt angle of the drone's camera.
* lidar_scan: Perform a LiDAR scan to get point cloud data.
Actuators:
* magnet_grab: Control the drone's magnet to grab or release objects.
さらに、
日本語で解説して
とお願いすると、
✦ はい、承知いたしました。Hakoniwaドローンで利用可能な機能の一覧を日本語で解説します。
シミュレータ制御:
* hakoniwa_simulator_activate: Hakoniwaドローンを有効化します。
* hakoniwa_simulator_start: Hakoniwaドローンを開始します。
* hakoniwa_simulator_terminate: Hakoniwaドローンを終了します。
ドローン制御:
* drone_set_ready: ドローンをミッションのために準備します。
* drone_takeoff: 指定した高度へ離陸するよう命令します。
* drone_land: 着陸するよう命令します。
* drone_get_state: ドローンの現在の状態(位置、姿勢など)を取得します。
* drone_go_to: 指定した位置へドローンを移動させます。
センサー:
* camera_capture_image: ドローンのカメラから画像を撮影します。
* camera_set_tilt: ドローンのカメラのチルト角度を設定します。
* lidar_scan: LiDARスキャンを実行し、点群データを取得します。
アクチュエータ:
* magnet_grab: ドローンの電磁石を制御し、オブジェクトを掴んだり離したりします。
シミュレーションを開始しよう!
activate the drone simulator
で、そのまま、
start simulation
とすると、Unityアプリが起動します。ちょっと時間かかるけど(30秒くらい)。
あと、途中で、起動確認のダイアログがでますが、OKしてください。
で、こんな感じで、GeminiとUnityアプリがお目見えします!
あとは、お好きにAIに指示するだけ。
ちょっとやってみましょう。
👉 実際に Gemini CLI からドローンを飛ばしてみた様子です。
ちなみに、所感として、英語で指示するほうがちゃんと動いてくれるような気がしましたので、重要なところは英語で指示してます。
さいごに
これで一通りの説明は終了ですが、自分の環境でしかテストしとりませんので、うまく動かないケースもあるかもしれません。
そのために、じつは、テスト用のmcpサーバーも作って動作チェックできるようにしてますが、今日はこへんで。
さよなら。