Skip to content

Instantly share code, notes, and snippets.

@Williangalvani
Created February 10, 2021 18:21
Show Gist options
  • Save Williangalvani/09bce4a671425e9a7b74ff4e1409bf93 to your computer and use it in GitHub Desktop.
Save Williangalvani/09bce4a671425e9a7b74ff4e1409bf93 to your computer and use it in GitHub Desktop.
from pymavlink import mavutil
import time
############################## WARNING ################################
# THIS WILL DISABLE ARDUSUB'S ABILITIES TO CONTROL THE ROV BY ITSELF.
# USE WITH CAUTION
# MOTORS WILL SPIN WHEN THIS RUNS EVEN IF DISARMED
#######################################################################
# This example allows direct control of the thrusters, bypassing the
# builtin ardusub controllers and allowing direct control of the thrusters
# You will need to manually create a new mavlink endpoint (http://192.168.2.2:2770/mavproxy)
# at port 14551 so it can be used alongside QGC
# You will also need to setup the SERVOx_FUNCTION parameters to the corresponing
# RCx_IN option (SERVO1_FUNCTION = RCIN1 and so on)
# connect to the mavlink endpoint
master = mavutil.mavlink_connection('udpin:0.0.0.0:14551')
# Wait a heartbeat before sending commands
master.wait_heartbeat()
def set_rc_channels_pwm(channels_list):
""" Sets all RC channels PWM values
Args:
channels_list (List<int>): Channel pwm value 1100-1900
"""
# https://mavlink.io/en/messages/common.html#RC_CHANNELS_OVERRIDE
master.mav.rc_channels_override_send(
master.target_system, # target_system
master.target_component, # target_component
*channels_list) # RC channel list, in microseconds.
# Cycle PWMs up and down slowly between 1300 and 1700
delta = 1
value = 1500
while True:
value = value + delta
if value > 1700:
delta = -1
elif value < 1300:
delta = 1
# Mavlink 2 supports up to 18 channels
# sends a list with 18 times "value"
values_list = [value for i in range(18)]
set_rc_channels_pwm(values_list)
time.sleep(0.1)
print(value)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment