3 unstable releases
Uses new Rust 2024
| 0.2.1 | Oct 13, 2025 |
|---|---|
| 0.2.0 | Oct 13, 2025 |
| 0.1.0 | Oct 11, 2025 |
#842 in Hardware support
29KB
379 lines
About
This library provides idiomatic Rust abstractions for controlling Hiwonder LX-16A serial bus servos.
It offers a simple, minimal-setup interface for initializing the servo bus, commanding motion, and reading servo state.
Install
Add to your Cargo.toml:
[dependencies]
lx16a-servo = "0.2.0"
Examples
Connect the Bus Linker to your computer before running any examples. On macOS, your serial device is typically under /dev/tty.usbserial-*. Adjust the PATH constant in each example accordingly.
move_single_servo
Basic example demonstrating single servo control with position moves.
cargo run --example move_single_servo
Features:
- Enable/disable torque
- Read current position
- Command position moves with timing
- Basic servo interaction
assign_servo_id
Reassign a servo's ID (useful when setting up new servos or resolving ID conflicts).
cargo run --example assign_servo_id
Features:
- Change servo ID from
CURRENT_IDtoNEW_ID - Automatic fallback to broadcast mode if direct write fails
- Verification of new ID after assignment
Important: Only connect one servo to the bus when changing IDs to avoid conflicts.
multi_servo_control
Demonstrates synchronized multi-servo control using ServoController.
cargo run --example multi_servo_control
Features:
- Control multiple servos simultaneously
- Synchronized position moves
- Coordinated motion timing
- Read positions from multiple servos
Configure servo IDs using the S1 and S2 constants in the example.
Testing
Hardware integration tests are available in tests/hardware_tests.rs. These tests require a physical servo connected to the bus.
Configure your hardware setup by editing the constants at the top of the test file:
const PATH: &str = "/dev/tty.usbserial-210";
const BAUD: u32 = 115_200;
const TEST_SERVO_ID: u8 = 1;
Run all hardware tests (requires connected servo):
cargo test -- --ignored
Run a specific test:
cargo test test_read_position -- --ignored
List all available tests:
cargo test -- --ignored --list
Note:
- Tests are marked with
#[ignore = "requires hardware"]since they need a physical servo. Use the--ignoredflag to run them. - Tests run serially (one at a time) using the
serial_testcrate to prevent conflicts accessing the serial port.
Platforms
- Currently only Linux and macOS are supported via the
serialportcrate.
License
This project is licensed under the MIT License.
Dependencies
~2–12MB
~104K SLoC