Python driver for the Pololu Maestro series of servo controllers.
Originally cloned from: FRC4564/Maestro
from maestro import Maestro
# Connect to a Micro Maestro
with Maestro.connect('micro') as maestro:
# Set targets of servos 0-3 to 1500, 1600, 1700, and 1800 us
maestro.set_target(0, 1500)
maestro[1] = 1600
maestro[2:4] = [1700, 1800]
# Get targets
assert maestro.get_target(0) == 1500
assert maestro[1] == 1600
assert maestro[0:4] == [1500, 1600, 1700, 1800]
# After leaving the block, the Maestro is told to stop sending signals
# to the servos, and the connection is automatically closed
# Connect to a Mini Maestro 12
with Maestro.connect('mini12') as maestro:
# Servo position may not equal the target
# if speed or acceleration are set, e.g.:
# Move servo 10 from 1000 to 2000 us at low speed
maestro.set_target(10, 1000)
maestro.set_speed(10, 1)
maestro.set_target(10, 2000)
assert maestro.is_moving(10)
assert maestro.get_position(10) != maestro.get_target(10)
maestro.wait_until_done_moving()
assert not maestro.is_moving(10)
assert maestro.get_position(10) == maestro.get_target(10)
The MicroMaestro
and MiniMaestro
classes have the following methods:
set_target(channel: int, target_us: float)
: Set the target position of a servo.get_target(channel: int) -> float
set_targets(targets: dict[int, float])
: Set the target positions of multiple servos at once.get_targets() -> list[float]
get_position(channel: int) -> float
: Get the current position of a servo. May differ from the target if speed or acceleration is non-zero.get_positions() -> list[float]
set_limits(channel: int, min_us: float = None, max_us: float = None)
get_limits(channel: int) -> tuple[Optional[float], Optional[float]]
stop_channel(channel: int)
: Stop sending signals to a servo.stop()
: Stop all channels.go_home()
: Set all servos to their home positions.is_moving(channel: int) -> bool
any_are_moving() -> bool
wait_until_done_moving(poll_period: float = 0.1)
set_speed(channel: int, speed: int)
get_speed(channel: int) -> int
get_speeds() -> list[int]
set_acceleration(channel: int, acceleration: int)
get_acceleration(channel: int) -> int
get_accelerations() -> list[int]
set_digital(channel: int, value: bool)
get_digital(channel: int) -> bool
get_analog(channel: int) -> float
set_pwm(duty_cycle: float, period_us: float = 340)
(Mini Maestro only)
run_script_subroutine(subroutine: int, parameter: int = None)
script_is_running() -> bool
stop_script()
get_errors() -> int
The module can be run to interactively control the servo targets:
python -m maestro {micro,mini12,mini18,mini24} [--tty TTY]
pip install git+https://github.com/austin-bowen/pololu-maestro.git
On Linux, to connect to serial ports without root permissions, you may need to add your user to the dialout
group:
sudo usermod -aG dialout $USER
Then log out and back in. Do this step if you get "Permission denied" errors connecting to the Maestro.
- Open the Maestro Control Center (Windows / Linux) and connect it to your Maestro.
- Go to the Serial Settings tab, and make sure the Serial mode is set to either "USB Dual Port" or "USB Chained".
Setup:
python3 -m venv venv
source venv/bin/activate
pip install -e .[test]
Run unit tests and view coverage:
./test