Skip to main content

pyLKMotor: Control the LK motor with Python

PyPI version Python versions Github Tutorial License

Description

PyLKMotor is a Python library to control the LK motor. It provides a simple interface to control the motor and read its status. The library supports:

  • Enable/Disable the motor
  • Torque loop control
  • Speed loop control
  • Multi-turn, single-turn, and incremental position control
  • Read/write motor parameters
  • Read encoder data, multi-turn and single-turn position
  • Set zero position

Hardware Requirements

To use this library, you need the following hardware:

  • LK motor
  • CAN bus interface
  • 24V power supply

Note that this library uses the CAN bus interface to communicate with the motor. You need to connect the motor to the CAN bus interface and power supply. We tested the library with SocketCAN on Linux, and USB-to-CAN adapters on Windows. More details for supported CAN bus interfaces can be found in the python-can library.

Installation

The pylkmotor library supports Python>=3.10, tested on Windows 11, Ubuntu 22.04, and Raspberry Pi OS (bookworm). It can be installed using pip:

pip install pylkmotor

Or you can install it from the source code:

git clone https://github.com/han-xudong/pyLKMotor.git
cd pyLKMotor
pip install .

Usage

Here is an example to initialize the motor:

from pylkmotor import LKMotor

motor = LKMotor(bus_interface={BUS_INTERFACE}, bus_channel={BUS_CHANNEL}, motor_id={MOTOR_ID}, **kwargs)
  • bus_interface: The CAN bus interface, e.g., socketcan, kvaser, serial, etc.
  • bus_channel: The CAN bus channel, e.g., can0, can1, etc.
  • motor_id: The motor ID, e.g., 1, 2, etc.
  • kwargs: The keyword arguments to initialize the CAN bus interface, e.g., baudrate, etc.

This depends on the CAN bus interface you are using.

After initializing the motor, you can control the motor following the tutorial.

Resources

In docs/, you can find the following resources:

  • can_protocol.pdf: The CAN protocol document provided by LK Motor.
  • LK_motor_tool_v2.35.exe: The LK motor tool to configure the motor parameters.

License

PyLKMotor is released under the MIT License.

Acknowledgement

Metadata

Release files for pylkmotor 1.0.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pylkmotor 1.0.6
File Size Uploaded
pylkmotor-1.0.6.tar.gz 8.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pylkmotor 1.0.6
File Interpreter ABI Platform
pylkmotor-1.0.6-py3-none-any.whl Python 3 none any Details

Total release size: 15.5 kB

Release files / pylkmotor-1.0.6.tar.gz

Download URL pylkmotor-1.0.6.tar.gz
Size 8.3 kB
Tags Source
SHA-256 checksum
How to use checksums
b9f6234098ae058e0df47bd23702f3fe65ce0a8f2ce72d374320abfe59a079bf
BLAKE2b-256 checksum
How to use checksums
17b064856544f7223afa535285e2e7dfef24e9442a66e8745c464f81a3e46c27
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.11

Release files / pylkmotor-1.0.6-py3-none-any.whl

Download URL pylkmotor-1.0.6-py3-none-any.whl
Size 7.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
35f10d43838885fde2baf590cc2c7df9047411fdfc967ef18a3f81dee93c7721
BLAKE2b-256 checksum
How to use checksums
973a56ba0b728bd838cbae2cab9ab9993362f53fbaa54a35f1caac4da907faab
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.11

Release history Release notifications | RSS feed

This release

1.0.6 This release

2 release files

1.0.5

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page