Skip to main content

LateralController

Struct LateralController 

Source
pub struct LateralController { /* private fields */ }
Expand description

Horizontal position → velocity → acceleration cascade: turns a position target into a horizontal acceleration demand.

The position loop asks for position_p · error + target velocity, capped in magnitude at the target’s max_speed_mps (direction kept), and the velocity PID turns the velocity error into acceleration. With max_accel_mps2 set, the position loop slows toward the target along a braking curve instead of in proportion to the distance, and the PID tracks a shaped velocity target: it starts at the measured velocity, moves toward the demand at that rate, and its change is fed forward. With shaping off, brake_mps2 sets the braking curve alone, so a fast leg starts slowing in time to stop. Turning the acceleration into tilt is the guidance’s job (it depends on the airframe and its heading); CopterGuidance tilts by atan(|a| / g) toward it.

It holds only state (the velocity integral, derivative history, and shaped velocity target); gains and limits come from the LateralControllerConfig passed to each control call, so they can change between ticks without resetting the state.

Implementations§

Source§

impl LateralController

Source

pub fn control( &mut self, config: &LateralControllerConfig, dt: f32, target: LateralTarget, estimate: LateralEstimate, limit_mps2: Vec2, ) -> Vec2

Desired horizontal acceleration toward target.

§Arguments
  • config - Gains and limits; assumed valid (LateralControllerConfig::validate). An invalid limit does not panic: a negative or NaN max_integral acts as 0.
  • dt - Time step since the last update in seconds (must be positive and finite).
  • target - Desired position, feedforward velocity, and speed limit.
  • estimate - Current position and velocity.
  • limit_mps2 - The acceleration the caller last had to cap (e.g. at its tilt limit), or zero. The integral doesn’t grow in that direction, so it can’t wind up against a limit; it may still shrink or turn.
§Returns

Desired horizontal acceleration (x, y) in m/s², in the position frame. It is not saturated: the caller caps the tilt it turns into. A non-finite target or estimate gives zero (level) and leaves the integral untouched. The integral is clamped to max_integral to limit windup.

§Panics

If dt is not positive and finite.

§Examples
use stable_flight::controllers::{
    LateralController, LateralControllerConfig, LateralEstimate, LateralTarget,
};
use stable_flight::Vec2;

let config = LateralControllerConfig::default();
let mut controller = LateralController::default();
let target = LateralTarget {
    position_m: Vec2::new(5.0, 2.0), // 5 m north, 2 m east
    velocity_mps: Vec2::zeros(),
    max_speed_mps: 3.0,
};
let estimate = LateralEstimate {
    position_m: Vec2::new(4.0, 1.0),
    velocity_mps: Vec2::new(0.1, 0.05),
};

// Target is north-east: accelerate north (+x) and east (+y)
let accel_mps2 = controller.control(&config, 0.004, target, estimate, Vec2::zeros());
assert!(accel_mps2.x > 0.0 && accel_mps2.y > 0.0);

Trait Implementations§

Source§

impl Clone for LateralController

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for LateralController

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for LateralController

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl PartialEq for LateralController

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for LateralController

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> Scalar for T
where T: 'static + Clone + PartialEq + Debug,

Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.