M3D-EL-FP-USB Python Library
M3D-EL-FP-USB(6分力フォースプレート+9軸モーションセンサ)用のPythonライブラリです。
FTDI USB経由でのデバイス接続・通信
測定データの収集(1〜1000Hz、まとめ数1〜25)
ゼロ調整
校正パラメータの取得・保存・読み込み
AD値から工学値への変換
6分力(Fx, Fy, Fz, Mx, My, Mz)
COP(Center of Pressure)
加速度(3軸)
ジャイロ(3軸、±2000deg/s固定)
地磁気(3軸)
Python 3.8以上
FTDI D2XXドライバ(FTDIの公式サイトからダウンロード)
FTDI D2XXドライバをインストール
Pythonパッケージのインストール
pip install -r requirements.txt
ファイル
説明
m3d_el_fp_usb.py
メインデバイス制御クラス
ftdi_comm.py
FTDI USB通信モジュール
packet_parser.py
パケット解析・工学値変換
test_initial_connect.py
初回接続テスト(校正パラメータ取得・保存)
test_zero.py
ゼロ調整テスト
test_measure.py
測定テスト(リアルタイム表示)
test_multi_measure.py
複数台同時測定テスト
test_ext_trig.py
外部トリガテスト(トリガ出力)
test_ext_trig_wait.py
外部トリガテスト(トリガ受信待ち)
test_timing_stats.py
データ取得タイミング統計テスト
from m3d_el_fp_usb import M3dElFpUsb
device = M3dElFpUsb ()
# シリアル番号で接続
if device .connect_by_serial ("M3D-FP2U9-006" ):
# 校正パラメータ取得
device .get_calibration_parameters ()
# JSONに保存
device .save_calibration_parameters ("." )
device .disconnect ()
import time
from m3d_el_fp_usb import M3dElFpUsb , AccelRange
device = M3dElFpUsb ()
# シリアル番号で接続
if device .connect_by_serial ("M3D-FP2U9-006" ):
# 校正パラメータ読み込み
device .load_calibration_parameters ("M3D-FP2U9-006.json" )
# ゼロ調整
device .zero ()
# 測定条件設定
device .set_frequency (1000 )
device .set_matome (1 )
device .set_acc_range (AccelRange .G16 )
# 測定開始
device .start ()
# データ取得・工学値変換
while measuring :
if device .data_count > 0 :
ad_data = device .get_data ()
eng_data = device .ad_to_eng (ad_data , is_left = False )
# eng_dataを処理...
time .sleep (0.0001 ) # GIL競合回避
# 測定停止
device .stop ()
device .disconnect ()
from m3d_el_fp_usb import M3dElFpUsb
device = M3dElFpUsb ()
devices = device .list_devices ()
for dev in devices :
print (f"Index: { dev ['index' ]} , Serial: { dev ['serial' ]} " )
import time
from m3d_el_fp_usb import M3dElFpUsb , AccelRange
# 各デバイスのインスタンスを作成
device_r = M3dElFpUsb () # 右足
device_l = M3dElFpUsb () # 左足
# シリアル番号で接続
device_r .connect_by_serial ("M3D-FP2U9-001" )
device_l .connect_by_serial ("M3D-FP2U9-002" )
# 校正パラメータ読み込み
device_r .load_calibration_parameters ("M3D-FP2U9-001.json" )
device_l .load_calibration_parameters ("M3D-FP2U9-002.json" )
# ゼロ調整
device_r .zero ()
device_l .zero ()
# 測定条件設定
device_r .set_frequency (1000 )
device_r .set_matome (1 )
device_r .set_acc_range (AccelRange .G16 )
device_l .set_frequency (1000 )
device_l .set_matome (1 )
device_l .set_acc_range (AccelRange .G16 )
# 測定開始
device_r .start ()
device_l .start ()
# データ取得
while measuring :
if device_r .data_count > 0 :
ad_r = device_r .get_data ()
eng_r = device_r .ad_to_eng (ad_r , is_left = False )
if device_l .data_count > 0 :
ad_l = device_l .get_data ()
eng_l = device_l .ad_to_eng (ad_l , is_left = True )
time .sleep (0.0001 ) # GIL競合回避
# 測定停止・切断
device_r .stop ()
device_l .stop ()
device_r .disconnect ()
device_l .disconnect ()
import time
from m3d_el_fp_usb import M3dElFpUsb , AccelRange
# 各デバイスのインスタンスを作成
device_r = M3dElFpUsb () # 右足(マスター)
device_l = M3dElFpUsb () # 左足(スレーブ)
# シリアル番号で接続
device_r .connect_by_serial ("M3D-FP2U9-001" )
device_l .connect_by_serial ("M3D-FP2U9-002" )
# 校正パラメータ読み込み・ゼロ調整・測定条件設定...
# 外部トリガ待ち状態に移行
device_r .ext () # マスター
device_l .ext () # スレーブ
device_l .start_receive () # スレーブは先に受信スレッド開始
# トリガ信号を出力(測定開始)
# ※マスターにのみ発行(マスターがトリガ出力し、スレーブはトリガ受信)
device_r .trig ()
# データ取得
while measuring :
if device_r .data_count > 0 :
ad_r = device_r .get_data ()
eng_r = device_r .ad_to_eng (ad_r , is_left = False )
if device_l .data_count > 0 :
ad_l = device_l .get_data ()
eng_l = device_l .ad_to_eng (ad_l , is_left = True )
time .sleep (0.0001 ) # GIL競合回避
# 測定停止・切断
device_r .stop ()
device_l .stop ()
device_r .disconnect ()
device_l .disconnect ()
# 外部トリガ待ち状態に移行
device_r .ext ()
device_r .start_receive () # 受信スレッド開始
device_l .ext ()
device_l .start_receive () # 受信スレッド開始
# trig()は使用せず、外部からのトリガ信号を待つ
# トリガ受信後、自動的に測定開始
# データ取得
while measuring :
if device_r .data_count > 0 :
ad_r = device_r .get_data ()
eng_r = device_r .ad_to_eng (ad_r , is_left = False )
if device_l .data_count > 0 :
ad_l = device_l .get_data ()
eng_l = device_l .ad_to_eng (ad_l , is_left = True )
time .sleep (0.0001 ) # GIL競合回避
# 測定停止・切断
device_r .stop ()
device_l .stop ()
device_r .disconnect ()
device_l .disconnect ()
チャンネル
説明
単位
ACC_X/Y/Z
加速度
G
GYRO_X/Y/Z
角速度
deg/s
MAG_X/Y/Z
地磁気
uT
FX/FY/FZ
6分力の力成分
N
MX/MY/MZ
6分力のモーメント成分
N*m
MXD/MYD
座標変換後モーメント
N*m
COP_X/COP_Y
圧力中心
mm
レンジ
値
G2
±2G
G4
±4G
G8
±8G
G16
±16G
設定変更はIDLE状態でのみ可能
ゼロ調整は測定前に毎回実行してください
左足装着時は ad_to_eng(ad_data, is_left=True) を指定
測定ループには time.sleep(0.0001) を入れてください (GIL競合回避のため)
プロパティ
型
説明
status
DeviceStatus
デバイスの状態
info
DeviceInfo
デバイス情報(シリアル番号等)
calibration
CalibrationParams
校正パラメータ
data_count
int
バッファ内のデータ数
is_connected
bool
接続状態
値
説明
NO_DEVICE
未接続
INITIALIZE
初期化中
IDLE
待機中
EXT
外部トリガ待ち受け中
MEASURE
測定中
ZERO
ゼロ調整中
ERROR
エラー発生
メソッド
引数
戻り値
説明
list_devices()
なし
List[dict]
接続可能なデバイス一覧を取得
connect(device_index)
int
bool
インデックスで接続
connect_by_serial(serial)
str
bool
シリアル番号で接続
disconnect()
なし
なし
切断
メソッド
引数
戻り値
説明
start()
なし
bool
測定開始
stop()
なし
bool
測定停止
ext()
なし
bool
外部トリガ待ち状態に移行
trig()
なし
bool
トリガ信号出力(マスターデバイス用)
start_receive()
なし
bool
受信スレッド開始(スレーブデバイス用)
stop_receive()
なし
なし
受信スレッド停止
zero()
なし
bool
ゼロ調整(5秒タイムアウト)
メソッド
引数
戻り値
説明
get_data(count)
int(デフォルト1)
np.ndarray
AD値を取得
get_data_with_time(count)
int(デフォルト1)
tuple(np.ndarray, float)
AD値と受信時刻を取得
ad_to_eng(ad_values, is_left)
np.ndarray, bool
np.ndarray
AD値を工学値に変換
メソッド
引数
戻り値
説明
set_frequency(frequency)
int(1〜1000)
bool
サンプリング周波数設定
set_matome(matome)
int(1〜25)
bool
まとめ数設定
set_acc_range(range_val)
AccelRange
bool
加速度レンジ設定
メソッド
引数
戻り値
説明
get_device_status()
なし
DeviceStatus
デバイスステータス取得
get_calibration_parameters()
なし
bool
校正パラメータをデバイスから取得
save_calibration_parameters(directory)
str
bool
校正パラメータをJSONに保存
load_calibration_parameters(filepath)
str
bool
校正パラメータをJSONから読み込み
MIT License - 株式会社テック技販