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