Library for controlling bus servos using the LewanSoul Bus Servo Communication Protocol
Project description
LewanLib
Library for controlling bus servos using the LewanSoul Bus Servo Communication Protocol.
This README explains how to get the library, set up a Python environment on Windows (and other OSes), run tests, and start using the API.
Getting The Code
Clone the repository:
git clone https://github.com/NCSU-High-Powered-Rocketry-Club/LewanLib.git
cd LewanLib
Supported Python versions: 3.8 and newer (the project was developed against modern Python — use 3.10+ when possible).
Quick Setup (recommended: use a virtualenv)
Windows (PowerShell):
python -m venv .venv
.\.venv\Scripts\Activate.ps1
python -m pip install --upgrade pip
python -m pip install -e ".[dev]"
macOS / Linux (bash):
python -m venv .venv
source .venv/bin/activate
python -m pip install --upgrade pip
python -m pip install -e ".[dev]"
-e .installs the package in editable/developer mode. The".[dev]"extra installs development dependencies (tests, linters, type checkers).- If you prefer not to install dev dependencies, run
python -m pip install -e .instead.
Notes about pytest and PATH on Windows
- If
pytestis not found when you runpytestdirectly, it's usually because the PythonScriptsdirectory (or your virtualenv'sScripts) isn't on your PATH. Instead of modifying PATH you can always run tests with:
python -m pytest tests/ -q
- Using the virtualenv activation step above ensures the
Scriptsdirectory is on PATH for the current shell session.
Run Tests
After installing dev dependencies, run the test suite:
python -m pytest tests/ -v
This repository ships small unit tests in tests/ that validate utility functions and basic behavior.
Quick Usage Example
from lewanlib.bus import ServoBus
with ServoBus(port='COM3', baudrate=115200) as bus:
# Move servo 1 to 120 degrees over 1.0 seconds and wait until movement completes
bus.move_time_write(1, 120, 1.0, wait=True)
servo = bus.get_servo(1, name='Arm')
print('Position (deg):', servo.pos_read())
See lewanlib/bus.py and lewanlib/servo.py for more detailed API documentation and examples.
Development Tips
- Run the type checker:
python -m mypy lewanlib
- Run linters / formatters if installed:
python -m flake8
python -m black .
Hardware & Dependencies
- Hardware: LewanSoul bus servos and a serial adapter (USB-to-TTL/RS485 as appropriate for your hardware).
- Runtime dependency:
pyserial(installed automatically by the dev extras).
Troubleshooting
- If you see permission errors when accessing serial ports on Linux/macOS, ensure your user has access to the device (e.g., add to
dialoutgroup or usesudowhen testing). - If a test or command uses an absolute Python path (leftover from older workflows), prefer
python -m <module>to avoid path issues.
Additional Setup Docs
For alternative setups (for example, if you don't want to use conda), see SETUP_NO_CONDA.md for step-by-step instructions.
Package Layout
lewanlib/constants.py— Protocol constants and packet definitions.lewanlib/types.py— Type aliases and data structures.lewanlib/utils.py— Utility functions (conversions, checksums, etc.).lewanlib/servo.py—Servoconvenience wrapper class.lewanlib/bus.py—ServoBusclass (main interface to the servo bus).
License
See the LICENSE file for license details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
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 lewanlib-0.1.0.tar.gz.
File metadata
- Download URL: lewanlib-0.1.0.tar.gz
- Upload date:
- Size: 17.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.29 {"installer":{"name":"uv","version":"0.9.29","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7e31a88fee02bff08370a19a6b7c4f302a76996c1817d5c52eb6fca8a5298fe8
|
|
| MD5 |
65c95f63a25b4c05fca8d9fe2ef6c35d
|
|
| BLAKE2b-256 |
4e2b52d09f18254c0c17f4bd9b39bf3d503b639478182c75779f04d660ce6d78
|
File details
Details for the file lewanlib-0.1.0-py3-none-any.whl.
File metadata
- Download URL: lewanlib-0.1.0-py3-none-any.whl
- Upload date:
- Size: 16.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.29 {"installer":{"name":"uv","version":"0.9.29","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f213c4c0d6b6d1e49652b000cbaf6bb819dea87c82fb85d257dc6525e70ef9f0
|
|
| MD5 |
11afc0d38f2149a139876dba096c279b
|
|
| BLAKE2b-256 |
a811899c3bf32233775b776d6f1a80d7348cc2a32e0989a7bfcca251f6994aee
|