Sending Manual Messages to ROV2

I have some questions about the Send Manual Control example code: Pymavlink · GitBook

master.mav.manual_control_send(
    master.target_system,
    500,
    -500,
    250,
    500,
    0)

# To active button 0 (first button), 3 (fourth button) and 7 (eighth button)
# It's possible to check and configure this buttons in the Joystick menu of QGC
buttons = 1 + 1 << 3 + 1 << 7
master.mav.manual_control_send(
    master.target_system,
    0,
    0,
    0,
    0,
    buttons)

What is the purpose of “buttons” in this code? My current goal is to be able to write and run a python program on my laptop to move the tethered ROV2 without QGroundControl or my XBox controller. I did some reading and what I found was that buttons is " A bitfield corresponding to the joystick buttons’ current state". That doesn’t mean a whole lot to me. Can someone please explain to me what is happening in that example code?

Hi Amanda,

Since this is the manual_control example, it explains how the user can create fake manual inputs for the ROV, like joystick movements and buttons press. So, imagine that your ROV is running autonomously and your algorithm needs to increase the gain, or change the camera position or turn on the lights, this functions are usually done via joystick buttons, and this example shows how this can be accomplished with pymavlink.
As the example points, the joystick buttons are configured via QGC, so you need to be sure that this buttons do before using it.

Okay! I think that makes sense. What about situations where there is a 0 in the button field? Is zero mapped to going forward or is zero just a place filler here? This is an example I found from you on a different thread that has a zero in the button field:

# Send a positive x value for 5 seconds.
# http://mavlink.org/messages/common#MANUAL_CONTROL
i = 0
while i < 10:
        master.mav.manual_control_send(
            master.target_system,
            500,
            0,
            0,
            0,
            0)
        time.sleep(0.5)
        i += 1

sys.exit(0)

Hi Amanda,

Well, 0 is 0x00 in hexadecimal that is 0b0000000000000000 in binary. If there is no valid bit to set, this represents that no buttons are pressed.

okay, I think I get that.

What is happening here? It looks like a bitwise operation of some sort to me, but I am not 100% sure on what it is doing. Can you please explain that particular line in your example?

Hi Amanda,

This is just a simple bit left operation. Take a look in Bit Shifts and Logical Shifts.

I played around with it and have figured out the buttons bit masking. Thank you! :slight_smile:

I also have a question about the number ranges that you have for the other fields. It looks like all except z are -1000, to 1000. What do those numbers represent? For example, do those numbers represent milliseconds? propeller turns? What are they?

Hi Amanda,

From mavlink documentation:

Field Name Type Description
target uint8_t The system to be controlled.
x int16_t X-axis, normalized to the range [-1000,1000]. A value of INT16_MAX indicates that this axis is invalid. Generally corresponds to forward(1000)-backward(-1000) movement on a joystick and the pitch of a vehicle.
y int16_t Y-axis, normalized to the range [-1000,1000]. A value of INT16_MAX indicates that this axis is invalid. Generally corresponds to left(-1000)-right(1000) movement on a joystick and the roll of a vehicle.
z int16_t Z-axis, normalized to the range [-1000,1000]. A value of INT16_MAX indicates that this axis is invalid. Generally corresponds to a separate slider movement with maximum being 1000 and minimum being -1000 on a joystick and the thrust of a vehicle. Positive values are positive thrust, negative values are negative thrust.
r int16_t R-axis, normalized to the range [-1000,1000]. A value of INT16_MAX indicates that this axis is invalid. Generally corresponds to a twisting of the joystick, with counter-clockwise being 1000 and clockwise being -1000, and the yaw of a vehicle.
buttons uint16_t A bitfield corresponding to the joystick buttons’ current state, 1 for pressed, 0 for released. The lowest bit corresponds to Button 1.

As you can see, both axis X and Y uses 1000 and -1000 to represent -100% and 100% in a centralized joystick.
For the Z axis, to hold support for old RC radios that are not centralized, value range is from 0 to 1000, where 0 is full negative thrust and 1000 positive thrust. With that in mind, the value for no thrust for the Z axis is 500.

Hi guys , I am working on an AUV and i am using the manual control send , the point is , i want to do a pitch and roll movement , and when i read the documentation about it, it included enabled_extensions that referred to these movements but unfortunately i don’t quiet how to use it , so is there an example code that illustrates how can i do roll and pitch movements using manual control api

Hi @islamwael,

We don’t have an example for roll+pitch control using MANUAL_CONTROL at this point. I would recommend using RC_CHANNEL_OVERRIDES instead, but if you really don’t want to then you can use the roll_pitch_toggle button functionality (discussed in the last link in my quote) to switch between (forward+lateral) and (roll+pitch) control.