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 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) -> impl Stream<Item = (String, Value)> + use<>
pub async fn watch_change(&self) -> 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.