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>
impl<T> View<T>
Sourcepub fn new(inner: T, rotation: UnitQuaternion<f32>) -> Self
pub fn new(inner: T, rotation: UnitQuaternion<f32>) -> Self
inner, run in the view rotation (the view’s frame expressed in the body frame).
Sourcepub fn tailsitter(inner: T) -> Self
pub fn tailsitter(inner: T) -> Self
inner, run in a tailsitter’s hover view (tailsitter_rotation).
Sourcepub fn rotation(&self) -> &UnitQuaternion<f32>
pub fn rotation(&self) -> &UnitQuaternion<f32>
The view’s frame expressed in the body frame.
Sourcepub fn into_inner(self) -> T
pub fn into_inner(self) -> T
Unwraps the component.
Trait Implementations§
Source§impl<T: Configurable> Configurable for View<T>
impl<T: Configurable> Configurable for View<T>
Source§type Config = <T as Configurable>::Config
type Config = <T as Configurable>::Config
Source§fn set_config(&mut self, config: T::Config) -> Result<(), InvalidConfig>
fn set_config(&mut self, config: T::Config) -> Result<(), InvalidConfig>
architecture.md#config-ownership).Source§impl<G: Guidance> Guidance for View<G>
impl<G: Guidance> Guidance for View<G>
Source§fn wind(&self) -> Option<WindEstimate>
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
fn guide( &mut self, dt: f32, regime: FlightRegime, input: &ControlInput, state: &VehicleState, ) -> Setpoint
Source§fn prime(&mut self, state: &VehicleState)
fn prime(&mut self, state: &VehicleState)
Source§fn saturation(&self) -> Saturation
fn saturation(&self) -> Saturation
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>
fn flight_mode(&self) -> Option<FlightModeReport>
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<S: Stabilizer> Stabilizer for View<S>
impl<S: Stabilizer> Stabilizer for View<S>
Source§fn stabilize(
&mut self,
dt: f32,
setpoint: &Setpoint,
state: &VehicleState,
) -> ControlOutput
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
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)
fn prime(&mut self, state: &VehicleState)
impl<T: PartialEq> StructuralPartialEq for View<T>
Source§impl<S: Tunable> Tunable for View<S>
impl<S: Tunable> Tunable for View<S>
Source§fn probe_frame(&self) -> UnitQuaternion<f32>
fn probe_frame(&self) -> UnitQuaternion<f32>
The inner component’s probe frame, in this view.
Source§fn start_probe(&mut self, target: S::Target, config: ProbeConfig)
fn start_probe(&mut self, target: S::Target, config: ProbeConfig)
target with config, from the next tick. A running probe is handed
back first. Read moreSource§fn probe(&self) -> Option<(S::Target, ProbeStatus)>
fn probe(&self) -> Option<(S::Target, ProbeStatus)>
Source§fn stop_probe(&mut self) -> Option<(S::Target, ProbeStatus)>
fn stop_probe(&mut self) -> Option<(S::Target, ProbeStatus)>
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> 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<S> CopterTunable for S
Source§impl<T> Params for T
impl<T> Params for T
Source§fn param_count(&self) -> usize
fn param_count(&self) -> usize
0..param_count().Source§fn param_name(&self, index: usize) -> Option<&'static str>
fn param_name(&self, index: usize) -> Option<&'static str>
index, or None if it is out of range.Source§fn param_at(&self, index: usize) -> Option<f32>
fn param_at(&self, index: usize) -> Option<f32>
index, or None if it is out of range.Source§fn set_param_at(&mut self, index: usize, value: f32) -> Result<(), ParamError>
fn set_param_at(&mut self, index: usize, value: f32) -> Result<(), ParamError>
index to value. Out of range is ParamError::Unknown. On error
the config is unchanged.Source§fn param_index(&self, name: &str) -> Option<usize>
fn param_index(&self, name: &str) -> Option<usize>
name, or None if there is no such param. On a
duplicate name, the first index.Source§fn param(&self, name: &str) -> Option<f32>
fn param(&self, name: &str) -> Option<f32>
name, or None if there is no such param.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.