Skip to main content

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 fn has_extended_type(&self, name: &str) -> Result<bool>

Return true if the parameter has extended type information.

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. The first access will fetch the value from the Crazyflie. Subsequent accesses are served from a local cache and are 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, ) -> Result<impl Stream<Item = (String, Value)> + use<>>

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

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

Check if a parameter supports persistent storage

Returns true if the parameter can be stored in persistent storage, false otherwise.

Returns an error if the parameter does not exist.

Source

pub async fn get_extended_type(&self, name: &str) -> Result<u8>

Get the extended type flags of a parameter from the firmware

Returns a bitfield of extended type flags. Currently defined flags:

  • 0x01: PERSISTENT - parameter can be stored in persistent storage

This queries the firmware directly. For most use cases, is_persistent() is more convenient.

Returns an error if the parameter does not exist or does not have extended type information.

Source

pub async fn get_default_value(&self, name: &str) -> Result<Value>

Get the default value of a parameter as defined in the firmware

This retrieves the default value that the parameter has in the firmware, regardless of whether a different value has been stored in persistent storage.

Returns an error if the parameter does not exist or does not support getting default values.

Source

pub async fn persistent_get_state( &self, name: &str, ) -> Result<PersistentParamState>

Get the complete state of a persistent parameter

Returns the following information about a persistent parameter:

  • Whether a value is currently stored in persistent storage
  • The firmware’s default value
  • The stored value (if one exists)

Returns an error if the parameter does not exist or is not persistent.

§Example
let state = cf.param.persistent_get_state("ring.effect").await?;

println!("Default value: {:?}", state.default_value);
if state.is_stored {
    println!("Stored value: {:?}", state.stored_value.unwrap());
} else {
    println!("Using default (not stored)");
}
Source

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

Store the current value of a persistent parameter to persistent storage.

When a value is stored, it will be used as the parameter’s initial value on every subsequent boot, instead of the firmware default. Note that changing the parameter at runtime with set() does not update the stored value.

§Example
// First set the value you want to persist
cf.param.set("ring.effect", 10u8).await?;
 
// Then store it to persistent storage
cf.param.persistent_store("ring.effect").await?;
Source

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

Clear the stored value of a persistent parameter from persistent storage.

When cleared, the parameter will revert to the firmware default on every subsequent boot.

§Example
// Clear the stored value, reverting to default
cf.param.persistent_clear("ring.effect").await?;

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 !UnwindSafe for Param

§

impl Send for Param

§

impl Sync for Param

§

impl Unpin for Param

§

impl UnsafeUnpin 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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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.