Repository navigation
Releases
Releases · keigan-motor/pykeigan_motor
3.0.0: bleak BLE, MCP server, error details, USB diagnostics
pykeigan-motor 3.0.0 is on PyPI: https://pypi.org/project/pykeigan-motor/3.0.0/
pip install pykeigan-motor # USB
pip install "pykeigan-motor[ble]" # USB and BLE (python >= 3.8)
pip install "pykeigan-motor[ble,mcp]" # and the MCP server (python >= 3.10)
Documentation (Japanese / English): https://docs.keigan-motor.com/apiDocument/pykeigan_motor/
The method names are the same as v2. BLE has some incompatible changes (see below). Python 2.7 is no longer supported: pip on python 2.7 keeps installing 2.4.0.
MCP server (AI assistants)
pykeigan-mcplets AI assistants (Claude Code, Claude Desktop, etc.) control a Motor over USB or BLE, e.g.claude mcp add keiganmotor -- pykeigan-mcp --usb COM3.- Units are degrees and rpm. Speeds / torques above
--max-rpm(default 60) /--max-torque(default 0.3 N.m) are rejected. - Tools for moving, holding (
hold_position,hold_torque), settings, PID, flash save, safe run, IMU, taskset, teaching, queue, errors, BLE scan and link quality, andread_position_offset.--baudfor the USB baud rate.
Errors
- New
pykeigan.errors: causes, remedies and the meaning of the info value of all firmware error codes.errors.describe(log)makes a readable message. on_motor_error_cb(called only for errors) andlast_error(USB / BLE). The log hasidentifier,info,command_nameanderror_name.debug_mode=Truealso prints the cause and the remedy of errors.flash_memory_states: addedFLASH_STATE_ERASING(10) andFLASH_STATE_READING(30) (read_status()raisedKeyErrorwhile erasing / reading).
BLE
- bluepy replaced with bleak: BLE works on Windows and Linux (including Raspberry Pi 4/5) without sudo. Python >= 3.8 is required for BLE.
blecontroller.scan(), connection retries (BLEController(addr, timeout=10.0, retries=2)), faster connection on Windows,DeviceNotFoundError, notifications for measurement values / logs / events (same callbacks as USBController).- Link diagnostics:
diagnose_link(),link_stats(),blecontroller.diagnose_environment(),blecontroller.check_wifi(). read_imu_measurement_interval(),read_motor_measurement_interval()andread_baud_rate()are supported.- Incompatible changes: removed
BLEController.dev(bluepy Peripheral),start_command_log_capturing()andprint_command_log().start_debug()only prints the command logs received by notifications. Commands raiseConnectionErrorwhile disconnected andTimeoutErroron timeout.
USB
- Register reads return only a value received after the request (no stale cache).
- The end of a frame is found by its length byte (frames whose data contained
0D 0Awere dropped), and the whole device name is read (it was truncated to 13 characters). on_motor_log_cbalso receives unknown commands / error codes.USBController(port, open_timeout=None): raisesConnectionErrorafteropen_timeoutsec if the port cannot be opened.- Connection diagnosis: when the port cannot be opened, the cause is shown (Motor not visible to the OS = USB cable / hub / power, wrong port name, port used by another program).
diagnose_port(),find_keigan_ports(). Warns when the connection is lost 3 times within 60 sec. - New command
pykeigan-usb-check(python -m pykeigan.usbcheck): checks step by step whether the Motor is visible to the OS, the port opens, and the Motor answers. Exit code 0 / 1,--baud.
Common
read_position_offset(): the offset set bypreset_position()(register 0x5B). It survives a reboot aftersave_all_registers()from motor firmware 2.82B.- Clear
MissingDependencyErrormessages with the install command for the running Python when pyserial / bleak / mcp are missing or too old. BLE-only use no longer needs pyserial. - Removed
read_gpio_status()(register 0xCC is not supported by the library). - Python 3.9+: replaced
Thread.isAlive(), so the port is closed at exit. read_motion(): the completion callback is registered before sending the command.- New examples: BLE scan & select, multiple Motors, link check,
usb-offset-position-control.py. - Packaging:
python_requires >= 3.5, MIT license file in the package, project URLs,pyproject.toml.
BLE support is optional
From v2.2.0, you can use pip to install also on windows or mac:
pip install pykeigan-motor
If you need ble support on Linux:
pip install pykeigan-motor[ble]
Python2 support
v2.0.1
add "readmotion" "writeMotionPosition" command