use crazyflie_lib::crazyflie_link::LinkContext;
use crazyflie_lib::Crazyflie;
use std::f32::consts::PI;
use tokio::time::{sleep, Duration};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let context = LinkContext::new();
let crazyflie = Crazyflie::connect_from_uri(
&context,
"radio://0/80/2M/E7E7E7E7E7",
crazyflie_lib::NoTocCache
)
.await?;
println!("Taking off...");
if let Err(e) = crazyflie.high_level_commander.take_off(0.5, None, 2.0, None).await {
eprintln!("Take-off failed: {e}");
}
sleep(Duration::from_secs_f32(2.0)).await;
println!("Going to first position...");
if let Err(e) = crazyflie.high_level_commander.go_to(0.0, 0.5, 0.5, 0.0, 2.0, false, false, None).await {
eprintln!("Go-to failed: {e}");
}
sleep(Duration::from_secs_f32(2.0)).await;
println!("Going to second position...");
if let Err(e) = crazyflie.high_level_commander.go_to(-0.25, 0.0, 0.5, 0.0, 2.0, false, false, None).await {
eprintln!("Go-to failed: {e}");
}
sleep(Duration::from_secs_f32(2.0)).await;
println!("Moving in a spiral...");
if let Err(e) = crazyflie.high_level_commander.spiral(-PI*2.0, 0.5, 0.5, 0.0, 2.0, true, true, None).await {
eprintln!("Spiral failed: {e}");
}
sleep(Duration::from_secs_f32(2.0)).await;
println!("Landing...");
if let Err(e) = crazyflie.high_level_commander.land(0.0, None, 2.0, None).await {
eprintln!("Landing failed: {e}");
}
sleep(Duration::from_secs_f32(2.0)).await;
crazyflie.high_level_commander.stop(None).await?;
println!("Done");
Ok(())
}