1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

ここでは、Windows11で、Sony toio を活用し、PhysicalAIを目指したロボットシミュレーションの検証結果を報告します。

最近では PhysicalAIが注目されており、自分もロボットシミュレーションを試したいと思いました。ここでは、Windows11で、Sony製ロボット「toio:トイオ」を活用する手順を記録しておきます。

まず、この記事はtoioの単体動作検証の、以下の手順の続きです。

特に、PCプログラミングで活用する情報は、以下のウエブ「トイオラボ」が基本です。

ここでは、テキストプログラミングとして、Pythonライブラリ「toio.py」を用いたプログラミングを検証します。

この手順は、ウエブ資料「【toio】Python(パイソン)ライブラリの導入~使用方法まで徹底解説!」を参考にしました。
https://www.kanirobo.tech/toio-py/

PC環境の準備

コマンド入力のPowerShell

ここでは、Pythonのコマンド入力は、PowerShellを用いるので、Microsoft Storeで、最新版「7.6.4」を導入しておきます。

プログラミングのPython

以下の「toio.py」の解説を確認します。
https://github.com/toio/toio.py/blob/main/README.ja.md

以下の記述があるので、ここでは「Python 3.12」を利用することにします。
【Python 3.8 以降のバージョンをサポート (Python 3.12 の使用を推奨)】

以下のPythonのダウンロードサイトに接続します。
https://www.python.org/downloads/windows/

たくさんあるバージョンのなかで、「Python 3.12.10 - April 8, 2025」の項目で、「Download Windows installer (64-bit)」から入手します。

ダウンロードフォルダに、インストール用ファイル「python-3.12.10-amd64.exe」が保存されます。
このファイルをダブルクリックして、インストーラーが起動したら、「Add python.exe to PATH」にチェックを入れてPowerShellから使えるようにします。
「→ Install Now」で、インストールが進みます。
導入が成功したら、「Close」で終了します。
PowerShellを起動して、以下のように確認します。

PowerShell 7.6.4
PS C:\Windows\System32> python
Python 3.12.10 (tags/v3.12.10:0cc8128, Apr  8 2025, 12:21:36) [MSC v.1943 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()

プログラミング環境のVisual Studio Code

Microsoft Storeから、Visual Studio Codeを導入します。公開されている最新版で良いです。起動したら、Python 機能拡張を入れて、Jupyter 機能拡張をインストールします。

toio.pyの導入

以下のtoio.pyの解説ページを参考にして、セットアップを進めます。
https://github.com/toio/toio.py/blob/main/SETUP_GUIDE.ja.md

手順に従って、「setuptools・typing-extensions・bleak・toio.py・ipykernel」
を、pythonのpip機能で導入してゆきます。

python -m pip install setuptools --upgrade
python -m pip install typing-extensions
python -m pip install bleak=0.22.1
python -m pip install toio-py --upgrade
python -m pip install ipykernel

この中で「toio.pyセットアップガイド」から異なる部分があり、「bleak==0.22.1」のところです。自分の環境で、Python 3.12でガイドの手順で準備したところ、エラーでtoioが動作しませんでした。
そこで、bleakのバージョンをpip showで確認すると3.0.2でしたが、toioが想定しているbleakのバージョン0.21.1を指定するため、このような設定としました。

PowerShellで、以下のコマンド実行により、導入を確認します。

PS C:\Users\ryos> python -c "import toio.scanner; print('ok')"
ok

「ok」と表示が出れば toio.py のインストールは成功です。

toio.pyによる制御

ここでは、「C:\SonyToio\PythonWork」フォルダを作って、この中にプログラムを保存することにします。

Visual Studio Codeを起動して、以下のプログラムを、ファイル名「moter-ex1.py」として作成し、「C:\SonyToio\PythonWork」フォルダに保存します。

moter-ex1.py
import sys

from toio.simple import SimpleCube

def test():
    with SimpleCube() as cube:
        cube.move(30, 3)
        cube.spin(60, 2)
        cube.run_motor(70, 10, 1)
        cube.run_motor(10, 70, 1)
        cube.run_motor(-20, -20, 0)
        cube.sleep(0.5)
        cube.stop_motor()

if __name__ == "__main__":
    sys.exit(test())

準備ができたので、PCのBluetooth機能をONに設定し、toioキューブの電源を入れておきます。
プログラムの実行は、PowerShellで、「C:\SonyToio\PythonWork」フォルダに移動します。
以下のように、Pythonで実行します。

PS C:\Users\ryos> cd C:\SonyToio\PythonWork\
PS C:\SonyToio\PythonWork> dir
-a---          2026/08/07    17:16            339 moter-ex1.py

PS C:\SonyToio\PythonWork> python .\moter-ex1.py

プログラムを実行すると、音が鳴って前進し、くるくる回転してから、停止して音が鳴って、プログラムが終了します。

これで、PCからPythonを使って、toioを制御することができました!

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?