The positions are set by html request.
I want to determine in my python code, the current position of each servo
before I set the new position.
Here is my test python code that is called by a PHP script.
Please forgive my terrible python code it could probably be a lot better.
It is mostly cut and paste code.
Code: Select all
from __future__ import division
import sys
import time
# Import the PCA9685 module.
import Adafruit_PCA9685
# Initialise the PCA9685 using the default address (0x40).
pwm = Adafruit_PCA9685.PCA9685()
hservo_min = 150 # Min pulse length out of 4096
vervo_min = 150 # Min pulse length out of 4096
hservo_max = 600 # Max pulse length out of 4096
vservo_max = 600 # Max pulse length out of 4096
vpan = 1
hpan = 0
# Helper function to make setting a servo pulse width simpler.
def set_servo_pulse(channel, pulse):
pulse_length = 1000000 # 1,000,000 us per second
pulse_length //= 60 # 60 Hz
print('{0}us per period'.format(pulse_length))
pulse_length //= 4096 # 12 bits of resolution
print('{0}us per bit'.format(pulse_length))
pulse *= 1000
pulse //= pulse_length
pwm.set_pwm(channel, 0, pulse)
# Set frequency to 60hz, good for servos.
pwm.set_pwm_freq(60)
if not(len(sys.argv) == 3):
print("2 values must be entered")
quit()
try:
tmp1 = int(sys.argv[1])
except:
print("first value was not an integer!")
quit()
try:
tmp2 = int(sys.argv[2])
except:
print("second value was not an integer!")
quit()
if (139 <= tmp1 <= 600) and (90 <= tmp2 <= 600):
newtmp = 690 - tmp2
pwm.set_pwm(vpan, 0, tmp1)
pwm.set_pwm(hpan, 0, newtmp)
else:
print("numbers not in range")