def update(self, value):
'''
Accepts an input [-1, 1] and applies it as
scale between 0 and 4096
'''
assert(value <= 1 and -1 <= value)
#convert val to ms
pwm_val = 1600
if self.invert:
pwm_val -= value * 500
else:
pwm_val += value * 500
#SERVO_MIN_ms = 1100
#SERVO_MAX_ms = 2100
stepsPerCycle = 4096
cycleLengthMicroSeconds = 1000000 / self.frequency
stepLengthMicroSeconds = cycleLengthMicroSeconds / stepsPerCycle
#convert mS to 0-4096 scale
pulseLengthInSteps = math.trunc(pwm_val / stepLengthMicroSeconds) - 1
print('Values %d', value, self.channel, pulseLengthInSteps)
self.pwm.setPWM(self.channel, 0, pulseLengthInSteps)
评论列表
文章目录