Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(RA): RA model based on a probe mesh implementation #7807

Open
wants to merge 37 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
071296b
feat(RA): RA model based on a probe mesh implementation
Taz5150 Feb 19, 2023
123f408
feat(RA): RA model based on a probe mesh implementation
Taz5150 Feb 19, 2023
3f1e332
Merge branch 'flybywiresim:master' into radalt-system
Taz5150 Feb 22, 2023
7f22c11
Merge branch 'master' into radalt-system
Taz5150 Mar 16, 2023
ce4fb6d
feat: baseline for RA calculation by signal SNR
Taz5150 Mar 20, 2023
9917c4f
fix: included noise floor to SNR
Taz5150 Mar 20, 2023
4f43eb8
Merge branch 'master' into radalt-system
Taz5150 Mar 22, 2023
9876f2f
Merge branch 'master' into radalt-system
Taz5150 Mar 31, 2023
a63cef2
Update CHANGELOG.md
Taz5150 Apr 18, 2023
d100069
Merge remote-tracking branch 'upstream/master' into radalt-system
Taz5150 Apr 18, 2023
6c0c7f7
Merge branch 'radalt-system' of https://github.com/Taz5150/a32nx into…
Taz5150 Apr 18, 2023
019d96f
feat: new probe algorithm to improve performance
Taz5150 Apr 18, 2023
7fe265e
Merge branch 'flybywiresim:master' into radalt-system
Taz5150 Apr 27, 2023
b2c67a3
feat: probes measured by received power
Taz5150 Apr 27, 2023
707df21
Merge branch 'radalt-system' of https://github.com/Taz5150/a32nx into…
Taz5150 Apr 27, 2023
1e44064
Merge branch 'flybywiresim:master' into radalt-system
Taz5150 May 2, 2023
2328176
Merge branch 'flybywiresim:master' into radalt-system
Taz5150 May 10, 2023
6f2921e
refactor & feat: AC Bus power on
Taz5150 May 11, 2023
e89493a
Merge branch 'master' into radalt-system
Taz5150 May 11, 2023
98e254e
Update build.sh
Taz5150 May 12, 2023
759c047
Make build.sh executable
Taz5150 May 12, 2023
8a4bb9a
fix: TCAS probe detection fixed
Taz5150 May 18, 2023
31bb03e
Merge branch 'master' into radalt-system
Taz5150 May 18, 2023
b44ab3a
Update TcasComputer.ts
Taz5150 May 18, 2023
5b59985
Merge branch 'radalt-system' of https://github.com/Taz5150/a32nx into…
Taz5150 May 18, 2023
a494c71
Merge branch 'master' into radalt-system
Taz5150 Jun 6, 2023
b181f4d
fix: several documented fixes
Taz5150 Jun 15, 2023
8943e1a
Merge branch 'master' into radalt-system
Taz5150 Jun 15, 2023
5f8240e
Update fbw-a32nx/src/wasm/radalt_a320/src/radaltControl.h
Taz5150 Jul 4, 2023
bb89a1f
Update fbw-a32nx/src/wasm/radalt_a320/src/radaltControl.h
Taz5150 Jul 4, 2023
f771496
Update fbw-a32nx/src/wasm/radalt_a320/src/radaltControl.h
Taz5150 Jul 4, 2023
2fb7485
Update fbw-a32nx/src/wasm/radalt_a320/src/radaltControl.h
Taz5150 Jul 4, 2023
2fabd17
Update fbw-a32nx/src/wasm/radalt_a320/src/radaltGauge.cpp
Taz5150 Jul 4, 2023
2481d44
Update fbw-a32nx/src/wasm/radalt_a320/src/radaltControl.h
Taz5150 Jul 4, 2023
4b91d0f
Merge branch 'master' into radalt-system
Taz5150 Jul 4, 2023
f318045
update: suggestions from 2Hwk
Taz5150 Jul 4, 2023
e99292c
Merge branch 'master' into radalt-system
tracernz Oct 24, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

