A modular library system for robot control with motor drivers, joystick controllers, and GPIO management
Project description
Piwars2026lib
A modular library system for robot control with motor drivers, joystick controllers, and GPIO management for Raspberry Pi.
Features
- Motor Control: L298N dual motor driver control with PWM speed control
- Joystick Controller: Pygame-based joystick input handling with deadzone support
- GPIO Management: Centralized GPIO configuration and initialization
- Drive Control: Multiple drive algorithms (arcade, tank, curvature drive)
Installation
pip install piwars2026lib
Requirements
- Raspberry Pi (for GPIO functionality)
- Python 3.7+
- RPi.GPIO
- pygame
Quick Start
from piwars2026lib import MotorController, JoystickController, GPIOConfig, DriveControl
import pygame
# Initialize
pygame.init()
gpio = GPIOConfig()
gpio.setup()
# Setup motors with default pin configuration
pins = GPIOConfig.get_default_pins()
motors = MotorController(
ena_pin=pins['ENA'],
in1_pin=pins['IN1'],
in2_pin=pins['IN2'],
enb_pin=pins['ENB'],
in3_pin=pins['IN3'],
in4_pin=pins['IN4']
)
# Setup joystick
joystick = JoystickController(joystick_id=0, deadzone=0.1)
# Control loop
clock = pygame.time.Clock()
try:
while True:
joystick.pump_events()
x, y = joystick.get_left_stick()
left, right = DriveControl.arcade_drive(y, x)
motors.set_tank_drive(left, right)
clock.tick(50)
except KeyboardInterrupt:
pass
finally:
motors.cleanup()
joystick.cleanup()
gpio.cleanup()
pygame.quit()
API Documentation
MotorController
Controls dual motors using L298N driver.
motors = MotorController(ena_pin, in1_pin, in2_pin, enb_pin, in3_pin, in4_pin, pwm_freq=1000)
motors.set_motor_speed('A', speed) # speed: -100 to 100
motors.set_tank_drive(left_speed, right_speed)
motors.stop_all()
motors.cleanup()
JoystickController
Manages joystick input and provides normalized control values.
joystick = JoystickController(joystick_id=0, deadzone=0.1)
x, y = joystick.get_left_stick()
x, y = joystick.get_right_stick()
value = joystick.get_axis(axis_id)
button = joystick.get_button(button_id)
joystick.pump_events()
joystick.cleanup()
GPIOConfig
Manages GPIO configuration and initialization.
gpio = GPIOConfig(mode=GPIO.BCM, warnings=False)
gpio.setup()
pins = GPIOConfig.get_default_pins()
gpio.cleanup()
DriveControl
Provides various drive control algorithms.
# Arcade drive
left, right = DriveControl.arcade_drive(y_axis, x_axis)
# Tank drive
left, right = DriveControl.tank_drive(left_y, right_y)
# Curvature drive
left, right = DriveControl.curvature_drive(y_axis, x_axis, quick_turn_threshold=0.1)
Default Pin Configuration
The default pin configuration (BCM numbering) is:
- ENA: 13 (Motor A speed control - PWM)
- IN1: 19 (Motor A direction)
- IN2: 26 (Motor A direction)
- ENB: 12 (Motor B speed control - PWM)
- IN3: 16 (Motor B direction)
- IN4: 20 (Motor B direction)
License
MIT License
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
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 piwars2026lib-1.0.0.tar.gz.
File metadata
- Download URL: piwars2026lib-1.0.0.tar.gz
- Upload date:
- Size: 6.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4f8619f37dee4249f181ed4abfb7426b55b3eb846e3502aab4c96b11b6d11774
|
|
| MD5 |
3b53f8b27ce945087fd0a2f17ba8952c
|
|
| BLAKE2b-256 |
42b52aee0481194eb6ed74e687971738e9392daa75b141f15d89e3963227531a
|
File details
Details for the file piwars2026lib-1.0.0-py3-none-any.whl.
File metadata
- Download URL: piwars2026lib-1.0.0-py3-none-any.whl
- Upload date:
- Size: 7.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6c9208da89b3a44af6ac956874560aed12af2d5c4e625ad83e0d9ced8d17abd5
|
|
| MD5 |
e3c66780e53ca897985687fabc802528
|
|
| BLAKE2b-256 |
7344911a3f4ad85bede9a5bfb163441ab2c17bdf9b8134567440770c1b258e37
|