The gimbal protocol allows MAVLink control over the attitude/orientation of cameras (or other sensors) mounted on the drone
Gimbal Device: the actual gimbal device, hardware and software.
Gimbal Manager: software to deconflict gimbal messages and commands from different sources, and to abstract the capabilities of the Gimbal Device from gimbal users.
GIMBAL_DEVICE_ATTITUDE_STATUS
~/device/attitude_status
Send out its attitude and status at a regular rate, e.g. 10 Hz This message is a meant as broadcast
GIMBAL_MANAGER_STATUS
Current status about a high level gimbal manager. This message should be broadcast at a low regular rate (e.g. 5Hz).
GIMBAL_DEVICE_INFORMATION
Information about a low level gimbal. This message should be requested by the gimbal manager or a ground station using MAV_CMD_REQUEST_MESSAGE.
GIMBAL_MANAGER_INFORMATION
Information about a high level gimbal manager. This message should be requested by a ground station using MAV_CMD_REQUEST_MESSAGE.
GIMBAL_DEVICE_SET_ATTITUDE
Low level message to control a gimbal device's attitude. This message is to be sent from the gimbal manager to the gimbal device component.
GIMBAL_MANAGER_SET_ATTITUDE
High level message to control a gimbal's attitude.
GIMBAL_MANAGER_SET_PITCHYAW
High level message to control a gimbal's pitch and yaw angles.
Component ID of gimbal device to address (or 1–6 for non-MAVLink gimbal), 0 for all gimbal device components. Send command multiple times for more than one gimbal (but not all).
Messages with same value are from the same source (instance).
q
float[4]
Quaternion components: w, x, y, z. (1 0 0 0 is the null-rotation. The frame depends on whether the flag GIMBAL_MANAGER_FLAGS_YAW_LOCK is set)
angular_velocity_x
float
rad/s
invalid:NaN
X component of angular velocity. Positive is rolling to the right. NaN means ignore.
angular_velocity_y
float
rad/s
invalid:NaN
Y component of angular velocity. Positive is pitching up. NaN means ignore.
angular_velocity_z
float
rad/s
invalid:NaN
Z component of angular velocity. Positive is yawing to the right. NaN means ignore.
Mavlink GIMBAL_MANAGER_SET_ATTITUDE (282) High level message to control a gimbal's attitude. This message is to be sent to the gimbal manager , rate can be ignore by sending NaN.
# Image point (u, v), image size, and camera intrinsics (fx, fy, cx, cy)x_cam=(u-cx)/fxy_cam=(v-cy)/fyz_cam=1.0# 3D ray in camera frameray_camera=np.array([x_cam,y_cam,z_cam])ray_camera/=np.linalg.norm(ray_camera)# Convert to FLU/world frame (if needed)ray_world=camera_to_world@ray_camera# If using TF or known posequat=look_at_quaternion(ray_world)
import numpy as np
from scipy.spatial.transform import Rotation as R
def look_at_quaternion(forward_target, up=np.array([0, 0, 1])):
# Normalize direction
z = forward_target / np.linalg.norm(forward_target)
# Compute orthogonal axes
x = np.cross(up, z)
if np.linalg.norm(x) < 1e-5:
# up and forward are aligned → default right vector
x = np.array([1, 0, 0])
x /= np.linalg.norm(x)
y = np.cross(z, x)
rot_matrix = np.vstack((x, y, z)).T # FLU: forward=Z
return R.from_matrix(rot_matrix).as_quat() # [x, y, z, w]