pid-balancer/Examples/Adafruit_Servokit_servo_driver.py

39 lines
1.5 KiB
Python
Raw Normal View History

import math
2024-12-25 16:52:07 +01:00
from adafruit_servokit import ServoKit
2025-01-10 19:27:37 +01:00
from time import sleep
2024-12-25 16:52:07 +01:00
kit = ServoKit(channels=16)
MIN_PULSE = 400 # Defines angle 80, for current PID setup -- 550
MAX_PULSE = 2500 # Defines angle 100, for current PID setup -- 2450
kit.servo[0].set_pulse_width_range(MIN_PULSE, MAX_PULSE)
# kit.servo[0].set_pulse_width_range(MIN_PULSE, MAX_PULSE)
2024-12-25 16:52:07 +01:00
# Control the minimum and maximum range of the servo.
# min_pulse (int) The minimum pulse width of the servo in microseconds.
# max_pulse (int) The maximum pulse width of the servo in microseconds.
# kit.servo[0].set_pulse_width_range(500, 2500)
2024-12-25 16:52:07 +01:00
# Pulse width expressed as fraction between 0.0 (`min_pulse`) and 1.0 (`max_pulse`).
# For conventional servos, corresponds to the servo position as a fraction
# of the actuation range. Is None when servo is disabled (pulsewidth of 0ms)
2025-01-10 19:27:37 +01:00
# kit.servo[0].angle = 110
2024-12-25 16:52:07 +01:00
# property angle: float | None
# The servo angle in degrees. Must be in the range 0 to actuation_range.
# Is None when servo is disabled.
2025-01-17 21:09:24 +01:00
kit.servo[0].angle = 88
2024-12-25 16:52:07 +01:00
2025-01-08 15:25:41 +01:00
2024-12-25 16:52:07 +01:00
# property throttle: float
# How much power is being delivered to the motor.
# Values range from -1.0 (full throttle reverse) to 1.0 (full throttle forwards.)
# 0 will stop the motor from spinning.
# kit.continuous_servo[0].throttle = 0.5
2024-12-25 16:52:07 +01:00
# property actuation range: float | None
# The servo angle in degrees. Must be in the range 0 to actuation_range.
# Is None when servo is disabled
#kit.servo[0].actuation_range = 120