Skip to content

Commit

Permalink
ray_length improved and renamed to cuas_range
Browse files Browse the repository at this point in the history
  • Loading branch information
marcasmar1 committed Oct 23, 2023
1 parent bea861b commit 650a58b
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 33 deletions.
3 changes: 3 additions & 0 deletions cli/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
14 changes: 8 additions & 6 deletions cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<f64>,
/// 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<f64>,
}

let cmd = Args::command()
Expand Down Expand Up @@ -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.);
Expand All @@ -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)
Expand Down
20 changes: 13 additions & 7 deletions src/kml/detection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ pub fn write_detection_set(
x: &mut Writer<impl std::io::Write>,
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(())
Expand All @@ -34,7 +34,7 @@ pub fn write_detection(
x: &mut Writer<impl std::io::Write>,
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(
Expand Down Expand Up @@ -123,15 +123,15 @@ pub fn write_detection(
record.cuas_location.unwrap_or(static_cuas_origin),
*bearing,
*elevation,
ray_length,
cuas_range,
)?;
}
Location::Bearing { bearing } => {
ray_from_bearing(
x,
record.cuas_location.unwrap_or(static_cuas_origin),
*bearing,
ray_length,
cuas_range,
)?;
}
Location::Quad { quad } => {
Expand All @@ -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)?;
}
}
}
Expand Down
13 changes: 6 additions & 7 deletions src/kml/geometry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<impl Write>,
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"))?;
Expand Down Expand Up @@ -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"))?;
Expand Down Expand Up @@ -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")
Expand All @@ -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((
Expand Down
12 changes: 6 additions & 6 deletions src/kml/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ 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 {
pub fn disable_track_icons(mut self, val: bool) -> 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
}
}
Expand All @@ -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)
Expand All @@ -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())?;

Expand Down
20 changes: 13 additions & 7 deletions src/kml/tracking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ pub fn write_track_set(
x: &mut Writer<impl std::io::Write>,
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(())
Expand All @@ -34,7 +34,7 @@ pub fn write_track<W: std::io::Write>(
x: &mut Writer<W>,
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(
Expand Down Expand Up @@ -89,15 +89,15 @@ pub fn write_track<W: std::io::Write>(
record.cuas_location.unwrap_or(static_cuas_origin),
bearing,
elevation,
ray_length,
cuas_range,
)?;
}
Location::Bearing { bearing } => {
ray_from_bearing(
x,
record.cuas_location.unwrap_or(static_cuas_origin),
bearing,
ray_length,
cuas_range,
)?;
}
Location::Quad { quad } => {
Expand All @@ -107,10 +107,16 @@ pub fn write_track<W: std::io::Write>(
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!(),
Expand Down

0 comments on commit 650a58b

Please sign in to comment.