pub struct AttitudeSetpoint {
pub type_mask: u8,
pub q: [f32; 4],
pub body_roll_rate: f32,
pub body_pitch_rate: f32,
pub body_yaw_rate: f32,
pub thrust: f32,
}Expand description
A single SET_ATTITUDE_TARGET payload, frame-independent.
This is a transport-agnostic data value, NOT a controller: building one and
sending it is one fire-and-forget MAVLink frame. It owns no flight state,
mode, or schedule — the caller owns the policy around it (the autopilot
accepts these only in its attitude/offboard mode, and a command stream is a
heartbeat the caller must re-send well above the decay rate). The builder
validates that every field the type_mask does NOT ignore is finite, that a
commanded attitude is a unit quaternion, and that a commanded thrust is
within the normalized range, so a NaN / out-of-range command can never reach
the wire on an active axis.
Fields§
§type_mask: u8The type_mask ignore bits (ATTITUDE_TARGET_TYPEMASK_*). A set bit
ignores that axis. The high bits above the defined field are rejected so
a malformed mask cannot smuggle unknown semantics to the autopilot.
q: [f32; 4]Attitude quaternion (w, x, y, z), MAVLink order; zero rotation is
(1, 0, 0, 0). Meaningful only while ATTITUDE_IGNORE is clear.
body_roll_rate: f32Body roll rate, rad/s. Ignored when BODY_ROLL_RATE_IGNORE is set.
body_pitch_rate: f32Body pitch rate, rad/s. Ignored when BODY_PITCH_RATE_IGNORE is set.
body_yaw_rate: f32Body yaw rate, rad/s. Ignored when BODY_YAW_RATE_IGNORE is set.
thrust: f32Collective thrust, normalized 0..1 (-1..1 for reverse-thrust
vehicles). Ignored when THROTTLE_IGNORE is set.
Implementations§
Source§impl AttitudeSetpoint
impl AttitudeSetpoint
Sourcepub fn validate(&self) -> Result<(), SetpointError>
pub fn validate(&self) -> Result<(), SetpointError>
Validate the setpoint, returning the first problem found. Mirrors
GuidedSetpoint::validate so an out-of-range command is refused at
construction:
- the
type_maskcarries no bit outside the defined field, and - every numeric field on an axis the mask does NOT ignore is finite, and
- a commanded attitude is a unit quaternion, and
- a commanded thrust is within the normalized
-1..=1range.
An ignored axis is not checked (the autopilot disregards it), so a pure body-rate command with a NaN left in the (ignored) quaternion is accepted — but a NaN or out-of-range value on an active axis is rejected.
Sourcepub fn build_message(
&self,
target_system: u8,
target_component: u8,
) -> Result<MavMessage, SetpointError>
pub fn build_message( &self, target_system: u8, target_component: u8, ) -> Result<MavMessage, SetpointError>
Validate, then build the typed MavMessage for this setpoint. The
target_system / target_component address the vehicle; time_boot_ms
is fixed at 0 (the autopilot does not require a monotonic stamp on an
attitude setpoint; ArduPilot ignores it on the inbound path). The actual
X.25 CRC is folded with ATTITUDE_TARGET_CRC_EXTRA (49) by the typed
serializer, identical to what this builder’s own encoder would emit.