Skip to main content

Vehicle

Struct Vehicle 

Source
pub struct Vehicle<L> { /* private fields */ }
Expand description

A MAVLink vehicle over a ByteLink, exposed through the pamoja device model.

A vehicle sends as a ground station (its own system and component id) and addresses a target vehicle. The target is learned from the first heartbeat unless it is pinned with with_target. Attach signing with with_signer and with_verifier.

Implementations§

Source§

impl<L: ByteLink> Vehicle<L>

Source

pub fn new(link: L, system_id: u8, component_id: u8) -> Self

Creates a vehicle client sending as the given ground-station identity.

The target vehicle defaults to system 1, component 1, and is updated from the first heartbeat seen during connect.

§Arguments
  • link - the byte link to the vehicle.
  • system_id - this ground station’s system id.
  • component_id - this ground station’s component id.
§Returns

The vehicle client, with signing off.

Source

pub fn with_target(self, system_id: u8, component_id: u8) -> Self

Pins the target vehicle’s system and component id instead of learning them.

§Arguments
  • system_id - the target vehicle’s system id.
  • component_id - the target vehicle’s component id.
§Returns

The vehicle, for chaining.

Source

pub fn with_signer(self, signer: Signer) -> Self

Signs every outgoing frame with signer.

§Arguments
  • signer - the signer to stamp outgoing frames with.
§Returns

The vehicle, for chaining.

Source

pub fn with_verifier(self, verifier: Verifier) -> Self

Verifies signed incoming frames with verifier, and rejects unsigned ones.

§Arguments
  • verifier - the verifier to check incoming signed frames with.
§Returns

The vehicle, for chaining.

Source

pub fn target_system(&self) -> u8

Returns the target vehicle’s system id.

§Returns

The target system id.

Source

pub fn target_component(&self) -> u8

Returns the target vehicle’s component id.

§Returns

The target component id.

Source

pub async fn send_heartbeat(&mut self) -> CoreResult<()>

Sends a ground-station heartbeat, which some autopilots require before they accept commands.

§Returns

Ok(()) once the heartbeat has been sent.

§Errors

Returns Error::Transport if the frame cannot be sent.

Source

pub async fn recv(&mut self) -> CoreResult<Report>

Reads the next telemetry report from the vehicle.

Unlike [Telemetry::next_frame], this treats a closed link as an error rather than an end of stream.

§Returns

The next decoded Report.

§Errors

Returns Error::Closed if the link ends, or Error::Transport on a link fault.

Source

pub async fn send_command( &mut self, command: u16, params: [f32; 7], ) -> CoreResult<u8>

Sends a command to the vehicle and awaits its result, retransmitting on timeout.

The command is sent as a COMMAND_LONG and matched to its COMMAND_ACK. An in-progress acknowledgement extends the wait; a missing acknowledgement resends the command with an incremented confirmation, up to the retry budget.

§Arguments
  • command - the MAV_CMD id.
  • params - the seven command parameters.
§Returns

The MAV_RESULT the vehicle reported, including a rejection such as DENIED.

§Errors

Returns Error::Transport if the command is not acknowledged within the retry budget or the link faults.

Source

pub async fn arm(&mut self, arm: bool) -> CoreResult<u8>

Arms or disarms the vehicle.

§Arguments
  • arm - true to arm, false to disarm.
§Returns

The MAV_RESULT of the arm command.

§Errors

As send_command.

Source

pub async fn set_mode( &mut self, base_mode: u8, custom_mode: u32, ) -> CoreResult<u8>

Requests a mode change.

§Arguments
  • base_mode - the MAV_MODE_FLAG base-mode bits.
  • custom_mode - the autopilot-specific custom mode.
§Returns

The MAV_RESULT of the mode command.

§Errors

As send_command.

Source

pub async fn takeoff(&mut self, altitude: f32) -> CoreResult<u8>

Commands a takeoff to an altitude.

§Arguments
  • altitude - the target altitude, in metres.
§Returns

The MAV_RESULT of the takeoff command.

§Errors

As send_command.

Source

pub async fn request_message(&mut self, message_id: u32) -> CoreResult<u8>

Asks the vehicle to emit one message, by id.

§Arguments
  • message_id - the id of the message to request.
§Returns

The MAV_RESULT of the request.

§Errors

As send_command.

Source

pub async fn set_message_interval( &mut self, message_id: u32, interval_us: i32, ) -> CoreResult<u8>

Sets how often the vehicle streams a message.

§Arguments
  • message_id - the id of the message.
  • interval_us - the send interval, in microseconds, or -1 to disable.
§Returns

The MAV_RESULT of the request.

§Errors

As send_command.

Source

pub async fn upload_mission( &mut self, items: &[MissionItemInt], ) -> CoreResult<()>

Uploads a mission plan to the vehicle.

Runs the mission protocol’s sender role: announces the count, answers each item request, and completes on the vehicle’s acknowledgement, retransmitting on timeout.

§Arguments
  • items - the mission items, in sequence order; the target ids, sequence numbers, and mission type are stamped on for you.
§Returns

Ok(()) once the vehicle accepts the plan.

§Errors

Returns Error::Transport if the transfer times out or the vehicle rejects the plan.

Source

pub async fn download_mission(&mut self) -> CoreResult<Vec<MissionItemInt>>

Downloads the vehicle’s mission plan.

Runs the mission protocol’s receiver role: requests the count, requests each item in order, re-requests an out-of-order item, and acknowledges completion, retransmitting on timeout.

§Returns

The mission items, in sequence order.

§Errors

Returns Error::Transport if the transfer times out or the link faults.

Trait Implementations§

Source§

impl<L: ByteLink> Actuator for Vehicle<L>

Source§

type Command = Setpoint

The command accepted by a single application, for example a setpoint.
Source§

async fn apply(&mut self, command: Setpoint) -> CoreResult<()>

Applies a command to the actuator. Read more
Source§

impl<L: ByteLink> Device for Vehicle<L>

Source§

fn id(&self) -> &str

Returns the stable identifier for this device. Read more
Source§

async fn connect(&mut self) -> CoreResult<()>

Opens the device and prepares it for use. Read more
Source§

async fn disconnect(&mut self) -> CoreResult<()>

Releases the device and any resources it holds. Read more
Source§

impl<L: ByteLink> Telemetry for Vehicle<L>

Source§

type Frame = Report

A single telemetry frame, for example a status or position report.
Source§

async fn next_frame(&mut self) -> CoreResult<Option<Report>>

Awaits the next telemetry frame. Read more

Auto Trait Implementations§

§

impl<L> Freeze for Vehicle<L>
where L: Freeze,

§

impl<L> RefUnwindSafe for Vehicle<L>
where L: RefUnwindSafe,

§

impl<L> Send for Vehicle<L>
where L: Send,

§

impl<L> Sync for Vehicle<L>
where L: Sync,

§

impl<L> Unpin for Vehicle<L>
where L: Unpin,

§

impl<L> UnsafeUnpin for Vehicle<L>
where L: UnsafeUnpin,

§

impl<L> UnwindSafe for Vehicle<L>
where L: 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> 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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.