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. 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 and derivative history); 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
impl LateralController
Sourcepub fn control(
&mut self,
config: &LateralControllerConfig,
dt: f32,
target: LateralTarget,
estimate: LateralEstimate,
) -> Vec2
pub fn control( &mut self, config: &LateralControllerConfig, dt: f32, target: LateralTarget, estimate: LateralEstimate, ) -> Vec2
Desired horizontal acceleration toward target.
§Arguments
config- Gains and limits; assumed valid (LateralControllerConfig::validate). An invalid limit does not panic: a negative or NaNmax_integralacts 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.
§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);
assert!(accel_mps2.x > 0.0 && accel_mps2.y > 0.0);Trait Implementations§
Source§impl Clone for LateralController
impl Clone for LateralController
Source§impl Debug for LateralController
impl Debug for LateralController
Source§impl Default for LateralController
impl Default for LateralController
Source§impl PartialEq for LateralController
impl PartialEq for LateralController
impl StructuralPartialEq for LateralController
Auto Trait Implementations§
impl Freeze for LateralController
impl RefUnwindSafe for LateralController
impl Send for LateralController
impl Sync for LateralController
impl Unpin for LateralController
impl UnsafeUnpin for LateralController
impl UnwindSafe for LateralController
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.