From 2d893969b88f2260e2555e42996a3d0c9ed5719e Mon Sep 17 00:00:00 2001 From: udhaykumarbala Date: Sat, 27 Aug 2022 18:47:50 +0530 Subject: [PATCH] geofence example added --- mav-sdk/examples/geofence.rs | 50 ++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 mav-sdk/examples/geofence.rs diff --git a/mav-sdk/examples/geofence.rs b/mav-sdk/examples/geofence.rs new file mode 100644 index 0000000..f2dcf1a --- /dev/null +++ b/mav-sdk/examples/geofence.rs @@ -0,0 +1,50 @@ +use mav_sdk::Drone; + +const MAVSDK_SERVER: &str = "http://127.0.0.1:4000"; + +#[tokio::main] +async fn main() { + let mut drone = Drone::connect(MAVSDK_SERVER).await.expect("Should connect"); + println!("We have a DRONE connection with {}", MAVSDK_SERVER); + + println!("Uploading Geofence..."); + + let upload_geofence_request = mav_sdk::grpc::geofence::UploadGeofenceRequest { polygons: vec![ + mav_sdk::grpc::geofence::Polygon { + points:vec![mav_sdk::grpc::geofence::Point{ latitude_deg: 0.0, longitude_deg: 0.0 },mav_sdk::grpc::geofence::Point{ latitude_deg: 0.0, longitude_deg: 0.0 },mav_sdk::grpc::geofence::Point{ latitude_deg: 0.0, longitude_deg: 0.0 },mav_sdk::grpc::geofence::Point{ latitude_deg: 0.0, longitude_deg: 0.0 },], fence_type: 0, }, + ]}; + let upload_geofence = drone + .geofence + .upload_geofence(upload_geofence_request) + .await + .expect("Should upload geofence"); + + println!( + "Upload Geofence: {}", + &upload_geofence + .get_ref() + .geofence_result + .as_ref() + .unwrap() + .result_str + ); + + println!("Clearing Geofence..."); + + let clear_geofence_request = mav_sdk::grpc::geofence::ClearGeofenceRequest {}; + let clear_geofence = drone + .geofence + .clear_geofence(clear_geofence_request) + .await + .expect("Should clear geofence"); + + println!( + "Clear Geofence: {}", + &clear_geofence + .get_ref() + .geofence_result + .as_ref() + .unwrap() + .result_str + ); +}