Home        Store        Learn        Blog

When Python runs the "send RC" script, the result is incorrect

I used Send RC ( Pymavlink · GitBook )in PythonBut when it runs, all thrusters are working, and there is no difference when the first parameter of ‘’‘set_rc_channel_pwm’’’ function is changed to 1, 3, 4, 5 and 6. What is the reason? How to solve it? My bluerov configuration is as follows:

  1. Pix model: fmuv2

  2. Firmware version is 4.0.3

  3. The version used by pymavlink is mavlink 2

Thanks for any suggestions!

Hi @newname, welcome to the forum :slight_smile:

It’s possible to check which value (1100 full reverse, 1500 stopped, 1900 full forwards) is being sent to the individual thrusters with the SERVO_OUTPUT_RAW mavlink message that the Pixhawk sends out. While your ROV is running and connected to the topside you can check the current values at (refresh the page to see the latest values), or you could receive messages to get the values from within your script (which you could then print).

A few questions on your setup:

  1. Which version of the companion software are you using? It should be shown in the web interface.
  2. Which flight mode are you operating in? I’d recommend using manual mode to start with, because it should do only what you directly tell it to (modes that have stabilisation engaged will try to correct the ROV orientation, which may not be desired when starting out testing)
  3. Are you sending regular control commands and also regular heartbeats, as per the Safety section on the Pymavlink page?
I have the same problem as him, this is my code (Pymavlink,mavlink 2): 
Example of how to use RC_CHANNEL_OVERRIDE messages to force input channels
in Ardupilot. These effectively replace the input channels (from joystick
or radio), NOT the output channels going to thrusters and servos.

# 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(channel_id, pwm=1500):
    """ Set RC channel pwm value
        channel_id (TYPE): Channel ID
        pwm (int, optional): Channel pwm value 1100-1900
    if channel_id < 1 or channel_id > 18:
        print("Channel does not exist.")

    # Mavlink 2 supports up to 18 channels:
    # https://mavlink.io/en/messages/common.html#RC_CHANNELS_OVERRIDE
    rc_channel_values = [65535 for _ in range(18)]
    rc_channel_values[channel_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)

# The camera pwm value sets the servo speed of a sweep from the current angle to
#  the min/max camera angle. It does not set the servo position.
# Set camera tilt to 45º (max) with full speed
set_rc_channel_pwm(8, 1900)

# Set channel 12 to 1500us
# This can be used to control a device connected to a servo output by setting the
# SERVO[N]_Function to RCIN12 (Where N is one of the PWM outputs)
set_rc_channel_pwm(12, 1500)

The companion machine I use is jetson nano, the ardusub version and pixhawk are the same as the author (4.0.3, fmuv2) .

Set some roll

set_rc_channel_pwm(2, 1600)#No matter what parameters are used, all motors are working!
I have carefully read the mavlink command (Messages (common) · MAVLink Developer Guide) description, but I don’t know how to change it, because how to change the parameters of the “set_rc_channel_pwm” function is useless. what should I do? thanks for your help !I run the ”Arm/Disarm the vehicle“ code and it all works and i use “manual” mode.