drivers.py 文件源码

python
阅读 44 收藏 0 点赞 0 评论 0

项目:burro 作者: yconst 项目源码 文件源码
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)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号