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
impl Param
Sourcepub fn names(&self) -> Vec<String>
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”.
Sourcepub fn get_type(&self, name: &str) -> Result<ValueType>
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.
Sourcepub fn is_writable(&self, name: &str) -> Result<bool>
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.
Sourcepub fn has_extended_type(&self, name: &str) -> Result<bool>
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.
Sourcepub async fn set<T: Into<Value>>(&self, param: &str, value: T) -> Result<()>
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 ValueReturn an error in case of type mismatch or if the variable does not exist.
Sourcepub async fn get<T: TryFrom<Value>>(&self, name: &str) -> Result<T>
pub async fn get<T: TryFrom<Value>>(&self, name: &str) -> Result<T>
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.
Sourcepub async fn set_lossy(&self, name: &str, value: f64) -> Result<()>
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
257to au8variable will set it to the value1
- Example: Setting
- 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
u64parameter in af64.
Returns an error if the param does not exists.
Sourcepub async fn get_lossy(&self, name: &str) -> Result<f64>
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
u64parameter in af64.
Returns an error if the param does not exists.
Sourcepub async fn watch_change(
&self,
) -> Result<impl Stream<Item = (String, Value)> + use<>>
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.
Sourcepub async fn is_persistent(&self, name: &str) -> Result<bool>
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.
Sourcepub async fn get_extended_type(&self, name: &str) -> Result<u8>
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.
Sourcepub async fn get_default_value(&self, name: &str) -> Result<Value>
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.
Sourcepub async fn persistent_get_state(
&self,
name: &str,
) -> Result<PersistentParamState>
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)");
}Sourcepub async fn persistent_store(&self, name: &str) -> Result<()>
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?;Sourcepub async fn persistent_clear(&self, name: &str) -> Result<()>
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?;