失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > 树莓派pca9685舵机驱动板python驱动

树莓派pca9685舵机驱动板python驱动

时间:2024-06-19 02:48:08

相关推荐

树莓派pca9685舵机驱动板python驱动

#以下为python源程序 #输入通道与角度。即可选通并使该通道的舵机转动到相应的角度 from __future__ import division #导入 __future__ 文件的 division 功能函数(模块、变量名....) #新的板库函数 //= import time # Import the PCA9685 module. import Adafruit_PCA9685 #导入Adafruit_PCA9685模块 # Uncomment to enable debug output. #import logging #logging.basicConfig(level=logging.DEBUG) #调试打印日志输出 # Initialise the PCA9685 using the default address (0x40). pwm = Adafruit_PCA9685.PCA9685() #把Adafruit_PCA9685.PCA9685()引用地址赋给PWM标签 # Alternatively specify a different address and/or bus: #pwm = Adafruit_PCA9685.PCA9685(address=0x41, busnum=2) #2^12精度 角度转换成数值 #angle输入的角度值(0--180) #pulsewidth高电平占空时间(0.5ms--2.5ms) #/1000将us转换为ms #20ms时基脉冲(50HZ) #pulse_width=((angle*11)+500)/1000; //将角度转化为500(0.5)<-->2480(2.5)的脉宽值(高电平时间) angle=180时 pulse_width=2480us(2.5ms) #date/4096=pulse_width/20 ->有上pulse_width的计算结果得date=4096*( ((angle*11)+500)/1000 )/20 -->int date=4096((angle*11)+500)/20000; def set_servo_angle(channel, angle): #输入角度转换成12^精度的数值 date=4096*((angle*11)+500)/20000 #进行四舍五入运算 date=int(4096*((angle*11)+500)/(20000)+0.5)pwm.set_pwm(channel, 0, date) # Set frequency to 50hz, good for servos. pwm.set_pwm_freq(50) print('Moving servo on channel x, press Ctrl-C to quit...') while True: # Move servo on channel O between extremes. channel=int(input('pleas input channel:')) angle=int(input('pleas input angle:')) set_servo_angle(channel, angle) #time.sleep(1)

如果觉得《树莓派pca9685舵机驱动板python驱动》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。