Home        Store        Docs        Blog

Send Rc to Pixhawk

Hello friends,I want to send rc values to Pixhawk from Raspberry Pi,I found this code but ı want to serial communication instead of Udp how can ı change this code thanks a lot

Import mavutil

from pymavlink import mavutil

Create the connection

master = mavutil.mavlink_connection(‘udpin:’)

Wait a heartbeat before sending commands


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
id (TYPE): Channel ID
pwm (int, optional): Channel pwm value 1100-1900
if id < 1:
print(“Channel does not exist.”)

# 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.target_system,                # target_system
        master.target_component,             # target_component
        *rc_channel_values)                  # RC channel list, in microseconds.

Set some roll

set_rc_channel_pwm(2, 1600)

Set some yaw

set_rc_channel_pwm(4, 1600)

replace the connection string: udpin: -> /dev/ttACM0 or whatever your serial port is.

master = mavutil.mavlink_connection(‘/dev/ttyACM0’)

thanks a lot