Skip to main content

Vassar College's Python SDK for Feetech servo control and position reading

Project description

Vassar Feetech Servo SDK

A Python library and command-line tool for reading positions from Feetech servos (STS/SMS/HLS series).

Features

  • 🔌 Auto-detection of serial ports
  • 🎯 Support for multiple servo types: STS, SMS, and HLS series
  • 🚀 High-performance group sync read for multiple servos
  • 📊 Real-time display with configurable update rates
  • 🐍 Simple Python API for integration into your projects
  • 💻 Command-line interface for quick testing and monitoring
  • 🔧 Context manager support for clean resource management

Installation

From PyPI (when published)

pip install vassar-feetech-servo-sdk

From Source

git clone https://github.com/yourusername/vassar-feetech-servo-sdk.git
cd vassar-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

# Read from specific motors at 60Hz
vassar-servo --motor-ids 1,3,5 --hz 60

# Use specific port and servo type
vassar-servo --port /dev/ttyUSB0 --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 ServoReader

# Basic usage
reader = ServoReader()  # Auto-detect port, SMS/STS servos
reader.connect()

# Read single motor
position = reader.read_position(motor_id=1)
print(f"Motor 1 position: {position}")

# Read multiple motors
positions = reader.read_positions([1, 2, 3, 4, 5, 6])
for motor_id, pos in positions.items():
    print(f"Motor {motor_id}: {pos} ({pos/4095*100:.1f}%)")

reader.disconnect()

# Using context manager
with ServoReader() as reader:
    positions = reader.read_positions([1, 2, 3])
    print(positions)

# Continuous reading with callback
def my_callback(positions):
    print(f"Got positions: {positions}")

with ServoReader() as reader:
    reader.read_positions_continuous(
        motor_ids=[1, 2, 3],
        callback=my_callback,
        frequency=50.0
    )

Advanced Usage

# Specify port and servo type
reader = ServoReader(
    port="/dev/ttyUSB0",
    baudrate=1000000,
    servo_type="hls"  # 'sms_sts', 'hls', or 'scscl'
)

# Error handling
from vassar_feetech_servo_sdk import ServoReaderError, PortNotFoundError

try:
    reader = ServoReader()
    reader.connect()
    position = reader.read_position(1)
except PortNotFoundError:
    print("No servo port found!")
except ServoReaderError as e:
    print(f"Error: {e}")

API Reference

ServoReader Class

Constructor

ServoReader(port=None, baudrate=1000000, servo_type="sms_sts")
  • port: Serial port path (auto-detect if None)
  • baudrate: Communication speed (default: 1000000)
  • servo_type: Type of servo - 'sms_sts', 'hls', or 'scscl'

Methods

  • connect(): Establish connection to servos
  • disconnect(): Close connection
  • read_position(motor_id): Read single motor position
  • read_positions(motor_ids): Read multiple motor positions
  • read_positions_continuous(motor_ids, callback=None, frequency=30.0): Continuously read positions

Utility Functions

  • find_servo_port(): Auto-detect servo serial port

Servo Types

  • SMS/STS: Most common Feetech servos (default)
  • HLS: High-end servos with torque control
  • SCSCL: Specialized servo series

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

  1. Check servo power supply
  2. Verify baudrate matches servo configuration (default: 1000000)
  3. Ensure proper wiring (TX/RX not swapped)

Development

Setup Development Environment

# Clone the repository
git clone https://github.com/yourusername/vassar-feetech-servo-sdk.git
cd vassar-feetech-servo-sdk

# Install in development mode with dev dependencies
pip install -e ".[dev]"

# Run tests
pytest

# Format code
black feetech_reader

# Type checking
mypy feetech_reader

Building and Publishing

# Build package
python -m build

# Test upload to TestPyPI
twine upload --repository testpypi dist/*

# Upload to PyPI
twine upload dist/*

License

MIT License - see LICENSE file for details.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Advanced Usage - Direct scservo_sdk Access

The scservo_sdk is bundled with this package. For advanced users who need direct access to the low-level SDK:

import scservo_sdk as scs

# Direct SDK usage
port_handler = scs.PortHandler('/dev/ttyUSB0')
packet_handler = scs.sms_sts(port_handler)  # or scs.hls() for HLS servos

# ... use the SDK directly

Acknowledgments

Built on top of the excellent scservo_sdk library for Feetech servo communication.

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

vassar_feetech_servo_sdk-0.1.0.tar.gz (21.1 kB view details)

Uploaded Source

Built Distribution

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

vassar_feetech_servo_sdk-0.1.0-py3-none-any.whl (21.1 kB view details)

Uploaded Python 3

File details

Details for the file vassar_feetech_servo_sdk-0.1.0.tar.gz.

File metadata

File hashes

Hashes for vassar_feetech_servo_sdk-0.1.0.tar.gz
Algorithm Hash digest
SHA256 cb4de4937c54f7929ab444e3f62c43c9ef9d7d0d7ec94409b746543b7f6c0990
MD5 684521637c5b44680bd04b199d5e5e05
BLAKE2b-256 1d5024f09b08ede06dd3cb3cfc5569eb0edadb32c0949afb2007a0711d9428b9

See more details on using hashes here.

File details

Details for the file vassar_feetech_servo_sdk-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for vassar_feetech_servo_sdk-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a3565b19b5f200ec7e4b238685bfb8406805377024274b70e252fdc30feacb65
MD5 4c3bbfb782dee24154f07e9a5152ff0b
BLAKE2b-256 5852bba179053fe7311a6000034bc990eeef1f59cae461eb6b4eededda8d5a7e

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