Skip to content

Commit

Permalink
refactor: ♻️ update RfSensor to allow multiple faces
Browse files Browse the repository at this point in the history
  • Loading branch information
thkruz committed Mar 11, 2024
1 parent 4851248 commit 179b486
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 18 deletions.
12 changes: 7 additions & 5 deletions src/interfaces/RfSensorParams.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* @author Theodore Kruczek.
* @license MIT
* @license AGPL-3.0-or-later
* @copyright (c) 2022-2024 Theodore Kruczek Permission is
* hereby granted, free of charge, to any person obtaining a copy of this
* software and associated documentation files (the "Software"), to deal in the
Expand All @@ -25,10 +25,12 @@ import { Degrees } from 'ootk-core';
import { DetailedSensorParams } from '../types/types';

export interface RfSensorParams extends DetailedSensorParams {
boresightAz: Degrees;
boresightEl: Degrees;
/** For radars, this is the width of the beam */
/** The azimuth angles at boresight of the sensor */
boresightAz: Degrees[];
/** The elevation angles at boresight of the sensor */
boresightEl: Degrees[];
/** The width of the beam */
beamwidth: Degrees;
/** For radar sensors, what frequency does this sensor operate in? */
/** The frequency this sensor operate in */
freqBand?: string;
}
74 changes: 61 additions & 13 deletions src/objects/RfSensor.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* @author Theodore Kruczek.
* @license MIT
* @license AGPL-3.0-or-later
* @copyright (c) 2022-2024 Theodore Kruczek Permission is
* hereby granted, free of charge, to any person obtaining a copy of this
* software and associated documentation files (the "Software"), to deal in the
Expand All @@ -26,8 +26,9 @@ import { azel2uv, uv2azel, RfSensorParams } from '../main';
import { DetailedSensor } from './DetailedSensor';

export class RfSensor extends DetailedSensor {
boresightAz: Degrees;
boresightEl: Degrees;
boresightAz: Degrees[];
boresightEl: Degrees[];
faces: number;
freqBand?: string;
beamwidth: Degrees;

Expand All @@ -45,36 +46,83 @@ export class RfSensor extends DetailedSensor {

this.boresightAz = info.boresightAz;
this.boresightEl = info.boresightEl;
if (info.boresightAz.length !== info.boresightEl.length) {
throw new Error('Boresight azimuth and elevation arrays must be the same length');
}
this.faces = info.boresightAz.length;
this.beamwidth = info.beamwidth;
this.freqBand = info.freqBand;
}

uvFromAzEl(az: Degrees, el: Degrees) {
/**
* Converts azimuth and elevation angles to unit vector coordinates.
* @param az - The azimuth angle in degrees.
* @param el - The elevation angle in degrees.
* @param face - The face number (optional).
* @returns The unit vector coordinates.
*/
uvFromAzEl(az: Degrees, el: Degrees, face?: number) {
const azRad = (az * DEG2RAD) as Radians;
const elRad = (el * DEG2RAD) as Radians;
const azDiff = (azRad - this.boresightAzRad) as Radians;
const elDiff = (elRad - this.boresightElRad) as Radians;
const azDiff = (azRad - this.boresightAzRad(face ?? 0)) as Radians;
const elDiff = (elRad - this.boresightElRad(face ?? 0)) as Radians;

return azel2uv(azDiff, elDiff, this.beamwidthRad);
}

azElFromUV(u: number, v: number) {
/**
* Converts the given UV coordinates to azimuth and elevation angles.
* @param u - The U coordinate.
* @param v - The V coordinate.
* @param face - The face number for multi-faced sensors. (optional)
* @returns An object containing the azimuth and elevation angles in degrees.
* @throws Error if face number is not specified for multi-faced sensors.
*/
azElFromUV(u: number, v: number, face?: number) {
if (!face && this.faces > 1) {
throw new Error('Face number must be specified for multi-faced sensors');
}

const { az, el } = uv2azel(u, v, this.beamwidthRad);

return {
az: ((az + this.boresightAz) * RAD2DEG) as Degrees,
el: ((el + this.boresightEl) * RAD2DEG) as Degrees,
az: ((az + this.boresightAz[face ?? 0]) * RAD2DEG) as Degrees,
el: ((el + this.boresightEl[face ?? 0]) * RAD2DEG) as Degrees,
};
}

get boresightAzRad() {
return (this.boresightAz * DEG2RAD) as Radians;
/**
* Converts the boresight azimuth angle to radians.
* @param face - The face number for multi-faced sensors. (Optional)
* @returns The boresight azimuth angle in radians.
* @throws An error if the face number is not specified for multi-faced sensors.
*/
boresightAzRad(face?: number) {
if (!face && this.faces > 1) {
throw new Error('Face number must be specified for multi-faced sensors');
}

return (this.boresightAz[face ?? 0] * DEG2RAD) as Radians;
}

get boresightElRad() {
return (this.boresightEl * DEG2RAD) as Radians;
/**
* Converts the boresight elevation angle of the sensor to radians.
* @param face - The face number of the sensor (optional for single-faced sensors).
* @returns The boresight elevation angle in radians.
* @throws Error if the face number is not specified for multi-faced sensors.
*/
boresightElRad(face?: number) {
if (!face && this.faces > 1) {
throw new Error('Face number must be specified for multi-faced sensors');
}

return (this.boresightEl[face ?? 0] * DEG2RAD) as Radians;
}

/**
* Gets the beamwidth in radians.
* @returns The beamwidth in radians.
*/
get beamwidthRad() {
return (this.beamwidth * DEG2RAD) as Radians;
}
Expand Down
37 changes: 37 additions & 0 deletions test/rfSensor.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { Degrees, Kilometers, Milliseconds, SpaceObjectType } from 'ootk-core';
import { CommLink, ZoomValue } from '../src/main';
import { RfSensor } from '../src/objects/RfSensor';

describe('RfSensor', () => {
it('should create a new RfSensor', () => {
const sensor = new RfSensor({
objName: 'RAFFYL',
shortName: 'FYL',
id: 0,
name: 'RAF Fylingdales, United Kingdom',
uiName: 'RAF Fylingdales',
system: 'BMEWS UEWR',
freqBand: 'UHF',
type: SpaceObjectType.PHASED_ARRAY_RADAR,
lat: <Degrees>54.361758,
lon: <Degrees>-0.670051,
alt: <Kilometers>0.26, // Open Street Maps
minAz: <Degrees>0,
maxAz: <Degrees>360,
minEl: <Degrees>3,
maxEl: <Degrees>85,
minRng: <Kilometers>200,
maxRng: <Kilometers>5556,
changeObjectInterval: <Milliseconds>1000,
beamwidth: <Degrees>2.0,
commLinks: [CommLink.AEHF, CommLink.WGS],
boresightAz: [<Degrees>0],
boresightEl: [<Degrees>20],
zoom: ZoomValue.LEO,
country: 'United Kingdom',
operator: 'Royal Air Force',
});

expect(sensor).toBeInstanceOf(RfSensor);
});
});

0 comments on commit 179b486

Please sign in to comment.