From 650a58bd1cc3460c3ca5d805cb74edfa38655e0c Mon Sep 17 00:00:00 2001 From: marcasmar1 Date: Mon, 23 Oct 2023 17:59:36 +0200 Subject: [PATCH] ray_length improved and renamed to cuas_range --- cli/CHANGELOG.md | 3 +++ cli/src/lib.rs | 14 ++++++++------ src/kml/detection.rs | 20 +++++++++++++------- src/kml/geometry.rs | 13 ++++++------- src/kml/mod.rs | 12 ++++++------ src/kml/tracking.rs | 20 +++++++++++++------- 6 files changed, 49 insertions(+), 33 deletions(-) diff --git a/cli/CHANGELOG.md b/cli/CHANGELOG.md index 276af07..eab1951 100644 --- a/cli/CHANGELOG.md +++ b/cli/CHANGELOG.md @@ -1,3 +1,6 @@ +## 2.3.1 +- Implement CUAS range parameter for BearingElevation, Bearing, Arc and Quad + ## 2.3.0 - Update COURAGEOUS schema support to v0.4.0 - Implement CUAS location representation. diff --git a/cli/src/lib.rs b/cli/src/lib.rs index 07280e7..d89986e 100644 --- a/cli/src/lib.rs +++ b/cli/src/lib.rs @@ -74,9 +74,11 @@ pub fn run(formats: &HashMap<&'static str, Format>, allow_to_courageous_option: #[arg(long)] no_track_icons: bool, - /// Length of ray in meters for systems that represent position with BearingElevation. - #[arg(long)] - ray_length: Option, + /// Maximum distance from the C-UAS where objects can be detected. + /// It is used for the length of rays in meters in systems that represent position with BearingElevation or Bearing, + /// or the radius of arcs for Arc or Quad. + #[arg(long, short = 'r')] + cuas_range: Option, } let cmd = Args::command() @@ -158,8 +160,8 @@ fn process_to_kml( let output_path = input_path.with_extension("kml"); let output_file = BufWriter::new(File::create(&output_path)?); let disable_track_icons = args.get_flag("no_track_icons"); - let ray_length = *args - .try_get_one("ray_length") + let cuas_range = *args + .try_get_one("cuas_range") .ok() .flatten() .unwrap_or(&100.); @@ -169,7 +171,7 @@ fn process_to_kml( output_file, WriteAsKmlOptions::default() .disable_track_icons(disable_track_icons) - .ray_length(ray_length), + .cuas_range(cuas_range), )?; Ok(output_path) diff --git a/src/kml/detection.rs b/src/kml/detection.rs index 06d5b5a..5c2a0b4 100644 --- a/src/kml/detection.rs +++ b/src/kml/detection.rs @@ -14,14 +14,14 @@ pub fn write_detection_set( x: &mut Writer, set: &[Detection], static_cuas_origin: Position3d, - ray_length: f64, + cuas_range: f64, ) -> Result<(), quick_xml::Error> { x.create_element("Folder").write_inner_content(|x| { x.create_element("name") .write_text_content(BytesText::new("Detection Sets"))?; for detection in set { - write_detection(x, detection, static_cuas_origin,ray_length)?; + write_detection(x, detection, static_cuas_origin, cuas_range)?; } Ok(()) @@ -34,7 +34,7 @@ pub fn write_detection( x: &mut Writer, detection: &Detection, static_cuas_origin: Position3d, - ray_length: f64, + cuas_range: f64, ) -> Result<(), quick_xml::Error> { x.create_element("Folder").write_inner_content(|x| { x.create_element("name").write_text_content(BytesText::new( @@ -123,7 +123,7 @@ pub fn write_detection( record.cuas_location.unwrap_or(static_cuas_origin), *bearing, *elevation, - ray_length, + cuas_range, )?; } Location::Bearing { bearing } => { @@ -131,7 +131,7 @@ pub fn write_detection( x, record.cuas_location.unwrap_or(static_cuas_origin), *bearing, - ray_length, + cuas_range, )?; } Location::Quad { quad } => { @@ -141,10 +141,16 @@ pub fn write_detection( courageous_format::Quad::South => (225., 135.), courageous_format::Quad::West => (315., 225.), }; - create_arc_polygon(x, bearing_from, bearing_to, static_cuas_origin)?; + create_arc_polygon( + x, + bearing_from, + bearing_to, + static_cuas_origin, + cuas_range, + )?; } Location::Arc(Arc { from, to }) => { - create_arc_polygon(x, *from, *to, static_cuas_origin)?; + create_arc_polygon(x, *from, *to, static_cuas_origin, cuas_range)?; } } } diff --git a/src/kml/geometry.rs b/src/kml/geometry.rs index 77fc96f..58d7681 100644 --- a/src/kml/geometry.rs +++ b/src/kml/geometry.rs @@ -4,14 +4,13 @@ use courageous_format::Position3d; use map_3d::{aer2geodetic, Ellipsoid}; use quick_xml::{events::BytesText, Writer}; - pub fn ray_from_bearing( x: &mut Writer, cuas_origin: Position3d, bearing: f64, - ray_length: f64, + cuas_range: f64, ) -> Result<(), quick_xml::Error> { - let target = distance_from_position(cuas_origin, bearing, 0., ray_length); + let target = distance_from_position(cuas_origin, bearing, 0., cuas_range); x.create_element("LineString").write_inner_content(|x| { x.create_element("extrude") .write_text_content(BytesText::new("0"))?; @@ -40,9 +39,9 @@ pub fn ray_from_bearing_elevation( cuas_origin: Position3d, bearing: f64, elevation: f64, - ray_length: f64, + cuas_range: f64, ) -> Result<(), quick_xml::Error> { - let target = distance_from_position(cuas_origin, bearing, elevation, ray_length); + let target = distance_from_position(cuas_origin, bearing, elevation, cuas_range); x.create_element("LineString").write_inner_content(|x| { x.create_element("extrude") .write_text_content(BytesText::new("0"))?; @@ -95,6 +94,7 @@ pub fn create_arc_polygon( bearing_from: f64, bearing_to: f64, static_cuas_origin: Position3d, + cuas_range: f64, ) -> Result<(), quick_xml::Error> { x.create_element("Polygon").write_inner_content(|x| { x.create_element("extrude") @@ -107,12 +107,11 @@ pub fn create_arc_polygon( .write_inner_content(|x| { x.create_element("LinearRing").write_inner_content(|x| { const ARC_POINT_COUNT: usize = 64; - const ARC_RADIUS: f64 = 100.; let arc_points = (0..ARC_POINT_COUNT).map(|idx| { let angle_deg = bearing_from + (bearing_to - bearing_from) * (idx as f64 / ARC_POINT_COUNT as f64); - (angle_deg.to_radians(), 0., ARC_RADIUS) + (angle_deg.to_radians(), 0., cuas_range) }); let points = std::iter::once(( diff --git a/src/kml/mod.rs b/src/kml/mod.rs index dc93338..723baee 100644 --- a/src/kml/mod.rs +++ b/src/kml/mod.rs @@ -22,7 +22,7 @@ const KML_DOCUMENT_ATTRIBUTES: [(&str, &str); 2] = [ #[non_exhaustive] pub struct WriteAsKmlOptions { pub disable_track_icons: bool, - pub ray_length: f64, + pub cuas_range: f64, } impl WriteAsKmlOptions { @@ -30,8 +30,8 @@ impl WriteAsKmlOptions { self.disable_track_icons = val; self } - pub fn ray_length(mut self, val: f64) -> WriteAsKmlOptions { - self.ray_length = val; + pub fn cuas_range(mut self, val: f64) -> WriteAsKmlOptions { + self.cuas_range = val; self } } @@ -42,7 +42,7 @@ pub fn write_as_kml( options: WriteAsKmlOptions, ) -> anyhow::Result<()> { let mut xml = Writer::new(writer); - let ray_length = options.ray_length; + let cuas_range = options.cuas_range; xml.write_bom()?; xml.create_element("kml") .with_attributes(KML_DOCUMENT_ATTRIBUTES) @@ -55,13 +55,13 @@ pub fn write_as_kml( x, &database.detection, database.static_cuas_location.clone(), - ray_length, + cuas_range, )?; write_track_set( x, &database.tracks, database.static_cuas_location.clone(), - ray_length, + cuas_range, )?; write_cuas_origin(x, database.static_cuas_location.clone())?; diff --git a/src/kml/tracking.rs b/src/kml/tracking.rs index 725d6ec..02a3582 100644 --- a/src/kml/tracking.rs +++ b/src/kml/tracking.rs @@ -14,14 +14,14 @@ pub fn write_track_set( x: &mut Writer, set: &[Track], static_cuas_origin: Position3d, - ray_length: f64, + cuas_range: f64, ) -> Result<(), quick_xml::Error> { x.create_element("Folder").write_inner_content(|x| { x.create_element("name") .write_text_content(BytesText::new("Tracks"))?; for detection in set { - write_track(x, detection, static_cuas_origin, ray_length)?; + write_track(x, detection, static_cuas_origin, cuas_range)?; } Ok(()) @@ -34,7 +34,7 @@ pub fn write_track( x: &mut Writer, track: &Track, static_cuas_origin: Position3d, - ray_length: f64, + cuas_range: f64, ) -> Result<(), quick_xml::Error> { x.create_element("Folder").write_inner_content(|x| { x.create_element("name").write_text_content(BytesText::new( @@ -89,7 +89,7 @@ pub fn write_track( record.cuas_location.unwrap_or(static_cuas_origin), bearing, elevation, - ray_length, + cuas_range, )?; } Location::Bearing { bearing } => { @@ -97,7 +97,7 @@ pub fn write_track( x, record.cuas_location.unwrap_or(static_cuas_origin), bearing, - ray_length, + cuas_range, )?; } Location::Quad { quad } => { @@ -107,10 +107,16 @@ pub fn write_track( courageous_format::Quad::South => (225., 135.), courageous_format::Quad::West => (315., 225.), }; - create_arc_polygon(x, bearing_from, bearing_to, static_cuas_origin)?; + create_arc_polygon( + x, + bearing_from, + bearing_to, + static_cuas_origin, + cuas_range, + )?; } Location::Arc(Arc { from, to }) => { - create_arc_polygon(x, from, to, static_cuas_origin)?; + create_arc_polygon(x, from, to, static_cuas_origin, cuas_range)?; } // Positions are processed on the next step Location::Position2d(_) | Location::Position3d(_) => unreachable!(),