Softivation

Drone starts turning on a velocity command in GUIDED mode

Why does ArduCopter change heading when you send only a velocity command in GUIDED mode? Here is how to keep the nose fixed with type_mask, or turn it the way you want.

Furkan IŞIKAY 5 min read

You send a velocity command to the drone from Python with pymavlink and never touch yaw. Still, as the drone moves forward, it starts turning at the same time, as if it's making its own decision.

Anyone who sends velocity alone in GUIDED mode runs into this behavior sooner or later. The cause is a single number you send along with the velocity command that says which fields to ignore.

Why the drone turns on its own

The intuitive assumption: if you ignore the heading fields, the autopilot won't touch the heading. ArduCopter does the exact opposite.

When both the yaw angle and the yaw rate are ignored, the autopilot doesn't hold the current heading target. It falls back to its own default yaw behavior, and the drone starts turning toward the direction of travel.

In the figure below you see two versions of the same eastward velocity command. In the top row both heading fields are ignored, and the nose turns toward the direction of travel along the way. In the bottom row the yaw rate field is set to 0 and the nose doesn't turn.

Same velocity command, two different paths for the nose

Top view: with both heading fields ignored, the drone turns its nose from 0 degrees to 90 degrees while moving east. With yaw rate sent as zero, the nose stays where it is
Where to look: the red nose tips. Both move east along the same line. In the top row the nose turns toward the direction of travel along the way; in the bottom row it doesn't.

If you send 3 m/s east, in the top-row case yaw starts around 0 degrees, rises up to 95 degrees, and settles around 90 degrees, that is, in the direction of travel.

When it happens

It happens when you send velocity only (vx, vy, vz) with SET_POSITION_TARGET_LOCAL_NED and mark both the yaw and yaw_rate fields as "ignore" in the type mask.

According to community reports, it shows up in ArduCopter 4.1 and later, and hasn't been reported in 4.0.7.

Three masks, the same velocity command

The three calls below send the same velocity command. The difference is the type_mask value, and the third one also writes an angle into the yaw field. 3527 ignores both the yaw and yaw_rate fields. 1479 ignores only the yaw field and writes 0 into yaw_rate. 2503 does the opposite: it ignores the yaw_rate field and uses the yaw field.

Python
from pymavlink import mavutil

def send_velocity(m, vy, mask, yaw=0.0):
    m.mav.set_position_target_local_ned_send(
        0, m.target_system, m.target_component,
        mavutil.mavlink.MAV_FRAME_LOCAL_NED,
        mask,
        0, 0, 0,        # x,y,z (ignore)
        0.0, vy, 0.0,   # vx,vy,vz
        0, 0, 0,        # ax,ay,az (ignore)
        yaw, 0.0)       # yaw (radyan), yaw_rate

# WRONG: yaw AND yaw_rate ignored -> ArduCopter turns toward the direction of travel
send_velocity(m, vy=3.0, mask=3527)

# CORRECT: yaw ignored, yaw_rate = 0 -> nose stays where it is
send_velocity(m, vy=3.0, mask=1479)

# Move while facing a set heading: yaw_rate ignored, the yaw field is used
# (yaw=0.0 means north; if you send 2503 with yaw=0.0 the drone turns north)
send_velocity(m, vy=3.0, mask=2503, yaw=1.5708)   # 90 degrees = east

If you want the nose to stay where it is, use 1479: since the turn rate is 0, the drone moves while facing whichever way it was already facing. 2503 turns the nose to the angle you write in the yaw field. This field is in radians, and 0 means north. If you leave the yaw field at 0.0 and send 2503, the drone turns north before moving. If you want to move while facing a specific direction, use 2503 and write that angle into the yaw field.

Example: In a swarm flight you shift the drone east to keep its place in the formation, and the camera on the nose needs to keep looking at the target. If you send velocity with 3527, the drone turns its nose toward the direction of travel as it slides, and the camera loses the target. If you send 1479, the nose stays where it is, the drone slides sideways, and the camera keeps looking the same way.

Error Messages and Their Meanings

This behavior doesn't print a console error; it happens silently. Below is the exact wording users on the ArduPilot forum use when describing it.

the drone starts rotating if the y velocity component, v_y, is non-zero

Cause: when the yaw and yaw_rate fields are both ignored and vy is nonzero, ArduCopter switches to its default yaw behavior and turns toward the direction of travel. Fix: don't ignore both fields at once. To hold the current heading, send type_mask 1479. To face a specific angle, send 2503 and write the angle into the yaw field.

We go deeper into this topic in the course

In the Drone Control with Python from Scratch course we go line by line through why type_mask behaves this way bit by bit, the ModeGuided::set_yaw_state_rad function in the source code, and board-specific differences.

Was this article helpful?

Free resourceTEKNOFEST UAV software readiness checklistCheck off your UAV software readiness stage by stage on a printable list.