main.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!/usr/bin/env python
  2. import sys
  3. from pymavlink import mavutil
  4. def set_servo_pwm(servo_n, microseconds):
  5. """ Sets AUX 'servo_n' output PWM pulse-width.
  6. Uses https://mavlink.io/en/messages/common.html#MAV_CMD_DO_SET_SERVO
  7. 'servo_n' is the AUX port to set (assumes port is configured as a servo).
  8. Valid values are 1-3 in a normal BlueROV2 setup, but can go up to 8
  9. depending on Pixhawk type and firmware.
  10. 'microseconds' is the PWM pulse-width to set the output to. Commonly
  11. between 1100 and 1900 microseconds.
  12. """
  13. # master.set_servo(servo_n+8, microseconds) or:
  14. master.mav.command_long_send(
  15. master.target_system, master.target_component,
  16. mavutil.mavlink.MAV_CMD_DO_SET_SERVO,
  17. 0, # first transmission of this command
  18. servo_n + 8, # servo instance, offset by 8 MAIN outputs
  19. microseconds, # PWM pulse-width
  20. 0,0,0,0,0 # unused parameters
  21. )
  22. master = mavutil.mavlink_connection('udpin:127.0.0.1:14550')
  23. master.wait_heartbeat()
  24. print("CONNECT SUCCESS")
  25. count = 1
  26. for i in range(1100, 1700, 100):
  27. print("NUM: ", count, " | PWM: ", i)
  28. set_servo_pwm(count, i)
  29. count += 1
  30. print("SET SERVOS SUCCESS")