pub struct AttitudeController { /* private fields */ }Expand description
Roll/pitch angle PID loop: turns roll/pitch setpoints in radians into body-rate setpoints for the
BodyRateController.
It holds only state (integral and derivative history); gains and limits come from the
AttitudeControllerConfig passed to each control call, so they can
change between ticks without resetting the state.
Implementations§
Source§impl AttitudeController
impl AttitudeController
Sourcepub fn control(
&mut self,
config: &AttitudeControllerConfig,
dt: f32,
desired_angles_rad: Vec2,
estimated_angles_rad: Vec2,
) -> Vec2
pub fn control( &mut self, config: &AttitudeControllerConfig, dt: f32, desired_angles_rad: Vec2, estimated_angles_rad: Vec2, ) -> Vec2
Computes desired angular rates to achieve target roll and pitch angles.
Uses a PID controller to convert angle errors into angular rates (rad/s) for the rate control loop. Input angles are clamped to [-max_angles_rad.x, max_angles_rad.x] for roll and [-max_angles_rad.y, max_angles_rad.y] for pitch. Output rates are clamped to [-max_rate_radps.x, max_rate_radps.x] for roll and [-max_rate_radps.y, max_rate_radps.y] for pitch.
§Arguments
config- Gains and limits; assumed valid (AttitudeControllerConfig::validate). An invalid limit does not panic: a negative or NaN limit acts as 0.dt- Time step since the last update in seconds (must be positive and finite).desired_angles_rad- Target roll/pitch in radians. Values beyondmax_angles_radsaturate to it, and NaN is treated as 0 (level).estimated_angles_rad- Current roll/pitch angles in radians
§Returns
Desired angular rates (roll rate, pitch rate) in radians/second, clamped to configured max_rate_radps limits
§Panics
If dt is not positive and finite.
§Examples
use stable_flight::controllers::{AttitudeController, AttitudeControllerConfig};
use stable_flight::Vec2;
let config = AttitudeControllerConfig::default();
let mut controller = AttitudeController::default();
let dt = 0.004;
let desired_angles_rad = Vec2::new(0.4, -0.15); // roll right, pitch down
let estimated_angles_rad = Vec2::new(0.1, 0.0); // current roll/pitch in radians
let angular_rates = controller.control(&config, dt, desired_angles_rad, estimated_angles_rad);
assert!(angular_rates.x > 0.0 && angular_rates.y < 0.0);Trait Implementations§
Source§impl Clone for AttitudeController
impl Clone for AttitudeController
Source§impl Debug for AttitudeController
impl Debug for AttitudeController
Source§impl Default for AttitudeController
impl Default for AttitudeController
Source§impl PartialEq for AttitudeController
impl PartialEq for AttitudeController
impl StructuralPartialEq for AttitudeController
Auto Trait Implementations§
impl Freeze for AttitudeController
impl RefUnwindSafe for AttitudeController
impl Send for AttitudeController
impl Sync for AttitudeController
impl Unpin for AttitudeController
impl UnsafeUnpin for AttitudeController
impl UnwindSafe for AttitudeController
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> Scalar for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.