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//! | Link Service | Full |
19//! | Localization | Full |
20//! | Log | Full (V2) |
21//! | Memory | Partial |
22//! | Param | Full(V2) |
23//! | Platform | Full |
24//! | Supervisor | Full (info and command channels) |
25//!
26//! ## Compatibility
27//!
28//! This crate is compatible with Crazyflie protocol versions [`MIN_SUPPORTED_PROTOCOL_VERSION`]
29//! to [`MAX_SUPPORTED_PROTOCOL_VERSION`]. The Crazyflie guarantees backward compatibility for one
30//! protocol version, so this library will work with both the current and next protocol version.
31//!
32//! ## Usage
33//!
34//! The basic procedure to use the lib is:
35//! - Find the link URI to connect, either by scanning or as a config or user input
36//! - Create a Crazyflie object from the URI or a connected Link, this will connect to the Crazyflie and initializes
37//! the subsystems
38//! - Subsystems are available as public fields of the [Crazyflie] struct.
39//! - Use the subsystems in the Crazyflie object to control the Crazyflie
40//! - Drop the Crazyflie object or call [crazyflie::Crazyflie::disconnect()]
41//!
42//! All subsystems functions are only taking an un-mutable reference to self (`&self`), the intention is for the
43//! Crazyflie object to be shared between tasks using `Arc<>` or `Rc<>`.
44//!
45//! For example:
46//! ``` no_run
47//! # async fn test() -> Result<(), Box<dyn std::error::Error>> {
48//! let link_context = crazyflie_lib::crazyflie_link::LinkContext::new();
49//!
50//! // Scan for Crazyflies on the default address
51//! let found = link_context.scan([0xE7; 5]).await?;
52//!
53//! if let Some(uri) = found.first() {
54//! let cf = crazyflie_lib::Crazyflie::connect_from_uri(
55//! &link_context,
56//! uri,
57//! crazyflie_lib::NoTocCache
58//! ).await?;
59//!
60//! println!("List of params variables: ");
61//! for name in cf.param.names() {
62//! println!(" - {}", name);
63//! }
64//!
65//! println!("List of log variables: ");
66//! for name in cf.param.names() {
67//! println!(" - {}", name);
68//! }
69//!
70//! cf.disconnect().await;
71//! }
72//! # Ok(())
73//! # }
74//! ```
75//!
76//! ## Relation to the crazyflie-link and crazyradio crates
77//!
78//! Types from the [crazyflie-link] crate appear in this crate's public API (for example
79//! [`crazyflie_link::LinkContext`] and [`crazyflie_link::Connection`] in
80//! [`Crazyflie::connect_from_uri()`] and [`Crazyflie::connect_from_link()`]), which makes
81//! crazyflie-link a *public dependency*: code using this crate needs to name its types. To
82//! avoid a separate, possibly version-mismatched crazyflie-link dependency downstream, the
83//! crate is re-exported at [`crazyflie_link`] — use it through this path instead of adding
84//! a direct dependency. The crazyradio crate is reachable the same way, as
85//! `crazyflie_lib::crazyflie_link::crazyradio`.
86//!
87//! This is a supported part of the API: the re-exported crates only move to
88//! semver-incompatible versions in a semver-incompatible release of this crate.
89//!
90//! ## Cargo features
91//!
92//! - **packet_capture** - Enable CRTP packet capture in the link (Unix only). Forwards to
93//! the crazyflie-link feature of the same name, see `crazyflie_link::capture`.
94//!
95//! [crazyflie-link]: https://crates.io/crates/crazyflie-link
96
97#![warn(missing_docs)]
98
99mod crazyflie;
100mod crtp_utils;
101mod error;
102mod value;
103
104pub mod subsystems;
105
106/// Re-export of the exact [`crazyflie_link`] crate version this crate was built against.
107///
108/// crazyflie-link is a public dependency of this crate (its types appear in our API,
109/// e.g. [`crazyflie_link::LinkContext`]). Use this re-export instead of a direct
110/// crazyflie-link dependency to guarantee a single, version-matched copy in your build;
111/// the crazyradio crate is likewise available as
112/// `crazyflie_lib::crazyflie_link::crazyradio`.
113///
114/// Supported API: the re-exported crates only change incompatibly in a
115/// semver-incompatible release of this crate.
116pub use crazyflie_link;
117
118pub use crate::crazyflie::Crazyflie;
119pub use crate::error::{Error, Result};
120pub use crate::value::{Value, ValueType};
121pub use crate::crtp_utils::TocCache;
122pub use crate::crtp_utils::NoTocCache;
123
124/// Minimum supported protocol version
125///
126/// see [the crate documentation](crate#compatibility) for more information.
127pub const MIN_SUPPORTED_PROTOCOL_VERSION: u8 = 12;
128
129/// Maximum supported protocol version
130///
131/// see [the crate documentation](crate#compatibility) for more information.
132pub const MAX_SUPPORTED_PROTOCOL_VERSION: u8 = MIN_SUPPORTED_PROTOCOL_VERSION + 1;