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