1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/// Example demonstrating Lighthouse geometry persistence
///
/// This example shows how to persist lighthouse geometry and calibration data
/// to the Crazyflie's permanent storage.
///
/// IMPORTANT: This example assumes geometry/calibration data has already been
/// written to the Crazyflie's RAM via the memory subsystem (not shown here).
///
/// In a real scenario, you would:
/// 1. Estimate or load geometry data
/// 2. Write it to RAM via memory subsystem
/// 3. Use this persist function to save to permanent storage
///
/// REQUIREMENTS:
/// - Crazyflie with Lighthouse deck
/// - Geometry/calibration data already in RAM
use crazyflie_lib::Crazyflie;
use crazyflie_lib::crazyflie_link::LinkContext;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
env_logger::init();
let link_context = LinkContext::new();
// Connect to Crazyflie
let uri = std::env::var("CFURI").unwrap_or_else(|_| "radio://0/80/2M/E7E7E7E7E7".to_string());
println!("Connecting to {} ...", uri);
let crazyflie = Crazyflie::connect_from_uri(&link_context, &uri, crazyflie_lib::NoTocCache).await?;
println!("Connected!");
println!("\nThis example demonstrates the persist API.");
println!("NOTE: Geometry/calibration data must already be in RAM (via memory subsystem)");
// Example: Persist geometry for base stations 0 and 1, calibration for base station 0
let geo_base_stations = vec![0, 1]; // Persist geometry for BS 0 and 1
let calib_base_stations = vec![0]; // Persist calibration for BS 0
println!(
"\nPersisting geometry for base stations: {:?}",
geo_base_stations
);
println!(
"Persisting calibration for base stations: {:?}",
calib_base_stations
);
// Persist data (sends command and waits for confirmation with 5 second timeout)
println!("Persisting data and waiting for confirmation...");
match crazyflie
.localization
.lighthouse
.persist_lighthouse_data(&geo_base_stations, &calib_base_stations)
.await
{
Ok(true) => {
println!("✓ Data persisted successfully!");
}
Ok(false) => {
println!("✗ Persistence failed!");
}
Err(e) => {
println!("✗ Error: {}", e);
}
}
println!("\nExample complete!");
Ok(())
}