test.py 649 B

1234567891011121314151617181920212223242526272829303132
  1. import pigpio
  2. import subprocess
  3. import time
  4. subprocess.run('pigpiod', shell=True)
  5. pi = pigpio.pi()
  6. MSLIST = [
  7. {
  8. "name": 'MOTOR',
  9. "pinList": [13, 16]
  10. },
  11. {
  12. "name": 'SERVO',
  13. "pinList": [12, 19]
  14. },
  15. ]
  16. # 自动校准
  17. speed = 0
  18. while True:
  19. speed += 1
  20. for s in MSLIST:
  21. for d in s['pinList']:
  22. if s['name'] == 'MOTOR':
  23. # Set ESC speed via PWM
  24. pi.set_servo_pulsewidth(
  25. d, speed * 1000 / 7 + 1000)
  26. else:
  27. pi.set_servo_pulsewidth(d, 1500)
  28. time.sleep(2)
  29. print(speed)
  30. if speed > 3:
  31. break