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>
impl Trajectory<'static>
Sourcepub fn from_rth_plan_entry(
entry: &RthPlanEntry,
start: Vector3,
) -> Result<Self, RthTrajectoryError>
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<'_>
impl Trajectory<'_>
Sourcepub fn clear(&mut self)
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.
Sourcepub fn cut_at(&mut self, time_sec: f32) -> Result<(), TrajectoryBuilderError>
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.
Sourcepub fn replace_end_to_land_at(
&mut self,
stats: &TrajectoryStats,
new_landing_position: Vector3,
new_landing_velocity: f32,
) -> Result<TrajectoryStats, LandingError>
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.
Sourcepub 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>
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<'_>
impl Trajectory<'_>
Sourcepub fn propose_takeoff_time_sec(
&self,
min_ascent: f32,
speed: f32,
acceleration: f32,
) -> f32
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.
Sourcepub fn propose_landing_time_sec(
&self,
preferred_descent: f32,
verticality_threshold: f32,
) -> f32
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>
impl Trajectory<'static>
Sourcepub fn from_vec(bytes: Vec<u8>) -> Result<Self, TrajectoryError>
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>
impl<'a> Trajectory<'a>
Sourcepub fn from_buffer(bytes: &'a [u8]) -> Result<Self, TrajectoryError>
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.
Sourcepub fn from_binary_file(
file: &BinaryFile<'a>,
) -> Result<Option<Self>, TrajectoryError>
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.
Sourcepub fn into_owned(self) -> Trajectory<'static>
pub fn into_owned(self) -> Trajectory<'static>
The trajectory with its bytes owned, copying them if they are borrowed.
Sourcepub fn bytes(&self) -> &[u8] ⓘ
pub fn bytes(&self) -> &[u8] ⓘ
The bytes of the trajectory, as in the body of a trajectory block.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Whether the trajectory is empty: it has no bytes, or its scale is zero.
Sourcepub const fn scale(&self) -> f32
pub const fn scale(&self) -> f32
The scale of the coordinates: each unit is this many millimeters.
Sourcepub fn start_position(&self) -> Vector3WithYaw
pub fn start_position(&self) -> Vector3WithYaw
The position at time zero.
Sourcepub fn end_position(&self) -> Vector3WithYaw
pub fn end_position(&self) -> Vector3WithYaw
The position after the end of the trajectory.
Sourcepub fn total_duration_msec(&self) -> u32
pub fn total_duration_msec(&self) -> u32
The total duration of the trajectory, in milliseconds.
Sourcepub fn total_duration_sec(&self) -> f32
pub fn total_duration_sec(&self) -> f32
The total duration of the trajectory, in seconds.
Sourcepub fn segment_at(&self, time_sec: f32) -> (TrajectoryPlayerState, f32)
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.
Sourcepub fn axis_aligned_bounding_box(&self) -> BoundingBox
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.