Skip to content

Attitude

The toolkit sends desired attitude and collective thrust to PX4. PX4 retains attitude/rate feedback and allocation. This mode requires a curated hover-thrust scale.

Force to rotation

Use the common translation errors and acceleration law:

\[ \begin{aligned} B&=a_{\mathrm{cmd}}-g e_3 \\ b_{3d}&=-B/\|B\|. \end{aligned} \]

Desired heading \(b_{1c}=(\cos\psi_d,\sin\psi_d,0)^\top\) fixes the remaining attitude:

\[ \begin{aligned} b_{2d}&=\frac{b_{3d}\times b_{1c}}{\|b_{3d}\times b_{1c}\|} \\ b_{1d}&=b_{2d}\times b_{3d} \\ R_d&=[b_{1d}\ b_{2d}\ b_{3d}]. \end{aligned} \]

\(R_d\) maps desired FRD axes into NED. The foundations explain degeneracy and the frame conventions. The runtime converts \(R_d\) to a normalized scalar-first quaternion \(q_d=(w,x,y,z)\), using trace/major-diagonal branches to avoid an unstable single formula near 180° rotations.

Collective projection and message

Collective uses the current body axis, not the norm of the desired specific force \(B=A/m\):

\[ \begin{aligned} u&=-B^\top R e_3 \\ u_T&=\operatorname{clip}_{[0,1]}\left(h u/g\right). \end{aligned} \]

VehicleAttitudeSetpoint.q_d contains the FRD-to-NED quaternion. thrust_body=(0,0,-u_T) is dimensionless; negative FRD Z means upward thrust. yaw_sp_move_rate contains desired trajectory yaw rate in rad/s. Only OffboardControlMode.attitude is enabled.

Hover scale \(h\) comes from px4_allocator.hover_thrust in vehicle YAML. Collective projection/clipping can reduce thrust during attitude error. PX4 runs attitude/rate feedback.

Timing, run, and diagnosis

Valid position/velocity and attitude are required. The outer timer (100 Hz by default) publishes after confirmed Offboard; jerk/snap are not needed to construct \(R_d\) here. Shared lifecycle behavior still applies.

In a separate repository-root shell, with a matching, already airborne SITL vehicle and no competing controller:

source ros2/runtime_env.sh
ros2 launch offboard_controllers se3.launch.py \
  vehicle:=gz_f450 trajectory:=line_x handoff:=attitude \
  publish_diagnostics:=true record:=true

Inspect desired/measured attitude, specific-force direction, normalized collective, downstream rates, and motor limits. The law rejects invalid hover calibration and degenerate force/heading geometry.

Read attitude_reference.cpp, wrench.cpp, and publication.cpp.