Hi everyone,
I am trying to write a python program to test the T200 thrusters using a adafruit. I have the thrusters individually moving forward without any issue but I am trying to reverse the direction as well but am having major issues. I would really appreciate some help. below I have provided the code that I am currently using to test my thrusters. I am using a Raspberry pi 4B:
from adafruit_servokit import ServoKit
import time
Initialize the PCA9685 servo driver with 16 channels
kit = ServoKit(channels=16)
Define the channel for the single thruster being tested
THRUSTER_CHANNEL = 0 # Update to match your thruster’s channel
Function to test a single thruster
def test_thruster(channel, forward_min=1500, forward_max=1900, reverse_min=1500, reverse_max=1100, step=100):
print(f"Testing Thruster on Channel {channel}")
kit.continuous_servo[channel].throttle = 0.0 # Ensure no signal initially
time.sleep(1)
# Test forward direction
print("Testing forward direction...")
for pwm in range(forward_min, forward_max + 1, step):
normalized_pwm = (pwm - 1500) / 500 # Normalize PWM range for Adafruit ServoKit
print(f"Channel {channel}: PWM {pwm}, Normalized: {normalized_pwm}")
kit.continuous_servo[channel].throttle = normalized_pwm
time.sleep(2) # Hold each signal for 2 seconds
# Stop for a moment
print("Stopping thruster...")
kit.continuous_servo[channel].throttle = 0.0
time.sleep(2)
# Test reverse direction
print("Testing reverse direction...")
for pwm in range(reverse_min, reverse_max - 1, -step):
normalized_pwm = (pwm - 1500) / 500 # Normalize PWM range for Adafruit ServoKit
print(f"Channel {channel}: PWM {pwm}, Normalized: {normalized_pwm}")
kit.continuous_servo[channel].throttle = normalized_pwm
time.sleep(2) # Hold each signal for 2 seconds
# Stop thruster
print("Stopping thruster...")
kit.continuous_servo[channel].throttle = 0.0
print(f"Thruster test completed for Channel {channel}")
if name == “main”:
try:
test_thruster(THRUSTER_CHANNEL)
except KeyboardInterrupt:
print(“Test interrupted. Setting thruster to neutral.”)
kit.continuous_servo[THRUSTER_CHANNEL].throttle = 0.0