Skip to main content

Python library for controlling LK motors

Project description

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. For example, if you are using the socketcan interface, you can initialize the motor as follows:

motor = LKMotor(bus_interface='socketcan', bus_channel='can0', motor_id=1)

If you are using a USB-to-CAN adapter, you can initialize the motor as follows:

motor = LKMotor(bus_interface='serial', bus_channel='COM3', motor_id=1, baudrate=1000000)

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

License

PyLKMotor is released under the MIT License.

Acknowledgement

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

pylkmotor-1.0.3.tar.gz (7.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pylkmotor-1.0.3-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

Details for the file pylkmotor-1.0.3.tar.gz.

File metadata

  • Download URL: pylkmotor-1.0.3.tar.gz
  • Upload date:
  • Size: 7.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.11

File hashes

Hashes for pylkmotor-1.0.3.tar.gz
Algorithm Hash digest
SHA256 757d2e5af4249d10e085f879137bad5a319f3c7f6ca83aa519aff57d4af50052
MD5 08fced15261b9ed2649c131615d97c82
BLAKE2b-256 d37c8a9ce8a8766de84cc25c87a872720020a380c0a1df653fab2d01ae33dc4e

See more details on using hashes here.

File details

Details for the file pylkmotor-1.0.3-py3-none-any.whl.

File metadata

  • Download URL: pylkmotor-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 7.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.11

File hashes

Hashes for pylkmotor-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 0548b4e75a11c39a7ea30d6d2d6d57d84755a8bdf971737cb5ba06c6360860c5
MD5 2e61beacc240b54cb2b69b6eb1d21498
BLAKE2b-256 74dc12a06a0ca8e6b4ed502ba981674f0932e03aebe8c7130b7c94bc0186816e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page