## 0.12.0

1. [RA] Realistic RA model based on a probe mesh implementation - @Taz5150 (TazX [Z+2]#0405)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please rebase/merge and move to 0.13.0.


## 0.11.0

1. [FMS] Implement vertical navigation functions - @BlueberryKing (BlueberryKing)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ htmlgauge00 = WasmInstrument/WasmInstrument.html?wasm_module=systems.wasm&wasm_g
htmlgauge01 = WasmInstrument/WasmInstrument.html?wasm_module=fbw.wasm&wasm_gauge=fbw,0,0,1,1
htmlgauge02 = WasmInstrument/WasmInstrument.html?wasm_module=fadec.wasm&wasm_gauge=FadecGauge,0,0,1,1
htmlgauge03 = WasmInstrument/WasmInstrument.html?wasm_module=flypad-backend.wasm&wasm_gauge=FlyPadBackend,0,0,1,1
htmlgauge04 = A32NX/SystemsHost/systems-host.html,0,0,1,1
htmlgauge05 = WasmInstrument/WasmInstrument.html?wasm_module=radalt.wasm&wasm_gauge=RadAlt,0,0,1,1

[VCockpit18]
size_mm = 0,0
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"scene" : 0,
"scenes" : [
{
"nodes" : [ 0 ]
}
],

"nodes" : [
{
"mesh" : 0
}
],

"meshes" : [
{
"primitives" : [ {
"attributes" : {
"POSITION" : 0
}
} ]
}
],

"buffers" : [
{
"uri" : "triangleWithoutIndices.bin",
"byteLength" : 36
}
],
"bufferViews" : [
{
"buffer" : 0,
"byteOffset" : 0,
"byteLength" : 36,
"target" : 34962
}
],
"accessors" : [
{
"bufferView" : 0,
"byteOffset" : 0,
"componentType" : 5126,
"count" : 3,
"type" : "VEC3",
"max" : [ 1.0, 1.0, 0.0 ],
"min" : [ 0.0, 0.0, 0.0 ]
}
],

"asset" : {
"version" : "2.0"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[VERSION]
Major=1
Minor=0


[fltsim.0]
title=triangleWithoutIndices
model=
texture=

[General]
category=GroundVehicle
103 changes: 57 additions & 46 deletions fbw-a32nx/src/systems/tcas/src/components/TcasComputer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -388,60 +388,71 @@ export class TcasComputer implements TcasComponent {
* @param _deltaTime Deltatime of this frame
*/
private fetchRawTraffic(_deltaTime): void {
// RA Probe Mesh - Read the uID for the first probe of the mesh, and sets the
// length of the mesh (15 if RA is on, 0 if RA is off).
// This is needed until Asobo fixes the isGround flag (among other things)
const probeId = SimVar.GetSimVarValue('L:A32NX_RA_PROBE_ZERO', 'number');
let probeLen = 14;
if (probeId === 0) {
probeLen = 0;
}
Coherent.call('GET_AIR_TRAFFIC').then((obj: JS_NPCPlane[]) => {
this.airTraffic.forEach((traffic) => {
traffic.alive = false;
});
obj.forEach((tf) => {
// Junk bad air traffic
if (!tf.lat && !tf.lon && !tf.alt && !tf.heading) {
if (this.debug) {
console.log('Removing bugged traffic');
console.log('====================================');
console.log(` id | ${tf.uId}`);
console.log(` alt | ${tf.alt * 3.281}`);
console.log(` bearing | ${MathUtils.computeGreatCircleHeading(this.ppos.lat, this.ppos.long, tf.lat, tf.lon)}`);
console.log(` hDist | ${MathUtils.computeGreatCircleDistance(this.ppos.lat, this.ppos.long, tf.lat, tf.lon)}`);
console.log(' ================================ ');
// Only non-probe traffic will be considered
if (tf.uId < probeId || tf.uId > probeId + probeLen) {
// Junk bad air traffic
if (!tf.lat && !tf.lon && !tf.alt && !tf.heading) {
if (this.debug) {
console.log('Removing bugged traffic');
console.log('====================================');
console.log(` id | ${tf.uId}`);
console.log(` alt | ${tf.alt * 3.281}`);
console.log(` bearing | ${MathUtils.computeGreatCircleHeading(this.ppos.lat, this.ppos.long, tf.lat, tf.lon)}`);
console.log(` hDist | ${MathUtils.computeGreatCircleDistance(this.ppos.lat, this.ppos.long, tf.lat, tf.lon)}`);
console.log(' ================================ ');
}
return;
}
let traffic: TcasTraffic | undefined = this.airTraffic.find((p) => p && p.ID === tf.uId.toFixed(0));
if (!traffic) {
traffic = new TcasTraffic(tf, this.ppos, this.planeAlt);
this.airTraffic.push(traffic);
}
return;
}
let traffic: TcasTraffic | undefined = this.airTraffic.find((p) => p && p.ID === tf.uId.toFixed(0));
if (!traffic) {
traffic = new TcasTraffic(tf, this.ppos, this.planeAlt);
this.airTraffic.push(traffic);
}

traffic.alive = true;
traffic.seen = Math.min(traffic.seen + 1, 10);
const newAlt = tf.alt * 3.281;
traffic.vertSpeed = (newAlt - traffic.alt) / (_deltaTime / 1000) * 60; // feet per minute
traffic.groundSpeed = Math.abs(MathUtils.computeGreatCircleDistance(tf.lat, tf.lon, traffic.lat, traffic.lon) / (_deltaTime / 1000) * 3600);
const newSlantDist = MathUtils.computeDistance3D(traffic.lat, traffic.lon, traffic.alt, this.ppos.lat, this.ppos.long, this.pressureAlt);
const newClosureRate = (traffic.slantDistance - newSlantDist) / (_deltaTime / 1000) * 3600; // knots = nautical miles per hour
traffic.closureAccel = (newClosureRate - traffic.closureRate) / (_deltaTime / 1000);
traffic.closureRate = newClosureRate;
traffic.slantDistance = newSlantDist;
traffic.lat = tf.lat;
traffic.lon = tf.lon;
traffic.alt = tf.alt * 3.281;
traffic.heading = tf.heading;
traffic.relativeAlt = newAlt - this.planeAlt;

let taTau = (traffic.slantDistance - TCAS.DMOD[this.sensitivity.getVar()][TaRaIndex.TA] ** 2 / traffic.slantDistance) / traffic.closureRate * 3600;
let raTau = (traffic.slantDistance - TCAS.DMOD[this.sensitivity.getVar()][TaRaIndex.RA] ** 2 / traffic.slantDistance) / traffic.closureRate * 3600;
let vTau = traffic.relativeAlt / (this.verticalSpeed - traffic.vertSpeed) * 60;

if (raTau < 0) {
taTau = Infinity;
raTau = Infinity;
}
if (vTau < 0) {
vTau = Infinity;
traffic.alive = true;
traffic.seen = Math.min(traffic.seen + 1, 10);
const newAlt = tf.alt * 3.281;
traffic.vertSpeed = (newAlt - traffic.alt) / (_deltaTime / 1000) * 60; // feet per minute
traffic.groundSpeed = Math.abs(MathUtils.computeGreatCircleDistance(tf.lat, tf.lon, traffic.lat, traffic.lon) / (_deltaTime / 1000) * 3600);
const newSlantDist = MathUtils.computeDistance3D(traffic.lat, traffic.lon, traffic.alt, this.ppos.lat, this.ppos.long, this.pressureAlt);
const newClosureRate = (traffic.slantDistance - newSlantDist) / (_deltaTime / 1000) * 3600; // knots = nautical miles per hour
traffic.closureAccel = (newClosureRate - traffic.closureRate) / (_deltaTime / 1000);
traffic.closureRate = newClosureRate;
traffic.slantDistance = newSlantDist;
traffic.lat = tf.lat;
traffic.lon = tf.lon;
traffic.alt = tf.alt * 3.281;
traffic.heading = tf.heading;
traffic.relativeAlt = newAlt - this.planeAlt;

let taTau = (traffic.slantDistance - TCAS.DMOD[this.sensitivity.getVar()][TaRaIndex.TA] ** 2 / traffic.slantDistance) / traffic.closureRate * 3600;
let raTau = (traffic.slantDistance - TCAS.DMOD[this.sensitivity.getVar()][TaRaIndex.RA] ** 2 / traffic.slantDistance) / traffic.closureRate * 3600;
let vTau = traffic.relativeAlt / (this.verticalSpeed - traffic.vertSpeed) * 60;

if (raTau < 0) {
taTau = Infinity;
raTau = Infinity;
}
if (vTau < 0) {
vTau = Infinity;
}
traffic.taTau = taTau;
traffic.raTau = raTau;
traffic.vTau = vTau;
}
traffic.taTau = taTau;
traffic.raTau = raTau;
traffic.vTau = vTau;
});

if (this.airTraffic.length > TCAS.MEMORY_MAX) {
Expand Down
22 changes: 22 additions & 0 deletions fbw-a32nx/src/wasm/radalt_a320/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# This CMakeLists.txt file is used only for syntax highlighting and navigating
# through the code in an IDE. It is not used for building the project.

cmake_minimum_required(VERSION 3.19)
project(flybywire-a32nx-radalt)

set(CMAKE_CXX_STANDARD 20)
set(MSFS_SDK "C:\\MSFS SDK")

set(CMAKE_CXX_FLAGS "-c -g -DDEBUG -Wno-unused-command-line-argument -Wno-ignored-attributes -Wno-macro-redefined --sysroot \"${MSFS_SDK}/WASM/wasi-sysroot\" -target wasm32-unknown-wasi -flto -D_MSFS_WASM=1 -D__wasi__ -D_LIBCPP_HAS_NO_THREADS -D_WINDLL -D_MBCS -mthread-model single -fno-exceptions -fms-extensions")

include_directories("${MSFS_SDK}/WASM/include")
include_directories("${MSFS_SDK}/WASM/wasi-sysroot/include")
include_directories("${MSFS_SDK}/SimConnect SDK/include")

include_directories(
./src
)

add_executable(flybywire-a32nx-radalt
./src/radaltGauge.cpp
)
63 changes: 63 additions & 0 deletions fbw-a32nx/src/wasm/radalt_a320/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/bin/bash

# get directory of this script relative to root
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
OUTPUT="${DIR}/../../../out/flybywire-aircraft-a320-neo/SimObjects/AirPlanes/FlyByWire_A320_NEO/panel/radalt.wasm"

if [ "$1" == "--debug" ]; then
CLANG_ARGS="-g"
else
WASMLD_ARGS="--strip-debug"
fi

set -ex

# create temporary folder for o files
mkdir -p "${DIR}/obj"
pushd "${DIR}/obj"

# compile c++ code for the A32NX
clang++ \
-c \
${CLANG_ARGS} \
-std=c++20 \
-Wno-unused-command-line-argument \
-Wno-ignored-attributes \
-Wno-macro-redefined \
--sysroot "${MSFS_SDK}/WASM/wasi-sysroot" \
-target wasm32-unknown-wasi \
-flto \
-D_MSFS_WASM=1 \
-D__wasi__ \
-D_LIBCPP_HAS_NO_THREADS \
-D_WINDLL \
-D_MBCS \
-mthread-model single \
-fno-exceptions \
-fms-extensions \
-fvisibility=hidden \
-O3 \
-I "${MSFS_SDK}/WASM/include" \
-I "${MSFS_SDK}/SimConnect SDK/include" \
"${DIR}/src/radaltGauge.cpp"

# restore directory.
popd

wasm-ld \
--no-entry \
--allow-undefined \
-L "${MSFS_SDK}/WASM/wasi-sysroot/lib/wasm32-wasi" \
-lc "${MSFS_SDK}/WASM/wasi-sysroot/lib/wasm32-wasi/libclang_rt.builtins-wasm32.a" \
--export __wasm_call_ctors \
${WASMLD_ARGS} \
--export-dynamic \
--export malloc \
--export free \
--export __wasm_call_ctors \
--export-table \
--gc-sections \
-O3 --lto-O3 \
-lc++ -lc++abi \
${DIR}/obj/*.o \
-o $OUTPUT
71 changes: 71 additions & 0 deletions fbw-a32nx/src/wasm/radalt_a320/src/SimVars.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#pragma once

/// <summary>
/// A collection of SimVar unit enums.
/// </summary>
class Units {
public:
ENUM Percent = get_units_enum("Percent");
ENUM Pounds = get_units_enum("Pounds");
ENUM Psi = get_units_enum("Psi");
ENUM Pph = get_units_enum("Pounds per hour");
ENUM Gallons = get_units_enum("Gallons");
ENUM Feet = get_units_enum("Feet");
ENUM FootPounds = get_units_enum("Foot pounds");
ENUM FeetMin = get_units_enum("Feet per minute");
ENUM Number = get_units_enum("Number");
ENUM Mach = get_units_enum("Mach");
ENUM Millibars = get_units_enum("Millibars");
ENUM SluggerSlugs = get_units_enum("Slug per cubic feet");
ENUM Celsius = get_units_enum("Celsius");
ENUM Bool = get_units_enum("Bool");
ENUM Hours = get_units_enum("Hours");
ENUM Seconds = get_units_enum("Seconds");
};

/// <summary>
/// A collection of SimVars and LVars for the A32NX
/// </summary>
class SimVars {
public:
Units* m_Units;

/// <summary>
/// Collection of LVars for the A32NX
/// </summary>
ENUM PlaneAltitudeAGL = get_aircraft_var_enum("PLANE ALT ABOVE GROUND");

ID DevVar;
ID ProbeZero;
ID RadAlt;
ID AcBus1;
ID AcBus2;

SimVars() { this->initializeVars(); }

void initializeVars() {
DevVar = register_named_variable("A32NX_DEVELOPER_STATE");
ProbeZero = register_named_variable("A32NX_RA_PROBE_ZERO");
RadAlt = register_named_variable("A32NX_RA_RAW");
AcBus1 = register_named_variable("A32NX_ELEC_AC_1_BUS_IS_POWERED");
AcBus2 = register_named_variable("A32NX_ELEC_AC_2_BUS_IS_POWERED");

//this->setDeveloperState(0);
this->setRadioAltitude(99999);
this->setProbeZero(0);


m_Units = new Units();
}
// Collection of LVar 'set' Functions
void setProbeZero(FLOAT64 value) { set_named_variable_value(ProbeZero, value); }
void setDeveloperState(FLOAT64 value) { set_named_variable_value(DevVar, value); }
void setRadioAltitude(FLOAT64 value) { set_named_variable_value(RadAlt, value); }

// Collection of SimVar/LVar 'get' Functions
FLOAT64 getDeveloperState() { return get_named_variable_value(DevVar); }
FLOAT64 getRadarAltitude() { return get_named_variable_value(RadAlt); }
FLOAT64 getAcBusState1() { return get_named_variable_value(AcBus1); }
FLOAT64 getAcBusState2() { return get_named_variable_value(AcBus2); }
FLOAT64 getPlaneAltitudeAGL() { return aircraft_varget(PlaneAltitudeAGL, m_Units->Feet, 0); }
};
Loading
Loading