Skip to content

Releases

3.0.0: bleak BLE, MCP server, error details, USB diagnostics

Choose a tag to compare

@takashi-keigan takashi-keigan released this 15 Nov 09:26

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-mcp lets 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, and read_position_offset. --baud for 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) and last_error (USB / BLE). The log has identifier, info, command_name and error_name.
  • debug_mode=True also prints the cause and the remedy of errors.
  • flash_memory_states: added FLASH_STATE_ERASING (10) and FLASH_STATE_READING (30) (read_status() raised KeyError while 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() and read_baud_rate() are supported.
  • Incompatible changes: removed BLEController.dev (bluepy Peripheral), start_command_log_capturing() and print_command_log(). start_debug() only prints the command logs received by notifications. Commands raise ConnectionError while disconnected and TimeoutError on 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 0A were dropped), and the whole device name is read (it was truncated to 13 characters).
  • on_motor_log_cb also receives unknown commands / error codes.
  • USBController(port, open_timeout=None): raises ConnectionError after open_timeout sec 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 by preset_position() (register 0x5B). It survives a reboot after save_all_registers() from motor firmware 2.82B.
  • Clear MissingDependencyError messages 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

Choose a tag to compare

@wingcloud wingcloud released this 22 Nov 12:05
15683e9

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

Choose a tag to compare

@wingcloud wingcloud released this 01 Jun 00:15
v2.1.0

python 2 support

v2.0.1

Choose a tag to compare

@keigan-motor keigan-motor released this 12 May 07:38
add "readmotion" "writeMotionPosition" command