lx16a-servo

Crates.iolx16a-servo
lib.rslx16a-servo
version0.2.1
created_at2025-10-11 01:23:22.953651+00
updated_at2025-10-13 00:01:57.609592+00
descriptionAbstraction library for controlling Hiwonder LX-16A servos over UART.
homepagehttps://github.com/abagul1/lx16a-servo
repositoryhttps://github.com/abagul1/lx16a-servo
max_upload_size
id1877714
size59,190
(abagul1)

documentation

https://docs.rs/lx16a-servo

README

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_ID to NEW_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 --ignored flag to run them.
  • Tests run serially (one at a time) using the serial_test crate to prevent conflicts accessing the serial port.

Platforms

  • Currently only Linux and macOS are supported via the serialport crate.

License

This project is licensed under the MIT License.

Commit count: 0

cargo fmt