Param

Struct Param 

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

§Access to the Crazyflie Param Subsystem

This struct provide methods to interact with the parameter subsystem. See the param module documentation for more context and information.

Implementations§

Source§

impl Param

Source

pub fn names(&self) -> Vec<String>

Get the names of all the parameters

The names contain group and name of the parameter variable formatted as “group.name”.

Source

pub fn get_type(&self, name: &str) -> Result<ValueType>

Return the type of a parameter variable or an Error if the parameter does not exist.

Source

pub fn is_writable(&self, name: &str) -> Result<bool>

Return true if he parameter variable is writable. False otherwise.

Return an error if the parameter does not exist.

Source

pub async fn set<T: Into<Value>>(&self, param: &str, value: T) -> Result<()>

Set a parameter value.

This function will set the variable value and wait for confirmation from the Crazyflie. If the set is successful Ok(()) is returned, otherwise the error code reported by the Crazyflie is returned in the error.

This function accepts any primitive type as well as the Value type. The type of the param variable is checked at runtime and must match the type given to the function, either the direct primitive type or the type contained in the Value enum. For example, to write a u16 value, both lines are valid:

cf.param.set("example.param", 42u16).await?;  // From primitive
cf.param.set("example.param", Value::U16(42)).await?;  // From Value

Return an error in case of type mismatch or if the variable does not exist.

Source

pub async fn get<T: TryFrom<Value>>(&self, name: &str) -> Result<T>
where <T as TryFrom<Value>>::Error: Debug,

Get param value

Get value of a parameter. This function takes the value from a local cache and so is quick.

Similarly to the set function above, the type of the param must match the return parameter. For example to get a u16 param:

let example: u16 = cf.param.get("example.param").await?;  // To primitive
dbg!(example);  // 42
let example: Value = cf.param.get("example.param").await?;  // To Value
dbg!(example);  // Value::U16(42)

Return an error in case of type mismatch or if the variable does not exist.

Source

pub async fn set_lossy(&self, name: &str, value: f64) -> Result<()>

Set a parameter from a f64 potentially loosing data

This function is a forgiving version of the set function. It allows to set any parameter of any type from a f64 value. This allows to set parameters without caring about the type and risking a type mismatch runtime error. Since there is no type or value check, loss of information can happen when using this function.

Loss of information can happen in the following cases:

  • When setting an integer, the value is truncated to the number of bit of the parameter
    • Example: Setting 257 to a u8 variable will set it to the value 1
  • Similarly floating point precision will be truncated to the parameter precision. Rounding is undefined.
  • Setting a floating point outside the range of the parameter is undefined.
  • It is not possible to represent accurately a u64 parameter in a f64.

Returns an error if the param does not exists.

Source

pub async fn get_lossy(&self, name: &str) -> Result<f64>

Get a parameter as a f64 independently of the parameter type

This function is a forgiving version of the get function. It allows to get any parameter of any type as a f64 value. This allows to get parameters without caring about the type and risking a type mismatch runtime error. Since there is no type or value check, loss of information can happen when using this function.

Loss of information can happen in the following cases:

  • It is not possible to represent accurately a u64 parameter in a f64.

Returns an error if the param does not exists.

Source

pub async fn watch_change(&self) -> impl Stream<Item = (String, Value)>

Get notified for all parameter value change

This function returns an async stream that will generate a tuple containing the name of the variable that has changed (in the form of group.name) and its new value.

There can be two reasons for a parameter to change:

  • Either the parameter was changed by a call to Param::set(). The notification will be generated when the Crazyflie confirms the parameter has been set.
  • Or it can be a parameter change in the Crazyflie itself. The Crazyflie will send notification packet for every internal parameter change.

Trait Implementations§

Source§

impl Debug for Param

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl !Freeze for Param

§

impl !RefUnwindSafe for Param

§

impl Send for Param

§

impl Sync for Param

§

impl Unpin for Param

§

impl !UnwindSafe for Param

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.