pycasx.acas.acasx

ACAS X implementation for pyCASX.

Module Contents

Classes

ACASX

The brain behind pyCASX.

Attributes

RHO_INA

pycasx.acas.acasx.RHO_INA
class pycasx.acas.acasx.ACASX(model_path=None, backend='nnet')

Bases: pycasx.acas.hcas.HCASMixin, pycasx.acas.vcas.VCASMixin

The brain behind pyCASX.

This class contains all the logic for the ACAS X implementation. Well, almost, some logic is provided by the mixin classes

Parameters:
  • model_path (Path | str | None) – Path to the ACAS model folder.

  • backend (Literal["nnet", "onnx", "torch"], optional) – The runtime backend to use. Defaults to “nnet”.

advise()

Advise the pilot on the current situation.

Returns:

The HCAS and VCAS

advisories.

Return type:

tuple[HCASAdvisories, VCASAdvisories]

fetch_data()

Fetch the required data from FlightGear.

Fetches data of ownship and all intruders from FlightGear and post-processes the data to the required format for the ACAS X.

Note: a single get_prop or list_props (without recursion) call

via the HTTP API takes roughly 20 ms. Therefore, accessing the properties of a single aircraft in our current setup takes roughly 100 ms. This is a lot of time, especially when we have a lot of intruders. Therefore, not only should we try to eliminate unnecessary calls to intruders far away from the ownship, but we should also try to refactor this function to use concurrency.

Raises:

RuntimeError – If no connection is registered.

Return type:

None

evaluate(model_name, inputs)

Evaluate a CAS model.

Parameters:
  • model_name (str) – Name of the model to evaluate from the model dictionary.

  • inputs (npt.NDArray[np.float32]) – The inputs to the model.

Returns:

The outputs of the model.

Return type:

npt.NDArray[np.float32]

Raises:

NotImplementedError – Raised if the requested backend is not implemented.

_evaluate_nnet(model_name, inputs)

Evaluate a CAS model with the NNet runtime.

Parameters:
  • model_name (str) – Name of the model to evaluate from the model dictionary.

  • inputs (npt.NDArray[np.float32]) – The inputs to the model.

Returns:

The outputs of the model.

Return type:

npt.NDArray[np.float32]

_evaluate_onnx(model_name, inputs)

Evaluate a CAS model with the onnx runtime.

Parameters:
  • model_name (str) – Name of the model to evaluate from the model dictionary.

  • inputs (npt.NDArray[np.float32]) – The inputs to the model.

Returns:

The outputs of the model.

Return type:

npt.NDArray[np.float32]

Raises:

KeyError – Raised if the requested model is not found.

_evaluate_torch(model_name, inputs)

Evaluate a CAS model with the PyTorch runtime.

Parameters:
  • model_name (str) – Name of the model to evaluate from the model dictionary.

  • inputs (npt.NDArray[np.float32]) – The inputs to the model.

Returns:

The outputs of the model.

Return type:

npt.NDArray[np.float32]

Raises:

KeyError – Raised if the requested model is not found.

register_connection(connection)

Register a new connection to a connection provider.

The newly registered connection will be used to fetch data for the ACAS X model. If a connection is already registered, it will be overwritten.

Parameters:

connection (PropsConnection) – The connection provider.

Return type:

None

load_models(model_path)

Load the CAS models from the provided path.

Parameters:

model_path (Path | str) – Path to the CAS models.

Returns:

The loaded CAS models.

Return type:

ModelDict

Raises:
fetch_ownship_data()

Fetches the data of the ownship.

The ownship uses the following properties:
  • /sim/multiplay/callsign

  • /position/altitude-ft

  • /velocities/vertical-speed-fps

  • /velocities/equivalent-kt

  • /environment/density-slugft3

  • /orientation/true-heading-deg

  • /position/latitude-deg

  • /position/longitude-deg

Returns:

The ownship with the data fetched from FlightGear.

Return type:

Aircraft

fetch_intruder_data(intruder)

Fetches the data of a single intruder.

Parameters:

intruder (str) – The intruder to fetch the data for. This refers to the full path of the intruder in the property tree until the aircraft directory. E.g. /ai/models/aircraft for the zeroth intruder and /ai/models/aircraft[1] for the first intruder.

Returns:

The intruder with the data fetched from FlightGear.

Return type:

Aircraft

fetch_aircraft_data(call_sign, altitude_ft, vertical_speed_fps, heading_deg, latitude_deg, longitude_deg, true_airspeed_kt=None, equivalent_airspeed_kt=None, density_slugft3=None)

Fetches the data of a single aircraft.

Fetch the required data to fully describe an aircraft from FlightGear. Some properties are optional, depending on the model used. For example, for AI aircraft, FlightGear directly provides the true airspeed, but for the ownship, we have to calculate it ourselves. Thus, one either has to provide the true airspeed or the equivalent airspeed and the density.

This method uses threading to improve performance.

Parameters:
  • call_sign (str) – The property string of the call sign.

  • altitude_ft (str) – The property string of the altitude.

  • vertical_speed_fps (str) – The property string of the vertical speed.

  • heading_deg (str) – The property string of the heading.

  • latitude_deg (str) – The property string of the latitude.

  • longitude_deg (str) – The property string of the longitude.

  • true_airspeed_kt (str | None) – The property string of the true airspeed.

  • equivalent_airspeed_kt (str | None) – The property string of the equivalent airspeed.

  • density_slugft3 (str | None) – The property string of the density.

Returns:

The aircraft with the data fetched from FlightGear.

Return type:

Aircraft

Raises:
  • ValueError – Raised if neither the true airspeed nor the equivalent airspeed and density are provided.

  • RuntimeError – Raised if internal logic fails. Please report this as a bug.