Skip to main content

Commander

Struct Commander 

Source
pub struct Commander { /* private fields */ }
Expand description

§Low level setpoint subsystem

This struct implements methods to send low level setpoints to the Crazyflie. See the commander module documentation for more context and information.

Implementations§

Source§

impl Commander

§Legacy RPY+ setpoint

This setpoint was originally the only one present in the Crazyflie and has been (ab)used to implement the early position control and other assisted and semi-autonomous mode.

Source

pub async fn setpoint_rpyt( &self, roll: f32, pitch: f32, yawrate: f32, thrust: u16, ) -> Result<()>

Sends a Roll, Pitch, Yawrate, and Thrust setpoint to the Crazyflie.

By default, unless modified by parameters, the arguments are interpreted as:

  • roll - Desired roll angle (degrees)
  • pitch - Desired pitch angle (degrees)
  • yawrate - Desired yaw rate (degrees/second)
  • thrust - Thrust as a 16-bit value (0 = 0% thrust, 65535 = 100% thrust)

Note: Thrust is locked by default for safety. To unlock, send a setpoint with thrust = 0 once before sending nonzero thrust values.

Example:

cf.commander.setpoint_rpyt(0.0, 0.0, 0.0, 0);      // Unlocks thrust
cf.commander.setpoint_rpyt(0.0, 0.0, 0.0, 1000);   // Sets thrust to 1000
Source§

impl Commander

§Generic setpoints

These setpoints are implemented in such a way that they are easy to add in the Crazyflie firmware and in libs like this one. So if you have a use-case not covered by any of the existing setpoint do not hesitate to implement and contribute your dream setpoint :-).

Source

pub async fn setpoint_position( &self, x: f32, y: f32, z: f32, yaw: f32, ) -> Result<()>

Sends an absolute position setpoint in world coordinates, with yaw as an absolute orientation.

§Arguments
  • x - Target x position (meters, world frame)
  • y - Target y position (meters, world frame)
  • z - Target z position (meters, world frame)
  • yaw - Target yaw angle (degrees, absolute)
Source

pub async fn setpoint_velocity_world( &self, vx: f32, vy: f32, vz: f32, yawrate: f32, ) -> Result<()>

Sends a velocity setpoint in the world frame, with yaw rate control.

§Arguments
  • vx - Target velocity in x (meters/second, world frame)
  • vy - Target velocity in y (meters/second, world frame)
  • vz - Target velocity in z (meters/second, world frame)
  • yawrate - Target yaw rate (degrees/second)
Source

pub async fn setpoint_zdistance( &self, roll: f32, pitch: f32, yawrate: f32, zdistance: f32, ) -> Result<()>

Sends a setpoint with absolute height (distance to the surface below), roll, pitch, and yaw rate commands.

§Arguments
  • roll - Desired roll angle (degrees)
  • pitch - Desired pitch angle (degrees)
  • yawrate - Desired yaw rate (degrees/second)
  • zdistance - Target height above ground (meters)
Source

pub async fn setpoint_hover( &self, vx: f32, vy: f32, yawrate: f32, zdistance: f32, ) -> Result<()>

Sends a setpoint with absolute height (distance to the surface below), and x/y velocity commands in the body-fixed frame.

§Arguments
  • vx - Target velocity in x (meters/second, body frame)
  • vy - Target velocity in y (meters/second, body frame)
  • yawrate - Target yaw rate (degrees/second)
  • zdistance - Target height above ground (meters)
Source

pub async fn setpoint_manual( &self, roll: f32, pitch: f32, yawrate: f32, thrust_percentage: f32, rate: bool, ) -> Result<()>

Sends a manual control setpoint for roll, pitch, yaw rate, and thrust percentage.

If rate is false, roll and pitch are interpreted as angles (degrees). If rate is true, they are interpreted as rates (degrees/second).

§Arguments
  • roll - Desired roll (degrees or degrees/second, depending on rate)
  • pitch - Desired pitch (degrees or degrees/second, depending on rate)
  • yawrate - Desired yaw rate (degrees/second)
  • thrust_percentage - Thrust as a percentage (0 to 100)
  • rate - If true, use rate mode; if false, use angle mode
Source

pub async fn setpoint_stop(&self) -> Result<()>

Sends a STOP setpoint, immediately stopping the motors. The Crazyflie will lose lift and may fall.

Source

pub async fn notify_setpoint_stop( &self, remain_valid_milliseconds: u32, ) -> Result<()>

Notify the firmware that low-level setpoints have stopped.

This tells the Crazyflie to drop the current low-level setpoint priority, allowing the High-level commander (or other sources) to take control again.

§Arguments
  • remain_valid_milliseconds - How long (in ms) the last low-level setpoint should remain valid before it is considered stale. Use 0 to make the hand-off immediate; small non-zero values can smooth transitions if needed.
§Examples

Hand control back to the High-level commander after a manual low-level burst:

// ... you were sending low-level setpoints here ...
cmd.notify_setpoint_stop(0).await?; // allow HL commander to resume

Trait Implementations§

Source§

impl Debug for Commander

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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, 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.