Skip to main content

View

Struct View 

Source
pub struct View<T> { /* private fields */ }
Expand description

A Guidance or Stabilizer run in a body frame rotated by a constant.

rotation is the view’s frame expressed in the vehicle’s body frame. Each tick the inner component sees the state in the view (VehicleState::rotate_body); a viewed stabilizer’s moments are rotated back into the body frame for the mixer, and its per-axis saturation flags with them. Config (Configurable, so params too) and autotune probes (Tunable) pass through to the inner component, in view axes; the probes’ frame (Tunable::probe_frame) is the view, so the autotune supervisor (Autotune) judges its envelope in view axes too.

Wrap guidance and the stabilizer each in the same view, as ArduPilot builds each tailsitter controller on its view (see the module docs).

§Examples

use core::f32::consts::FRAC_PI_2;
use stable_flight::guidance::copter::{CopterGuidance, CopterGuidanceConfig};
use stable_flight::nalgebra::UnitQuaternion;
use stable_flight::stabilizers::copter::{CopterStabilizer, CopterStabilizerConfig};
use stable_flight::{AttitudeSetpoint, Setpoint, Stabilizer, VehicleState, View};

let guidance = View::tailsitter(CopterGuidance::new(CopterGuidanceConfig::default()));
let mut stabilizer = View::tailsitter(CopterStabilizer::new(CopterStabilizerConfig::default()));

// Hovering nose up is level in the view: no attitude error, so no moments.
let hover = VehicleState {
    attitude: UnitQuaternion::from_euler_angles(0.0, FRAC_PI_2, 0.0),
    ..Default::default()
};
let setpoint = Setpoint::Attitude(AttitudeSetpoint { thrust: 0.5, ..Default::default() });
let output = stabilizer.stabilize(0.004, &setpoint, &hover);
assert!(output.moments.norm() < 1e-5);

Implementations§

Source§

impl<T> View<T>

Source

pub fn new(inner: T, rotation: UnitQuaternion<f32>) -> Self

inner, run in the view rotation (the view’s frame expressed in the body frame).

Source

pub fn tailsitter(inner: T) -> Self

inner, run in a tailsitter’s hover view (tailsitter_rotation).

Source

pub fn rotation(&self) -> &UnitQuaternion<f32>

The view’s frame expressed in the body frame.

Source

pub fn inner(&self) -> &T

The wrapped component.

Source

pub fn into_inner(self) -> T

Unwraps the component.

Trait Implementations§

Source§

impl<T: Clone> Clone for View<T>

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<T: Configurable> Configurable for View<T>

Source§

type Config = <T as Configurable>::Config

The component’s config.
Source§

fn config(&self) -> &T::Config

The config the component flies.
Source§

fn set_config(&mut self, config: T::Config) -> Result<(), InvalidConfig>

Replaces the config if it is valid; otherwise keeps the current one and returns the error. Call it between ticks: the new config applies from the next tick, and runtime state (integrals, derivative history, timers) is kept. A changed integral gain rescales its integral so the I term carries over without a bump; across a zero gain the integral resets (architecture.md#config-ownership).
Source§

impl<T: Debug> Debug for View<T>

Source§

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

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

impl<G: Guidance> Guidance for View<G>

Source§

fn wind(&self) -> Option<WindEstimate>

The inner guidance’s: wind is a world quantity, so the view doesn’t rotate it.

Source§

fn guide( &mut self, dt: f32, regime: FlightRegime, input: &ControlInput, state: &VehicleState, ) -> Setpoint

Produces this tick’s inner-loop setpoint. Read more
Source§

fn prime(&mut self, state: &VehicleState)

Resets guidance and primes it from a known-good vehicle state. Read more
Source§

fn saturation(&self) -> Saturation

What the last guide call clipped to a limit. FlightLoop merges it into the tick’s TelemetryRecord::saturation. The default reports nothing.
Source§

fn flight_mode(&self) -> Option<FlightModeReport>

The flight mode the last guide call flew, for a guidance that flies more than one regime. FlightLoop puts it in an armed tick’s TelemetryRecord::flight_mode. The default, None, means copter only: the loop reports FlightModeReport::copter_only. A guidance that wraps another forwards this.
Source§

impl<T: PartialEq> PartialEq for View<T>

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<S: Stabilizer> Stabilizer for View<S>

Source§

fn stabilize( &mut self, dt: f32, setpoint: &Setpoint, state: &VehicleState, ) -> ControlOutput

Stabilizes in the view, then rotates the moments (and any cruise moments) back into the body frame.

Source§

fn saturation(&self) -> Saturation

The inner stabilizer’s report, its per-axis moments flags carried into body axes: a body axis is flagged when a saturated view axis feeds it (for a 90° view, the flags are relabeled).

Source§

fn prime(&mut self, state: &VehicleState)

Resets the stabilizer and primes it from a known-good vehicle state. Read more
Source§

impl<T: PartialEq> StructuralPartialEq for View<T>

Source§

impl<S: Tunable> Tunable for View<S>

Source§

fn probe_frame(&self) -> UnitQuaternion<f32>

The inner component’s probe frame, in this view.

Source§

type Target = <S as Tunable>::Target

Names a loop a stage can replace.
Source§

fn start_probe(&mut self, target: S::Target, config: ProbeConfig)

Starts a probe on target with config, from the next tick. A running probe is handed back first. Read more
Source§

fn probe(&self) -> Option<(S::Target, ProbeStatus)>

The current probe, if any: running, or finished and not yet stopped.
Source§

fn stop_probe(&mut self) -> Option<(S::Target, ProbeStatus)>

Ends the probe, handing the loop back to its controller if the probe still flies it, and returns its last status.

Auto Trait Implementations§

§

impl<T> Freeze for View<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for View<T>
where T: RefUnwindSafe,

§

impl<T> Send for View<T>
where T: Send,

§

impl<T> Sync for View<T>
where T: Sync,

§

impl<T> Unpin for View<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for View<T>
where T: UnsafeUnpin,

§

impl<T> UnwindSafe for View<T>
where T: UnwindSafe,

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<S> CopterTunable for S
where S: Configurable<Config = CopterStabilizerConfig> + Tunable<Target = TunedLoop>,

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> Params for T

Source§

fn param_count(&self) -> usize

Number of params; their indices are 0..param_count().
Source§

fn param_name(&self, index: usize) -> Option<&'static str>

The name of the param at index, or None if it is out of range.
Source§

fn param_at(&self, index: usize) -> Option<f32>

The value of the param at index, or None if it is out of range.
Source§

fn set_param_at(&mut self, index: usize, value: f32) -> Result<(), ParamError>

Sets the param at index to value. Out of range is ParamError::Unknown. On error the config is unchanged.
Source§

fn param_index(&self, name: &str) -> Option<usize>

The index of the param called name, or None if there is no such param. On a duplicate name, the first index.
Source§

fn param(&self, name: &str) -> Option<f32>

The value of the param called name, or None if there is no such param.
Source§

fn set_param(&mut self, name: &str, value: f32) -> Result<(), ParamError>

Sets the param called name to value. On error the config is unchanged.
Source§

fn visit_params(&self, f: &mut dyn FnMut(&'static str, f32))

Calls f with every param’s name and value, in index order.
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.