Vassar College's Python SDK for Feetech servo control and position reading
Project description
Vassar Feetech Servo SDK
A comprehensive Python SDK and command-line tool for controlling Feetech servos (STS/HLS series).
Features
- 🔌 Auto-detection of serial ports
- 🎯 Support for STS and HLS servos (HLS includes torque control)
- 📖 Read positions from single or multiple servos
- 🎯 Set middle position - Calibrate servos to position 2048
- ✍️ Write position targets (coming soon)
- 💪 Write torque targets (coming soon)
- 🚀 High-performance group sync operations
- 📊 Real-time monitoring with configurable update rates
- 🐍 Clean Python API with servo configuration at initialization
- 💻 Command-line interface for all operations
- 🔧 Context manager support for clean resource management
Installation
From PyPI
pip install vassar-feetech-servo-sdk
From Source
git clone https://github.com/vassar-robotics/feetech-servo-sdk.git
cd feetech-servo-sdk
pip install -e .
Dependencies
- Python >= 3.7
- pyserial >= 3.5
Note: The scservo_sdk is bundled with this package, so no separate installation is needed.
Quick Start
Command Line Usage
# Read from motors 1-6 continuously at 30Hz
vassar-servo
# Set all servos to middle position
vassar-servo --set-middle
# Read from specific motors at 60Hz
vassar-servo --motor-ids 1,3,5 --hz 60
# Use HLS servos (default is STS)
vassar-servo --servo-type hls
# Read once and exit
vassar-servo --once
# Output JSON format (useful for scripting)
vassar-servo --once --json
Python API Usage
from vassar_feetech_servo_sdk import ServoController
# Initialize controller with your servo configuration
servo_ids = [1, 2, 3, 4, 5, 6]
controller = ServoController(servo_ids=servo_ids, servo_type="sts") # or "hls"
controller.connect()
# Read all configured servos
positions = controller.read_all_positions()
for motor_id, pos in positions.items():
print(f"Motor {motor_id}: {pos} ({pos/4095*100:.1f}%)")
# Set servos to middle position
success = controller.set_middle_position()
if success:
print("All servos calibrated to middle position!")
controller.disconnect()
# Using context manager
with ServoController([1, 2, 3], "sts") as controller:
positions = controller.read_all_positions()
print(positions)
# Continuous reading with callback
def my_callback(positions):
print(f"Got positions: {positions}")
with ServoController([1, 2, 3], "hls") as controller:
controller.read_positions_continuous(
callback=my_callback,
frequency=50.0
)
Advanced Usage
# Initialize with specific configuration
controller = ServoController(
servo_ids=[1, 2, 3, 4, 5, 6],
servo_type="hls", # 'sts' or 'hls'
port="/dev/ttyUSB0",
baudrate=1000000
)
# Error handling
from vassar_feetech_servo_sdk import ServoReaderError, PortNotFoundError
try:
controller = ServoController([1, 2, 3], "sts")
controller.connect()
positions = controller.read_all_positions()
except PortNotFoundError:
print("No servo port found!")
except ServoReaderError as e:
print(f"Error: {e}")
API Reference
ServoController Class
Constructor
ServoController(servo_ids, servo_type="sts", port=None, baudrate=1000000)
servo_ids: List of servo IDs to control (e.g., [1, 2, 3, 4, 5, 6])servo_type: Type of servo - 'sts' or 'hls' (default: 'sts')port: Serial port path (auto-detect if None)baudrate: Communication speed (default: 1000000)
Methods
connect(): Establish connection to servosdisconnect(): Close connectionread_position(motor_id): Read single motor positionread_positions(motor_ids=None): Read multiple motor positionsread_all_positions(): Read all configured servo positionsset_middle_position(motor_ids=None): Calibrate servos to middle position (2048)read_positions_continuous(motor_ids=None, callback=None, frequency=30.0): Continuously read positions
Utility Functions
find_servo_port(): Auto-detect servo serial port
Servo Types
- STS: Standard Feetech servos (default) - position and speed control
- Middle position calibration uses torque=128 method
- HLS: High-end servos with additional torque control capabilities
- Middle position calibration uses offset calibration (
reOfsCal) method
- Middle position calibration uses offset calibration (
Troubleshooting
Port Not Found
If auto-detection fails, specify the port manually:
# Linux
vassar-servo --port /dev/ttyUSB0
# macOS
vassar-servo --port /dev/tty.usbserial-*
# Windows
vassar-servo --port COM3
Permission Denied (Linux)
Add your user to the dialout group:
sudo usermod -a -G dialout $USER
# Log out and back in for changes to take effect
Connection Failed
- Check servo power supply
- Verify baudrate matches servo configuration (default: 1000000)
- Ensure proper wiring (TX/RX not swapped)
Examples
The package includes several example scripts in the examples/ directory:
basic_usage.py- Simple example showing how to connect and read servo positionscontinuous_reading.py- Real-time monitoring with custom callbacksservo_types.py- Demonstrates differences between STS and HLS servosset_middle_position.py- Shows how to calibrate servos to middle position
Acknowledgments
Built on top of the excellent scservo_sdk library for Feetech servo communication.
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 vassar_feetech_servo_sdk-0.2.2.tar.gz.
File metadata
- Download URL: vassar_feetech_servo_sdk-0.2.2.tar.gz
- Upload date:
- Size: 22.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
533097810fe1723cb63da1332b7015f69617d2a288f52bc0ee6e9e5345b9a166
|
|
| MD5 |
37daa384707b3f053d6b232d77177356
|
|
| BLAKE2b-256 |
f30895296f50ce1a22e5890122471a198a024690f068510b7f16781ef861e22d
|
File details
Details for the file vassar_feetech_servo_sdk-0.2.2-py3-none-any.whl.
File metadata
- Download URL: vassar_feetech_servo_sdk-0.2.2-py3-none-any.whl
- Upload date:
- Size: 26.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
819b1e7689bc83be5d9afae9742d381d5a4c8fbf2bf3387602221ec1a3e48238
|
|
| MD5 |
bab06a56eca83be02e0ee88fc7e81cb9
|
|
| BLAKE2b-256 |
8482c8bb588334106c48f2891abbbdf032ce80f09d78aae470f6a85bc805f906
|