Skip to main content

crazyflie_lib/
lib.rs

1//! # Crazyflie library
2//!
3//! This crate allows to connect, communicate with and control the Crazyflie using the [crazyflie-link] crate
4//! to open a communication link. The link implementation only supports radio for now, but more will be implemented
5//! in the future (at least USB).
6//!
7//! ## Status
8//!
9//! The crate aims at implementing a Rust API to control the Crazyflie. The Crazyflie functionalities are implemented in
10//! subsystems. The current status is:
11//!
12//! | Subsystem | Support |
13//! |-----------|---------|
14//! | App channel | Full |
15//! | Commander | Full |
16//! | Console | Full |
17//! | High-level Commander | Full |
18//! | Localization | Full |
19//! | Log | Full (V2) |
20//! | Memory | None |
21//! | Param | Full(V2) |
22//! | Platform | Full |
23//!
24//! ## Compatibility
25//!
26//! This crate is compatible with Crazyflie protocol versions [`MIN_SUPPORTED_PROTOCOL_VERSION`]
27//! to [`MAX_SUPPORTED_PROTOCOL_VERSION`]. The Crazyflie guarantees backward compatibility for one
28//! protocol version, so this library will work with both the current and next protocol version.
29//!
30//! ## Usage
31//!
32//! The basic procedure to use the lib is:
33//!  - Find the link URI to connect, either by scanning or as a config or user input
34//!  - Create a Crazyflie object from the URI or a connected Link, this will connect to the Crazyflie and initializes
35//!    the subsystems
36//!  - Subsystems are available as public fields of the [Crazyflie] struct.
37//!  - Use the subsystems in the Crazyflie object to control the Crazyflie
38//!  - Drop the Crazyflie object or call [crazyflie::Crazyflie::disconnect()]
39//!
40//! All subsystems functions are only taking an un-mutable reference to self (`&self`), the intention is for the
41//! Crazyflie object to be shared between tasks using `Arc<>` or `Rc<>`.
42//!
43//! For example:
44//! ``` no_run
45//! # async fn test() -> Result<(), Box<dyn std::error::Error>> {
46//! let link_context = crazyflie_link::LinkContext::new();
47//!
48//! // Scan for Crazyflies on the default address
49//! let found = link_context.scan([0xE7; 5]).await?;
50//!
51//! if let Some(uri) = found.first() {
52//!     let cf = crazyflie_lib::Crazyflie::connect_from_uri(
53//!         &link_context,
54//!         uri,
55//!         crazyflie_lib::NoTocCache
56//!     ).await?;
57//!
58//!     println!("List of params variables: ");
59//!     for name in cf.param.names() {
60//!         println!(" - {}", name);
61//!     }
62//!
63//!     println!("List of log variables: ");
64//!     for name in cf.param.names() {
65//!         println!(" - {}", name);
66//!     }
67//!
68//!     cf.disconnect().await;
69//! }
70//! # Ok(())
71//! # }
72//! ```
73//!
74//! [crazyflie-link]: https://crates.io/crates/crazyflie-link
75
76#![warn(missing_docs)]
77
78mod crazyflie;
79mod crtp_utils;
80mod error;
81mod value;
82
83pub mod subsystems;
84
85pub use crate::crazyflie::Crazyflie;
86pub use crate::error::{Error, Result};
87pub use crate::value::{Value, ValueType};
88pub use crate::crtp_utils::TocCache;
89pub use crate::crtp_utils::NoTocCache;
90
91/// Minimum supported protocol version
92///
93/// see [the crate documentation](crate#compatibility) for more information.
94pub const MIN_SUPPORTED_PROTOCOL_VERSION: u8 = 10;
95
96/// Maximum supported protocol version
97///
98/// see [the crate documentation](crate#compatibility) for more information.
99pub const MAX_SUPPORTED_PROTOCOL_VERSION: u8 = MIN_SUPPORTED_PROTOCOL_VERSION + 1;