Skip to main content

Trajectory

Struct Trajectory 

Source
pub struct Trajectory<'a> { /* private fields */ }
Expand description

The trajectory of a drone.

The bytes of the trajectory are borrowed when it is read from a show file in memory, and owned when they were built or modified.

Cutting a borrowed trajectory at the boundary of a segment narrows the borrowed bytes. Other modifications (cutting within a segment, replacing the end with a landing) copy the bytes that are kept, like the C library does. An alternative that would save that memory: keep borrowing the unmodified segments, and store the few modified or appended segments at the end inline, in a small fixed buffer. A cut rewrites at most one segment and a landing appends one, so this would need no allocation, at the cost of a more complex player.

Implementations§

Source§

impl Trajectory<'static>

Source

pub fn from_rth_plan_entry( entry: &RthPlanEntry, start: Vector3, ) -> Result<Self, RthTrajectoryError>

The trajectory of the action of an RTH plan entry, flown from the given position, which is where the plan expects the drone to be.

The trajectory holds the start position until the time of the entry and its delay, rises along the neck, moves to the target, holds the position for the delay after the action, and descends to the landing altitude if the entry has a landing velocity. The drone is expected to land when the trajectory ends.

§Errors

Returns an error if a coordinate or a duration is out of range, or memory could not be allocated.

Source§

impl Trajectory<'_>

Source

pub fn clear(&mut self)

Removes all segments of the trajectory, making it empty. A borrowed trajectory stops borrowing the show file; the show file is left intact.

Source

pub fn cut_at(&mut self, time_sec: f32) -> Result<(), TrajectoryBuilderError>

Cuts the trajectory at the given time, in seconds. The time is rounded to milliseconds. Cutting after the end does nothing.

Cutting at the boundary of a segment only drops the segments after it, so a borrowed trajectory keeps borrowing. Cutting within a segment rewrites that segment, so the bytes of a borrowed trajectory up to the end of that segment are copied.

§Errors

Returns an error if memory could not be allocated, or a control point of the rewritten segment is out of range. The trajectory is left intact then.

Source

pub fn replace_end_to_land_at( &mut self, stats: &TrajectoryStats, new_landing_position: Vector3, new_landing_velocity: f32, ) -> Result<TrajectoryStats, LandingError>

Replaces the end of the trajectory with a smooth landing at the given position, arriving there at rest, and returns the updated statistics. See replace_end_to_land_at_with_terminal_velocity.

§Errors

As for replace_end_to_land_at_with_terminal_velocity.

Source

pub fn replace_end_to_land_at_with_terminal_velocity( &mut self, stats: &TrajectoryStats, new_landing_position: Vector3, new_landing_velocity: f32, terminal_velocity: f32, ) -> Result<TrajectoryStats, LandingError>

Replaces the end of the trajectory after the landing time in the statistics with a cubic Bézier curve to the given position, and returns the statistics of the new trajectory: the given statistics, with the components that were calculated updated.

The duration of the landing segment is the vertical distance divided by new_landing_velocity, at most 60 seconds. The drone arrives at the landing position with terminal_velocity, downwards.

The bytes of a borrowed trajectory up to the landing time are copied.

§Errors

Returns an error if the statistics have no landing time, a velocity is invalid, the landing position is not below the position at the landing time, a coordinate is out of range, or memory could not be allocated. The trajectory is left intact then.

Source§

impl Trajectory<'_>

Source

pub fn propose_takeoff_time_sec( &self, min_ascent: f32, speed: f32, acceleration: f32, ) -> f32

Proposes a takeoff time for the trajectory, in seconds, assuming that the drone starts at the first point of the trajectory and takes off vertically by min_ascent, accelerating with acceleration up to speed and decelerating to a stop at the end. An infinite acceleration means constant speed during the entire takeoff.

Returns infinity if the settings are invalid or the trajectory never gets min_ascent above its first point. The result may be negative.

Source

pub fn propose_landing_time_sec( &self, preferred_descent: f32, verticality_threshold: f32, ) -> f32

Proposes a landing time for the trajectory, in seconds, assuming that the drone lands directly below the last point of the trajectory. The landing starts when the drone is above the last point by at most preferred_descent, on the last run of vertical segments of the trajectory; a segment is vertical if its start and end are not farther than verticality_threshold along the X and Y axes.

A preferred descent that is not positive and finite means landing at the end of the trajectory. A negative verticality threshold is treated as zero. The result is at most the duration of the trajectory.

Source§

impl Trajectory<'static>

Source

pub const fn new() -> Self

An empty trajectory at the origin.

Source

pub fn from_vec(bytes: Vec<u8>) -> Result<Self, TrajectoryError>

A trajectory that owns the given body of a trajectory block.

§Errors

Returns TrajectoryError::Corrupted if the body is malformed.

Source§

impl<'a> Trajectory<'a>

Source

pub fn from_buffer(bytes: &'a [u8]) -> Result<Self, TrajectoryError>

A trajectory that borrows the given body of a trajectory block.

§Errors

Returns TrajectoryError::Corrupted if the body is malformed.

Source

pub fn from_binary_file( file: &BinaryFile<'a>, ) -> Result<Option<Self>, TrajectoryError>

The trajectory of a show file, borrowing its bytes from the show file, or None if the show file has no trajectory.

§Errors

Returns an error if the trajectory block is truncated or malformed.

Source

pub fn into_owned(self) -> Trajectory<'static>

The trajectory with its bytes owned, copying them if they are borrowed.

Source

pub fn bytes(&self) -> &[u8] ⓘ

The bytes of the trajectory, as in the body of a trajectory block.

Source

pub fn is_empty(&self) -> bool

Whether the trajectory is empty: it has no bytes, or its scale is zero.

Source

pub const fn scale(&self) -> f32

The scale of the coordinates: each unit is this many millimeters.

Source

pub fn start_position(&self) -> Vector3WithYaw

The position at time zero.

Source

pub fn end_position(&self) -> Vector3WithYaw

The position after the end of the trajectory.

Source

pub fn total_duration_msec(&self) -> u32

The total duration of the trajectory, in milliseconds.

Source

pub fn total_duration_sec(&self) -> f32

The total duration of the trajectory, in seconds.

Source

pub fn segment_at(&self, time_sec: f32) -> (TrajectoryPlayerState, f32)

The segment that contains the given time, in seconds, with its derivatives calculated, and the relative time within the segment.

Source

pub fn axis_aligned_bounding_box(&self) -> BoundingBox

The axis-aligned bounding box of the segments of the trajectory. The intervals are empty (from infinity to minus infinity) if the trajectory has no segments.

Trait Implementations§

Source§

impl<'a> Clone for Trajectory<'a>

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<'a> Debug for Trajectory<'a>

Source§

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

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

impl Default for Trajectory<'static>

Source§

fn default() -> Self

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

impl<'a> PartialEq for Trajectory<'a>

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<'a> StructuralPartialEq for Trajectory<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for Trajectory<'a>

§

impl<'a> RefUnwindSafe for Trajectory<'a>

§

impl<'a> Send for Trajectory<'a>

§

impl<'a> Sync for Trajectory<'a>

§

impl<'a> Unpin for Trajectory<'a>

§

impl<'a> UnsafeUnpin for Trajectory<'a>

§

impl<'a> UnwindSafe for Trajectory<'a>

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.