Created
December 2, 2019 19:36
-
-
Save Williangalvani/af1906aa1238a58103d6c30f6004e320 to your computer and use it in GitHub Desktop.
code to demonstrate weird behavior of ArduSub master
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#This makes my thrusters go insane! | |
# Import mavutil | |
from pymavlink import mavutil | |
import time | |
# Create the connection | |
master = mavutil.mavlink_connection('udpin:0.0.0.0:14551') | |
# Wait a heartbeat before sending commands | |
master.wait_heartbeat() | |
# Create a function to send RC values | |
# More information about Joystick channels | |
# here: https://www.ardusub.com/operators-manual/rc-input-and-output.html#rc-inputs | |
def set_rc_channel_pwm(id, pwm=1500): | |
""" Set RC channel pwm value | |
Args: | |
id (TYPE): Channel ID | |
pwm (int, optional): Channel pwm value 1100-1900 | |
""" | |
if id < 1: | |
print("Channel does not exist.") | |
return | |
# We only have 8 channels | |
# https://mavlink.io/en/messages/common.html#RC_CHANNELS_OVERRIDE | |
if id < 9: | |
rc_channel_values = [65535 for _ in range(8)] | |
rc_channel_values[id - 1] = pwm | |
master.mav.rc_channels_override_send( | |
master.target_system, # target_system | |
master.target_component, # target_component | |
*rc_channel_values) # RC channel list, in microseconds. | |
# Set some roll | |
set_rc_channel_pwm(1, 1500) | |
set_rc_channel_pwm(2, 1500) | |
set_rc_channel_pwm(3, 1500) | |
set_rc_channel_pwm(4, 1500) | |
set_rc_channel_pwm(5, 1500) | |
set_rc_channel_pwm(6, 1500) | |
set_rc_channel_pwm(7, 1500) | |
set_rc_channel_pwm(8, 1500) | |
master.mav.command_long_send( | |
master.target_system, | |
master.target_component, | |
mavutil.mavlink.MAV_CMD_COMPONENT_ARM_DISARM, | |
0, | |
1, 0, 0, 0, 0, 0, 0) | |
while True: | |
time.sleep(1) | |
set_rc_channel_pwm(3, 1526) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment