Cannot move camera servo with pymavlink

Hi there,

I’m trying to move my camera servo via pymavlink. I tried two methods:

  1. one is to control by virtually pushing button. Here is my button configuration:

Here is my code snippet:

def mount_down():
    send_button_control(MOUNT_DOWN_BUTTON) #11 12 or whatever

def send_button_control(btn):
    buttons=1<<btn

    print(buttons)
    master.mav.manual_control_send(
        master.target_system,
        0,
        0,
        500,
        0,
        buttons)
    master.mav.manual_control_send(
        master.target_system,
        0,
        0,
        500,
        0,
        0)
  1. The other method that I`m using is to control camera servo channel:

Here is my camera channel config:

camera

if(event.axis==7): #light2 #camera control #this part is to handle joystick
                        if(abs(abs(event.value)-0.06)<0.06): #this part is to handle joystick
                            event.value=0 #this part is to handle joystick
                        throttlein=1500+event.value*600  #this part is to handle joystick
                        tested_functions.set_rc_channel_pwm(10,int(throttlein))  #sending channel input by mavlink

def set_rc_channel_pwm(channel_id, pwm=1500): #in library
    """ Set RC channel pwm value
    Args:
        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.")
        return

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

Is there anything that I am doing wrong?

Thanks for the answers in advance.

Hi @elchinaslanli,

There are a couple of ways to do this:

  1. Use the MountTilt RC Input functionality
    • as described in that link, this sets a speed for the mount to tilt in a given direction
    • using RC_CHANNELS_OVERRIDE can set an explicit value for the speed
      • this was seemingly your second approach, but you didn’t indicate how you were going about it, so it’s unclear whether you were setting a non-zero speed for long enough for the camera to move
    • using the MountTilt button press approach sets the maximum speed while the button is held down
      • this was your first approach, but your send_button_control function very quickly releases the button, so the camera would have only minimal time to move during each mount_down() call, so you would need to call the function repeatedly to notice the camera moving (or you could add a delay before releasing the button, which would be more efficient)
  2. Set the servo PWM directly to control the current target angle for the servo
    • this requires setting the SERVOn_FUNCTION parameter for the camera from MountTilt(7) to Disabled(0) (or disabling the camera tilt option in QGC)
1 Like

Hi again @EliotBR ,

According to this instruction of yours, I decided to define two separate functions:

One is for falling edge:

def send_button_control_push(btn):
    buttons=1<<btn
    master.mav.manual_control_send(
        master.target_system,
        0,
        0,
        500,
        0,
        buttons)

And the other one is for rising edge:

def send_button_control_release(btn):
    master.mav.manual_control_send(
        master.target_system,
        0,
        0,
        500,
        0,
        0)

Now the camera tilt is working.

I will try the second inctruction of yours when I`m available.

Thank you very much, @EliotBR <3 !

1 Like