Python driver for PAMC-204 / PAMC-204-RJ Piezo Assist Motor Controller
Project description
pypamc_204
PAMC-204 / PAMC-204-RJ ピエゾアシストモーターコントローラ用 Python ライブラリ
インストール
pip install pypamc_204
開発版(ローカルインストール):
cd pypamc-204
pip install -e .
必要環境
- Python 3.9+
- pyserial
開発環境のセットアップ
1. リポジトリをクローン
git clone https://github.com/mechano-transformer/PAMC-204.git
cd pypamc-204
2. 仮想環境(venv)を作成・有効化
Windows:
python -m venv .venv
.venv\Scripts\activate
macOS / Linux:
python3 -m venv .venv
source .venv/bin/activate
3. 開発用依存パッケージと共にインストール
pip install -e ".[dev]"
これで pypamc204 本体 + pytest がインストールされます。
4. ユニットテストの実行
pytest
詳細出力で実行する場合:
pytest -v
特定のテストクラスだけ実行する場合:
pytest tests/test_controller.py::TestRotation -v
5. 仮想環境の終了
deactivate
クイックスタート
from pypamc204 import PAMC204
# コントローラに接続(アドレス1がデフォルト)
with PAMC204("COM3") as ctrl:
# ファームウェアバージョン確認
print(ctrl.get_firmware_info())
# 出力電圧を100Vに設定
ctrl.set_voltage(100)
# CH1を正回転(500Hz, 1000パルス)
ctrl.rotate_forward(channel=1, frequency=500, pulses=1000)
# CH2を逆回転(連続駆動)
ctrl.rotate_reverse(channel=2, frequency=300)
# 停止
ctrl.stop()
使い方
接続
from pypamc204 import PAMC204
# context manager(推奨)
with PAMC204("COM3", address=1) as ctrl:
...
# 手動で接続管理
ctrl = PAMC204("COM3")
ctrl.open()
# ... 操作 ...
ctrl.close()
ドライバの検出
with PAMC204("COM3") as ctrl:
# 特定アドレスにドライバが存在するか確認
if ctrl.ping(1):
print("E01 is connected")
# 全アドレス (1–32) をスキャン
found = ctrl.scan_addresses()
print(f"Found drivers: {found}")
アドレス変更
# ※単一ドライバ接続時のみ実行すること
with PAMC204("COM3") as ctrl:
ctrl.set_address(5) # アドレスを E05 に変更
出力電圧の調整
with PAMC204("COM3") as ctrl:
# 70, 80, 90, 100, 110, 120, 130, 140, 150V から選択
ctrl.set_voltage(120)
# DAC値を直接指定(1900–4095)
ctrl.set_voltage_raw(3000)
モーター駆動(正回転 / 逆回転)
with PAMC204("COM3") as ctrl:
# 正回転: CH1, 1000Hz, 5000パルス
ctrl.rotate_forward(channel=1, frequency=1000, pulses=5000)
# 逆回転: CH2, 500Hz, 連続駆動(pulses=0)
ctrl.rotate_reverse(channel=2, frequency=500)
# 拡張パルス(最大999999パルス)
ctrl.rotate_forward(channel=1, frequency=800, pulses=100000)
# 連続駆動を停止(駆動パルス数が返る)
result = ctrl.stop()
print(result) # e.g. "E01FIN1456"
# パルス数だけ取得
count = ctrl.get_stop_pulse_count()
モーション停止
with PAMC204("COM3") as ctrl:
# 連続駆動を停止(パルス数レスポンスあり)
ctrl.stop()
# 全チャンネル即時停止(レスポンスなし)
ctrl.abort()
# 特定チャンネルの停止(レスポンスなし)
ctrl.stop_channel(channel=1)
ホームポジション
with PAMC204("COM3") as ctrl:
# ホームポジション設定
ctrl.set_home(channel=1, position=1000)
# ホームポジション取得
home = ctrl.get_home(channel=1)
print(f"Home position: {home}")
位置制御
with PAMC204("COM3") as ctrl:
# 速度設定(1–1500 steps/sec)
ctrl.set_velocity(channel=1, velocity=500)
# 絶対位置へ移動
ctrl.move_absolute(channel=1, position=5000)
# 相対移動(現在位置から+1000ステップ)
ctrl.move_relative(channel=1, steps=1000)
# 無限移動
ctrl.move_indefinite(channel=1, direction="+")
# 動作完了を待つ
ctrl.wait_until_done(channel=1, timeout=10.0)
ステータス問い合わせ
with PAMC204("COM3") as ctrl:
# 実位置
pos = ctrl.get_position(channel=1)
# 目標位置(駆動中: 目標位置 / 停止中: 実位置)
target = ctrl.get_target_position(channel=1)
# 相対移動の目標位置
rel_target = ctrl.get_relative_target(channel=1)
# 速度
vel = ctrl.get_velocity(channel=1)
# 動作完了チェック(True=停止, False=駆動中)
done = ctrl.is_motion_done(channel=1)
# 移動チェック(True=移動中, False=停止)
moving = ctrl.is_moving(channel=1)
生コマンド送信
with PAMC204("COM3") as ctrl:
response = ctrl.send_raw("E01INF")
print(response)
コマンド一覧
| メソッド | コマンド | 説明 |
|---|---|---|
get_firmware_info() |
ExxINF |
ファームウェアバージョン確認 |
ping() |
Exx |
ドライバ存在確認 |
set_address() |
SETADDRxx |
アドレス変更 |
set_voltage() |
ExxDACnnnn |
出力電圧調整 |
rotate_forward() |
ExxNRnnnnyyyyz |
正回転駆動 |
rotate_reverse() |
ExxRRnnnnyyyyz |
逆回転駆動 |
stop() |
ExxS |
連続駆動停止 |
abort() |
ExxAB |
モーション停止 |
set_home() |
ExxmDHnnnn |
ホームポジション設定 |
get_home() |
ExxmDH? |
ホームポジション問い合わせ |
is_motion_done() |
ExxmMD? |
動作完了ステータス |
move_indefinite() |
ExxmMVn |
無限移動 |
is_moving() |
ExxmMV? |
移動方向問い合わせ |
move_absolute() |
ExxmPAnnnn |
絶対位置移動 |
get_target_position() |
ExxmPA? |
目標位置問い合わせ |
move_relative() |
ExxmPRnnnn |
相対移動 |
get_relative_target() |
ExxmPR? |
相対目標位置問い合わせ |
stop_channel() |
ExxmST |
チャンネル動作停止 |
get_position() |
ExxmTP? |
実位置問い合わせ |
set_velocity() |
ExxmVAnnnn |
速度設定 |
get_velocity() |
ExxmVA? |
速度問い合わせ |
通信仕様
| 項目 | 値 |
|---|---|
| ボーレート | 115200 bps |
| データビット | 8 bit |
| パリティ | None |
| ストップビット | 1 bit |
| フロー制御 | None |
| デリミタ | CR + LF |
ライセンス
MIT
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pypamc_204-0.1.0.tar.gz
(14.0 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pypamc_204-0.1.0.tar.gz.
File metadata
- Download URL: pypamc_204-0.1.0.tar.gz
- Upload date:
- Size: 14.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
33914ecf47fa7dc09f285fc85fd940a9b7139d8cdc8081053f20d1f9940cb652
|
|
| MD5 |
6a3979f926ab28e26a24a549c32ba44e
|
|
| BLAKE2b-256 |
5ed50e44008413701ba36d4c56070d81ec47358c67b0b33ee28cdab417884703
|
File details
Details for the file pypamc_204-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pypamc_204-0.1.0-py3-none-any.whl
- Upload date:
- Size: 9.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
751a9eebed676884f0fb75793b8477cb04a9b445290ac73e7299aac114cf4647
|
|
| MD5 |
1efc92b4fafd1db2a59971c4e3926d7e
|
|
| BLAKE2b-256 |
212e6834fcd06040739ee8b1a43595e3b74059e3a56f6b1e5fa31c799ff7385f
|